3 new commits in tox: https://bitbucket.org/hpk42/tox/commits/521459223e52/ Changeset: 521459223e52 User: hpk42 Date: 2015-06-18 14:07:12+00:00 Summary: allow all env variables during installation of dependencies Affected #: 7 files
diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +2.1.0 +---------- + +- fix issue258, fix issue248, fix issue253: for non-test commands + (installation, venv creation) we pass in the full invocation environment. + 2.0.2 ---------- diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 doc/config.txt --- a/doc/config.txt +++ b/doc/config.txt @@ -195,14 +195,16 @@ A list of wildcard environment variable names which shall be copied from the tox invocation environment to the test - environment. If a specified environment variable doesn't exist in the tox - invocation environment it is ignored. You can use ``*`` and ``?`` to - match multiple environment variables with one name. + environment when executing test commands. If a specified environment + variable doesn't exist in the tox invocation environment it is ignored. + You can use ``*`` and ``?`` to match multiple environment variables with + one name. - Note that the ``PATH`` and ``PIP_INDEX_URL`` variables are unconditionally - passed down and on Windows ``SYSTEMROOT``, ``PATHEXT``, ``TEMP`` and ``TMP`` - will be passed down as well whereas on unix ``TMPDIR`` will be passed down. - You can override these variables with the ``setenv`` option. + Note that the ``PATH``, ``LANG`` and ``PIP_INDEX_URL`` variables are + unconditionally passed down and on Windows ``SYSTEMROOT``, ``PATHEXT``, + ``TEMP`` and ``TMP`` will be passed down as well whereas on unix + ``TMPDIR`` will be passed down. You can override these variables + with the ``setenv`` option. .. confval:: recreate=True|False(default) diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 setup.py --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ description='virtualenv-based automation of test activities', long_description=open("README.rst").read(), url='http://tox.testrun.org/', - version='2.0.2', + version='2.1.0.dev1', license='http://opensource.org/licenses/MIT', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], author='holger krekel', diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 tests/test_venv.py --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -510,6 +510,7 @@ def test_env_variables_added_to_pcall(tmpdir, mocksession, newconfig, monkeypatch): pkg = tmpdir.ensure("package.tar.gz") monkeypatch.setenv("X123", "123") + monkeypatch.setenv("YY", "456") config = newconfig([], """ [testenv:python] commands=python -V @@ -533,9 +534,12 @@ assert env['ENV_VAR'] == 'value' assert env['VIRTUAL_ENV'] == str(venv.path) assert env['X123'] == "123" + # all env variables are passed for installation + assert l[0].env["YY"] == "456" + assert "YY" not in l[1].env assert set(["ENV_VAR", "VIRTUAL_ENV", "PYTHONHASHSEED", "X123", "PATH"])\ - .issubset(env) + .issubset(l[1].env) # for e in os.environ: # assert e in env diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 tox/__init__.py --- a/tox/__init__.py +++ b/tox/__init__.py @@ -1,5 +1,5 @@ # -__version__ = '2.0.2' +__version__ = '2.1.0.dev1' from .hookspecs import hookspec, hookimpl # noqa diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 tox/config.py --- a/tox/config.py +++ b/tox/config.py @@ -409,8 +409,11 @@ parser.add_testenv_attribute( name="passenv", type="space-separated-list", postprocess=passenv, - help="environment variables names which shall be passed " - "from tox invocation to test environment when executing commands.") + help="environment variables needed during executing test commands " + "(taken from invocation environment). Not that tox always " + "passes in some basic environment variables which are needed for " + "basic functioning of the Python interpreter. See --showconfig " + "for the resulting passenv setting.") parser.add_testenv_attribute( name="whitelist_externals", type="line-list", diff -r 6d4378ce90621105cda12fb2f9dfc67dfbefc7ca -r 521459223e524337d187ef07277f0ee1485cd313 tox/venv.py --- a/tox/venv.py +++ b/tox/venv.py @@ -317,16 +317,22 @@ action=action, extraenv=extraenv) def _getenv(self, extraenv={}): - env = {} - for envname in self.envconfig.passenv: - if envname in os.environ: - env[envname] = os.environ[envname] + if extraenv is None: + # for executing tests + env = {} + for envname in self.envconfig.passenv: + if envname in os.environ: + env[envname] = os.environ[envname] + else: + # for executing install commands + env = os.environ.copy() env.update(self.envconfig.setenv) env['VIRTUAL_ENV'] = str(self.path) + if extraenv is not None: + env.update(extraenv) - env.update(extraenv) return env def test(self, redirect=False): @@ -357,7 +363,7 @@ try: self._pcall(argv, cwd=cwd, action=action, redirect=redirect, - ignore_ret=ignore_ret) + ignore_ret=ignore_ret, extraenv=None) except tox.exception.InvocationError as err: self.session.report.error(str(err)) self.status = "commands failed" https://bitbucket.org/hpk42/tox/commits/4091d0ea77e8/ Changeset: 4091d0ea77e8 User: hpk42 Date: 2015-06-18 14:07:13+00:00 Summary: remove --set-home option which probably nobody used and was hackily implemented Affected #: 4 files diff -r 521459223e524337d187ef07277f0ee1485cd313 -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,11 @@ - fix issue258, fix issue248, fix issue253: for non-test commands (installation, venv creation) we pass in the full invocation environment. +- remove experimental --set-home option which was hardly used and + hackily implemented (if people want home-directory isolation we should + figure out a better way to do it, possibly through a plugin) + + 2.0.2 ---------- diff -r 521459223e524337d187ef07277f0ee1485cd313 -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 tests/test_venv.py --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -619,48 +619,3 @@ assert x4.endswith(os.sep + 'x') mocksession.report.expect("warning", "*test command found but not*") - -def test_sethome_only_on_option(newmocksession, monkeypatch): - mocksession = newmocksession([], "") - venv = mocksession.getenv('python') - action = mocksession.newaction(venv, "qwe", []) - monkeypatch.setattr(tox.venv, "hack_home_env", None) - venv._install(["x"], action=action) - - -def test_sethome_works_on_option(newmocksession, monkeypatch): - mocksession = newmocksession(["--set-home", "-i ALL=http://qwe"], "") - venv = mocksession.getenv('python') - action = mocksession.newaction(venv, "qwe", []) - venv._install(["x"], action=action) - _, mocked = mocksession.report.getnext("logpopen") - p = mocked.env["HOME"] - pydist = py.path.local(p).join(".pydistutils.cfg") - assert "http://qwe" in pydist.read() - - -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 - - -def test_hack_home_env_passthrough(tmpdir, monkeypatch): - from tox.venv import hack_home_env - env = hack_home_env(tmpdir, "http://index") - monkeypatch.setattr(os, "environ", env) - - tmpdir = tmpdir.mkdir("tmpdir2") - env2 = hack_home_env(tmpdir) - assert env2["HOME"] == str(tmpdir) - assert env2["PIP_INDEX_URL"] == "http://index" - assert "index_url = http://index" in \ - tmpdir.join(".pydistutils.cfg").read() diff -r 521459223e524337d187ef07277f0ee1485cd313 -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 tox/config.py --- a/tox/config.py +++ b/tox/config.py @@ -283,10 +283,6 @@ parser.add_argument("--develop", action="store_true", dest="develop", help="install package in the venv using 'setup.py develop' via " "'pip -e .'") - parser.add_argument("--set-home", action="store_true", dest="sethome", - help="(experimental) force creating a new $HOME for each test " - "environment and create .pydistutils.cfg|pip.conf files " - "if index servers are specified with tox. ") parser.add_argument('-i', action="append", dest="indexurl", metavar="URL", help="set indexserver url (if URL is of form name=url set the " @@ -410,10 +406,10 @@ parser.add_testenv_attribute( name="passenv", type="space-separated-list", postprocess=passenv, help="environment variables needed during executing test commands " - "(taken from invocation environment). Not that tox always " - "passes in some basic environment variables which are needed for " - "basic functioning of the Python interpreter. See --showconfig " - "for the resulting passenv setting.") + "(taken from invocation environment). Note that tox always " + "passes through some basic environment variables which are " + "needed for basic functioning of the Python system. " + "See --showconfig for the eventual passenv setting.") parser.add_testenv_attribute( name="whitelist_externals", type="line-list", diff -r 521459223e524337d187ef07277f0ee1485cd313 -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 tox/venv.py --- a/tox/venv.py +++ b/tox/venv.py @@ -259,9 +259,7 @@ l.append("--pre") return l - def run_install_command(self, packages, options=(), - indexserver=None, action=None, - extraenv=None): + def run_install_command(self, packages, options=(), action=None): argv = self.envconfig.install_command[:] # use pip-script on win32 to avoid the executable locking i = argv.index('{packages}') @@ -277,10 +275,7 @@ pass old_stdout = sys.stdout sys.stdout = codecs.getwriter('utf8')(sys.stdout) - if extraenv is None: - extraenv = {} - self._pcall(argv, cwd=self.envconfig.config.toxinidir, - extraenv=extraenv, action=action) + self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action) sys.stdout = old_stdout def _install(self, deps, extraopts=None, action=None): @@ -302,31 +297,26 @@ assert ixserver.url is None or isinstance(ixserver.url, str) for ixserver in l: - if self.envconfig.config.option.sethome: - extraenv = hack_home_env( - homedir=self.envconfig.envtmpdir.join("pseudo-home"), - index_url=ixserver.url) - else: - extraenv = {} - packages = d[ixserver] options = self._installopts(ixserver.url) if extraopts: options.extend(extraopts) self.run_install_command(packages=packages, options=options, - action=action, extraenv=extraenv) + action=action) def _getenv(self, extraenv={}): if extraenv is None: - # for executing tests + # for executing tests we construct a clean environment env = {} for envname in self.envconfig.passenv: if envname in os.environ: env[envname] = os.environ[envname] else: - # for executing install commands + # for executing non-test commands we use the full + # invocation environment env = os.environ.copy() + # in any case we honor per-testenv setenv configuration env.update(self.envconfig.setenv) env['VIRTUAL_ENV'] = str(self.path) @@ -405,24 +395,3 @@ return "0" * 32 return path.computehash() - -def hack_home_env(homedir, index_url=None): - # 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 not index_url: - index_url = os.environ.get("TOX_INDEX_URL") - if index_url: - homedir.join(".pydistutils.cfg").write( - "[easy_install]\n" - "index_url = %s\n" % index_url) - d["PIP_INDEX_URL"] = index_url - d["TOX_INDEX_URL"] = index_url - return d https://bitbucket.org/hpk42/tox/commits/673d3f1f8d09/ Changeset: 673d3f1f8d09 User: hpk42 Date: 2015-06-18 14:07:14+00:00 Summary: cleanup internal env variable code a bit Affected #: 3 files diff -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 -r 673d3f1f8d095cd8e1733506ffdc2f162b93e59b tests/test_venv.py --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -618,4 +618,3 @@ x4 = venv.getcommandpath("x", cwd=tmpdir) assert x4.endswith(os.sep + 'x') mocksession.report.expect("warning", "*test command found but not*") - diff -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 -r 673d3f1f8d095cd8e1733506ffdc2f162b93e59b tox/config.py --- a/tox/config.py +++ b/tox/config.py @@ -295,11 +295,9 @@ dest="recreate", help="force recreation of virtual environments") parser.add_argument("--result-json", action="store", - dest="resultjson", metavar="PATH", - help="write a json file with detailed information about " - "all commands and results involved. This will turn off " - "pass-through output from running test commands which is " - "instead captured into the json result file.") + dest="resultjson", metavar="PATH", + help="write a json file with detailed information about " + "all commands and results involved.") # We choose 1 to 4294967295 because it is the range of PYTHONHASHSEED. parser.add_argument("--hashseed", action="store", diff -r 4091d0ea77e84887031b2fb34050c5da8d8bc252 -r 673d3f1f8d095cd8e1733506ffdc2f162b93e59b tox/venv.py --- a/tox/venv.py +++ b/tox/venv.py @@ -267,12 +267,11 @@ if '{opts}' in argv: i = argv.index('{opts}') argv[i:i + 1] = list(options) + for x in ('PIP_RESPECT_VIRTUALENV', 'PIP_REQUIRE_VIRTUALENV', '__PYVENV_LAUNCHER__'): - try: - del os.environ[x] - except KeyError: - pass + os.environ.pop(x, None) + old_stdout = sys.stdout sys.stdout = codecs.getwriter('utf8')(sys.stdout) self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action) @@ -304,8 +303,8 @@ self.run_install_command(packages=packages, options=options, action=action) - def _getenv(self, extraenv={}): - if extraenv is None: + def _getenv(self, testcommand=False): + if testcommand: # for executing tests we construct a clean environment env = {} for envname in self.envconfig.passenv: @@ -320,9 +319,6 @@ env.update(self.envconfig.setenv) env['VIRTUAL_ENV'] = str(self.path) - if extraenv is not None: - env.update(extraenv) - return env def test(self, redirect=False): @@ -331,7 +327,7 @@ self.status = 0 self.session.make_emptydir(self.envconfig.envtmpdir) cwd = self.envconfig.changedir - env = self._getenv() + env = self._getenv(testcommand=True) # Display PYTHONHASHSEED to assist with reproducibility. action.setactivity("runtests", "PYTHONHASHSEED=%r" % env.get('PYTHONHASHSEED')) for i, argv in enumerate(self.envconfig.commands): @@ -353,7 +349,7 @@ try: self._pcall(argv, cwd=cwd, action=action, redirect=redirect, - ignore_ret=ignore_ret, extraenv=None) + ignore_ret=ignore_ret, testcommand=True) except tox.exception.InvocationError as err: self.session.report.error(str(err)) self.status = "commands failed" @@ -364,20 +360,18 @@ self.session.report.error(self.status) raise - def _pcall(self, args, venv=True, cwd=None, extraenv={}, + def _pcall(self, args, cwd, venv=True, testcommand=False, action=None, redirect=True, ignore_ret=False): for name in ("VIRTUALENV_PYTHON", "PYTHONDONTWRITEBYTECODE"): - try: - del os.environ[name] - except KeyError: - pass - assert cwd + os.environ.pop(name, None) + cwd.ensure(dir=1) old = self.patchPATH() try: args[0] = self.getcommandpath(args[0], venv, cwd) - env = self._getenv(extraenv) - return action.popen(args, cwd=cwd, env=env, redirect=redirect, ignore_ret=ignore_ret) + env = self._getenv(testcommand=testcommand) + return action.popen(args, cwd=cwd, env=env, + redirect=redirect, ignore_ret=ignore_ret) finally: os.environ['PATH'] = old @@ -394,4 +388,3 @@ if not path.check(file=1): return "0" * 32 return path.computehash() - 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. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit