Commits

mete0r_kr committed 5e3344f

use inlined virtualenv-1.9.1 and pip<1.4 for CPython 2.5 / Jython 2.5

Since virtualenv 1.10 and pip 1.4 has dropped python 2.5 support, use inlined virtualenv-1.9.1 and Pip<1.4 for CPython 2.5 / Jython 2.5

  • Participants
  • Parent commits 3be5bca
  • Branches use-venv191-pip13-for-python25

Comments (0)

Files changed (2)

tests/test_venv.py

 import os, sys
 from tox._venv import VirtualEnv, CreationConfig, getdigest
 from tox._venv import find_executable
+from tox._venv import _getinterpreterversion
 
 #def test_global_virtualenv(capfd):
 #    v = VirtualEnv()
     py.test.raises(tox.exception.InterpreterNotFound,
                    venv.getsupportedinterpreter)
 
+def test_getinterpreterversion():
+    from distutils.sysconfig import get_python_version
+    version = _getinterpreterversion(sys.executable)
+    assert version == get_python_version()
+
 def test_create(monkeypatch, mocksession, newconfig):
     config = newconfig([], """
         [testenv:py123]
 from __future__ import with_statement
 import sys, os, re
+import textwrap
+import subprocess
 import py
 import tox
 from tox._config import DepConfig
         if action is None:
             action = self.session.newaction(self, "create")
         config_interpreter = self.getsupportedinterpreter()
-        f, path, _ = py.std.imp.find_module("virtualenv")
-        f.close()
-        venvscript = path.rstrip("co")
-        #venvscript = py.path.local(tox.__file__).dirpath("virtualenv.py")
+        config_interpreter_version = _getinterpreterversion(config_interpreter)
+        use_venv191 = config_interpreter_version < '2.6'
+        use_pip13 = config_interpreter_version < '2.6'
+        if not use_venv191:
+            f, path, _ = py.std.imp.find_module("virtualenv")
+            f.close()
+            venvscript = path.rstrip("co")
+        else:
+            venvscript = py.path.local(tox.__file__).dirpath("virtualenv-1.9.1.py")
         args = [config_interpreter, venvscript]
         if self.envconfig.distribute:
             args.append("--distribute")
         args.append(self.path.basename)
         self._pcall(args, venv=False, action=action, cwd=basepath)
         self.just_created = True
+        if use_pip13:
+            indexserver = self.envconfig.config.indexserver['default']
+            action = self.session.newaction(self, "pip_downgrade")
+            action.setactivity('pip-downgrade', 'pip<1.4')
+            argv = ["easy_install"] + self._commoninstallopts(indexserver) + ['pip<1.4']
+            self._pcall(argv, cwd=self.envconfig.envlogdir, action=action)
 
     def finish(self):
         self._getliveconfig().writeconfig(self.path_config)
         self.session.report.verbosity2("setting PATH=%s" % os.environ["PATH"])
         return oldPATH
 
+def _getinterpreterversion(executable):
+    print_python_version = textwrap.dedent("""
+    from distutils.sysconfig import get_python_version
+    print(get_python_version())
+    """)
+    proc = subprocess.Popen([str(executable), '-c', print_python_version],
+                            stdout=subprocess.PIPE)
+    odata, edata = proc.communicate()
+    if proc.returncode:
+        raise tox.exception.UnsupportedInterpreter(
+            "Error getting python version from %s" % executable)
+    if sys.version_info[0] == 3:
+        string = str
+    else:
+        string = lambda x, encoding: str(x)
+    return string(odata, 'ascii').strip()
+
 def getdigest(path):
     path = py.path.local(path)
     if not path.check(file=1):