[Pytest-commit] commit/tox: hpk42: during installation of packages HOME is now set to a pseudo

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Aug 13 23:34:44 CEST 2013


1 new commit in tox:

https://bitbucket.org/hpk42/tox/commits/6aec60d13d3a/
Changeset:   6aec60d13d3a
User:        hpk42
Date:        2013-08-13 23:34:12
Summary:     during installation of packages HOME is now set to a pseudo
location (envtmpdir/pseudo-home).  Also, if an index url was
specified a .pydistutils.cfg file will be written so that index_url
is set if a package contains a ``setup_requires``.
Affected #:  5 files

diff -r 9e74e6ff0c037ac8dc542f7bfefcc5928683b14e -r 6aec60d13d3a4fed9496efd7310e76bf2beaf529 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
 1.6.0.dev
 -----------------
 
+- during installation of dependencies HOME is set to a pseudo
+  location (envtmpdir/pseudo-home).  If an index url was specified
+  a .pydistutils.cfg file will be written so that index_url
+  is set if a package contains a ``setup_requires``. 
+
 - remove toxbootstrap.py for now because it is broken.
 
 - fix issue35: add new "install_command" testenv-option to configure the

diff -r 9e74e6ff0c037ac8dc542f7bfefcc5928683b14e -r 6aec60d13d3a4fed9496efd7310e76bf2beaf529 setup.py
--- a/setup.py
+++ b/setup.py
@@ -28,7 +28,7 @@
         description='virtualenv-based automation of test activities',
         long_description=open("README.rst").read(),
         url='http://tox.testrun.org/',
-        version='1.6rc1',
+        version='1.6rc2',
         license='http://opensource.org/licenses/MIT',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
         author='holger krekel',

diff -r 9e74e6ff0c037ac8dc542f7bfefcc5928683b14e -r 6aec60d13d3a4fed9496efd7310e76bf2beaf529 tests/test_venv.py
--- a/tests/test_venv.py
+++ b/tests/test_venv.py
@@ -611,3 +611,16 @@
     monkeypatch.setenv("PATH", str(tmpdir))
     x4 = venv.getcommandpath("x", cwd=tmpdir)
     mocksession.report.expect("warning", "*test command found but not*")
+
+def test_hack_home_env(tmpdir):
+    from tox._venv import hack_home_env
+    env = hack_home_env(tmpdir, "http://index")
+    assert env["HOME"] == str(tmpdir)
+    assert env["PIP_INDEX_URL"] == "http://index"
+    assert "index_url = http://index" in \
+           tmpdir.join(".pydistutils.cfg").read()
+    tmpdir.remove()
+    env = hack_home_env(tmpdir, None)
+    assert env["HOME"] == str(tmpdir)
+    assert not tmpdir.join(".pydistutils.cfg").check()
+    assert "PIP_INDEX_URL" not in env

diff -r 9e74e6ff0c037ac8dc542f7bfefcc5928683b14e -r 6aec60d13d3a4fed9496efd7310e76bf2beaf529 tox/__init__.py
--- a/tox/__init__.py
+++ b/tox/__init__.py
@@ -1,5 +1,5 @@
 #
-__version__ = '1.6rc1'
+__version__ = '1.6rc2'
 
 class exception:
     class Error(Exception):

diff -r 9e74e6ff0c037ac8dc542f7bfefcc5928683b14e -r 6aec60d13d3a4fed9496efd7310e76bf2beaf529 tox/_venv.py
--- a/tox/_venv.py
+++ b/tox/_venv.py
@@ -266,7 +266,8 @@
             l.append("--download-cache=%s" % self.envconfig.downloadcache)
         return l
 
-    def run_install_command(self, args, indexserver=None, action=None):
+    def run_install_command(self, args, indexserver=None, action=None,
+                            extraenv=None):
         argv = self.envconfig.install_command_argv[:]
         # use pip-script on win32 to avoid the executable locking
         if argv[0] == "pip" and sys.platform == "win32":
@@ -282,8 +283,10 @@
             except KeyError:
                 pass
         env = dict(PYTHONIOENCODING='utf_8')
-        self._pcall(argv, cwd=self.envconfig.envlogdir, extraenv=env,
-            action=action)
+        if extraenv is not None:
+            env.update(extraenv)
+        self._pcall(argv, cwd=self.envconfig.envlogdir,
+            extraenv=env, action=action)
 
     def _install(self, deps, extraopts=None, action=None):
         if not deps:
@@ -305,8 +308,12 @@
 
         extraopts = extraopts or []
         for ixserver in l:
+            extraenv = hack_home_env(
+                homedir=self.envconfig.envtmpdir.join("pseudo-home"),
+                index_url = ixserver.url)
             args = d[ixserver] + extraopts
-            self.run_install_command(args, ixserver.url, action)
+            self.run_install_command(args, ixserver.url, action,
+                                     extraenv=extraenv)
 
     def _getenv(self):
         env = self.envconfig.setenv
@@ -415,3 +422,22 @@
         # Python launcher py.exe
         if m:
             locate_via_py(*m.groups())
+
+
+def hack_home_env(homedir, index_url):
+    # XXX HACK (this could also live with tox itself, consider)
+    # if tox uses pip on a package that requires setup_requires
+    # the index url set with pip is usually not recognized
+    # because it is setuptools executing very early.
+    # We therefore run the tox command in an artifical home
+    # directory and set .pydistutils.cfg and pip.conf files
+    # accordingly.
+    if not homedir.check():
+        homedir.ensure(dir=1)
+    d = dict(HOME=str(homedir))
+    if index_url:
+        homedir.join(".pydistutils.cfg").write(
+            "[easy_install]\n"
+            "index_url = %s\n" % index_url)
+        d["PIP_INDEX_URL"] = index_url
+    return d

Repository URL: https://bitbucket.org/hpk42/tox/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list