Repository: pypa/virtualenv

Issue:
add jython to CI
Blocked on https://github.com/tox-dev/tox/issues/1073.


Discussion:
``` the way to add jython to CI is:
http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar
java -jar ~/Downloads/jython-installer-2.7.1.jar -sd jython -e demo src doc
env/bin/jython
```

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -120,7 +120,12 @@ def get_version():
     package_data={"virtualenv_support": ["*.whl"]},
     python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
     extras_require={
-        "testing": ["mock", "pytest >= 3.0.0, <4", "pytest-cov >= 2.5.1, <3", "pytest-timeout >= 1.3.0, <2"],
+        "testing": [
+            'mock;python_version<"3.3"',
+            "pytest >= 3.0.0, <4",
+            "coverage >= 4.5.0, <5",
+            'pytest-timeout >= 1.3.0, <2; platform_python_implementation!="Jython"',
+        ],
         "docs": ["sphinx >= 1.8.0, < 2"],
     },
     **setup_params
diff --git a/src/virtualenv.py b/src/virtualenv.py
--- a/src/virtualenv.py
+++ b/src/virtualenv.py
@@ -894,7 +894,7 @@ def install_wheel(project_names, py_executable, search_dirs=None, download=False
         search_dirs = file_search_dirs()
 
     wheels = find_wheels(["setuptools", "pip"], search_dirs)
-    pythonpath = os.pathsep.join(wheels)
+    python_path = os.pathsep.join(wheels)
 
     # PIP_FIND_LINKS uses space as the path separator and thus cannot have paths
     # with spaces in them. Convert any of those to local file:// URL form.
@@ -911,7 +911,6 @@ def space_path2url(p):
         return urljoin("file:", pathname2url(os.path.abspath(p)))
 
     findlinks = " ".join(space_path2url(d) for d in search_dirs)
-
     SCRIPT = textwrap.dedent(
         """
         import sys
@@ -936,14 +935,16 @@ def space_path2url(p):
         try:
             args = ["install", "--ignore-installed"]
             if cert_file is not None:
-                args += ["--cert", cert_file.name]
+                args += ["--cert", cert_file.name{}]
             args += sys.argv[1:]
 
             sys.exit(_main(args))
         finally:
             if cert_file is not None:
                 os.remove(cert_file.name)
-    """
+    """.format(
+            ", '--no-cache'" if is_jython else ""
+        )
     ).encode("utf8")
 
     cmd = [py_executable, "-"] + project_names
@@ -951,8 +952,8 @@ def space_path2url(p):
     logger.indent += 2
 
     env = {
-        "PYTHONPATH": pythonpath,
-        "JYTHONPATH": pythonpath,  # for Jython < 3.x
+        "PYTHONPATH": python_path,
+        "JYTHONPATH": python_path,  # for Jython < 3.x
         "PIP_FIND_LINKS": findlinks,
         "PIP_USE_WHEEL": "1",
         "PIP_ONLY_BINARY": ":all:",


Test patch:
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -1,3 +1,4 @@
+import os
 import subprocess
 import sys
 
@@ -5,12 +6,20 @@
 
 import virtualenv
 
-VIRTUALENV_SCRIPT = virtualenv.__file__
+
+def get_src(path):
+    base, _ = os.path.splitext(path)
+    if virtualenv.is_jython and base.endswith("$py"):
+        base = base[:-3]  # strip away Jython ext
+    return "{}.py".format(base)
+
+
+VIRTUALENV_SCRIPT = get_src(virtualenv.__file__)
 
 
 def test_commandline_basic(tmpdir):
     """Simple command line usage should work"""
-    subprocess.check_call([sys.executable, VIRTUALENV_SCRIPT, str(tmpdir.join("venv"))])
+    subprocess.check_output([sys.executable, VIRTUALENV_SCRIPT, str(tmpdir.join("venv"))], stderr=subprocess.STDOUT)
 
 
 def test_commandline_explicit_interp(tmpdir):
@@ -26,9 +35,5 @@ def test_commandline_explicit_interp(tmpdir):
 @pytest.mark.skipif("sys.platform == 'win32' and sys.version_info[:1] >= (3,)")
 def test_commandline_abbrev_interp(tmpdir):
     """Specifying abbreviated forms of the Python interpreter should work"""
-    if sys.platform == "win32":
-        fmt = "%s.%s"
-    else:
-        fmt = "python%s.%s"
-    abbrev = fmt % (sys.version_info[0], sys.version_info[1])
+    abbrev = "{}{}.{}".format("" if sys.platform == "win32" else "python", *sys.version_info[0:2])
     subprocess.check_call([sys.executable, VIRTUALENV_SCRIPT, "-p", abbrev, str(tmpdir.join("venv"))])
diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py
--- a/tests/test_virtualenv.py
+++ b/tests/test_virtualenv.py
@@ -5,10 +5,14 @@
 import tempfile
 
 import pytest
-from mock import NonCallableMock, call, patch
 
 import virtualenv
 
+try:
+    from unittest.mock import NonCallableMock, call, patch
+except ImportError:
+    from mock import NonCallableMock, call, patch
+
 
 def test_version():
     """Should have a version string"""