From e54d3635aaebd1f0d862501efcf7840ab37bf527 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 26 May 2011 16:21:40 +0200 Subject: - rename environment to "setenv" to disambiguate a bit between test "environemnt" snad env-var settings - some docs for the new "setenv" directive --- doc/config.txt | 44 ++++++++++++++++++++++++-------------------- doc/example/basic.txt | 18 +++++++++++++++++- setup.py | 4 ++-- tests/test_config.py | 14 +++++++------- tests/test_venv.py | 4 ++-- tox/__init__.py | 2 +- tox/_config.py | 11 ++++++----- tox/_venv.py | 2 +- toxbootstrap.py | 2 +- 9 files changed, 61 insertions(+), 40 deletions(-) diff --git a/doc/config.txt b/doc/config.txt index 5cef3e2..180c41b 100644 --- a/doc/config.txt +++ b/doc/config.txt @@ -79,26 +79,6 @@ Complete list of settings that you can put into ``testenv*`` sections: change to this working directory when executing the test command. **default**: ``{toxinidir}`` -.. confval:: args_are_paths=BOOL - - treat positional arguments passed to ``tox`` as file system paths - and - if they exist on the filesystem - rewrite them according - to the ``changedir``. - **default**: True (due to the exists-on-filesystem check it's usually - safe to try rewriting). - -.. confval:: envtmpdir=path - - defines a temporary directory for the virtualenv which will be cleared - each time before the group of test commands is invoked. - **default**: ``{envdir}/tmp`` - -.. confval:: envlogdir=path - - defines a directory for logging where tox will put logs of tool - invocation. - **default**: ``{envdir}/log`` - .. confval:: deps=MULTI-LINE-LIST dependencies to be installed into the environment prior to project @@ -111,6 +91,10 @@ Complete list of settings that you can put into ``testenv*`` sections: deps = :myindex:pkg +.. confval:: setenv=MULTI-LINE-LIST + + each line contains a NAME=VALUE environment variable setting which + will be used for all command invocations. .. confval:: recreate=True|False(default) @@ -136,6 +120,26 @@ Complete list of settings that you can put into ``testenv*`` sections: have access to globally installed packages. **default:** False, meaning that virtualenvs will be created with ``--no-site-packages`` by default. +.. confval:: args_are_paths=BOOL + + treat positional arguments passed to ``tox`` as file system paths + and - if they exist on the filesystem - rewrite them according + to the ``changedir``. + **default**: True (due to the exists-on-filesystem check it's usually + safe to try rewriting). + +.. confval:: envtmpdir=path + + defines a temporary directory for the virtualenv which will be cleared + each time before the group of test commands is invoked. + **default**: ``{envdir}/tmp`` + +.. confval:: envlogdir=path + + defines a directory for logging where tox will put logs of tool + invocation. + **default**: ``{envdir}/log`` + .. confval:: indexserver .. versionadded:: 0.9 diff --git a/doc/example/basic.txt b/doc/example/basic.txt index 9bf0b68..7e93604 100644 --- a/doc/example/basic.txt +++ b/doc/example/basic.txt @@ -97,10 +97,26 @@ forcing re-creation of virtual environments .. versionadded:: 0.9 -To for tox to recreate a (particular) virtual environment:: +To force tox to recreate a (particular) virtual environment:: tox --recreate -e py27 would trigger a complete reinstallation of the existing py27 environment (or create it afresh if it doesn't exist). +setting environment variables +------------------------------------------- + +.. versionadded:: 1.0 + +If you need to set an environment variable like ``PYTHONPATH`` you +can use the ``setenv`` directive:: + + [testenv] + setenv = + PYTHONPATH = {toxinidir}/subdir + +When your test commands execute they will execute with +a PYTHONPATH setting that will lead Python to also import +from the ``subdir`` below the directory where your ``tox.ini`` +file resides. diff --git a/setup.py b/setup.py index 31bc427..71f72fe 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def main(): description='virtualenv-based automation of test activities', long_description=long_description, url='http://codespeak.net/tox', - version='1.0.dev3', + version='1.0.dev4', license='GPLv2 or later', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], author='holger krekel', @@ -57,4 +57,4 @@ def main(): ) if __name__ == '__main__': - main() + main() \ No newline at end of file diff --git a/tests/test_config.py b/tests/test_config.py index 7d2db89..0934e9c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -311,7 +311,7 @@ class TestConfigTestEnv: assert envconfig.distribute == True assert envconfig.sitepackages == False assert envconfig.envlogdir == envconfig.envdir.join("log") - assert envconfig.environment is None + assert envconfig.setenv is None def test_specific_command_overrides(self, tmpdir, newconfig): config = newconfig(""" @@ -352,19 +352,19 @@ class TestConfigTestEnv: envconfig = config.envconfigs['python'] assert envconfig.envpython == envconfig.envbindir.join("jython") - def test_environment_overrides(self, tmpdir, newconfig): + def test_setenv_overrides(self, tmpdir, newconfig): config = newconfig(""" [testenv] - environment = + setenv = PYTHONPATH = something ANOTHER_VAL=else """) assert len(config.envconfigs) == 1 envconfig = config.envconfigs['python'] - assert 'PYTHONPATH' in envconfig.environment - assert 'ANOTHER_VAL' in envconfig.environment - assert envconfig.environment['PYTHONPATH'] == 'something' - assert envconfig.environment['ANOTHER_VAL'] == 'else' + assert 'PYTHONPATH' in envconfig.setenv + assert 'ANOTHER_VAL' in envconfig.setenv + assert envconfig.setenv['PYTHONPATH'] == 'something' + assert envconfig.setenv['ANOTHER_VAL'] == 'else' def test_changedir_override(self, tmpdir, newconfig): config = newconfig(""" diff --git a/tests/test_venv.py b/tests/test_venv.py index 3def794..25f3d70 100644 --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -373,11 +373,11 @@ class TestVenvTest: assert 'PIP_RESPECT_VIRTUALENV' not in os.environ os.environ['PIP_RESPECT_VIRTUALENV'] = "1" -def test_session_environment_added_to_pcall(mocksession, newconfig): +def test_setenv_added_to_pcall(mocksession, newconfig): config = newconfig([], """ [testenv:python] commands=%s -V - environment = + setenv = ENV_VAR = value """ % sys.executable) mocksession._clearmocks() diff --git a/tox/__init__.py b/tox/__init__.py index 85b0fa3..9391450 100644 --- a/tox/__init__.py +++ b/tox/__init__.py @@ -1,5 +1,5 @@ # -__version__ = '1.0.dev3' +__version__ = '1.0.dev4' class exception: class Error(Exception): diff --git a/tox/_config.py b/tox/_config.py index 738da33..36ecfa3 100644 --- a/tox/_config.py +++ b/tox/_config.py @@ -209,9 +209,9 @@ class parseini: arg = vc.changedir.bestrelpath(origpath) args.append(arg) reader.addsubstitions(args) - vc.environment = reader.getdict(section, 'environment') - if not vc.environment: - vc.environment = None + vc.setenv = reader.getdict(section, 'setenv') + if not vc.setenv: + vc.setenv = None vc.commands = reader.getargvlist(section, "commands") vc.deps = [] @@ -411,11 +411,12 @@ class IniReader: def _replace_env(self, match): envkey = match.group('substitution_value') if not envkey: - raise tox.exception.ConfigError('env: requires an environment variable name') + raise tox.exception.ConfigError( + 'env: requires an environment variable name') if not envkey in os.environ: raise tox.exception.ConfigError( - "substitution env:%r: %r not found in environment" % + "substitution env:%r: unkown environment variable %r" % (envkey, envkey)) return os.environ[envkey] diff --git a/tox/_venv.py b/tox/_venv.py index 8128be4..fcb8acb 100644 --- a/tox/_venv.py +++ b/tox/_venv.py @@ -231,7 +231,7 @@ class VirtualEnv(object): def test(self): self.session.make_emptydir(self.envconfig.envtmpdir) cwd = self.envconfig.changedir - env = self.envconfig.environment + env = self.envconfig.setenv if env: env_arg = os.environ.copy() env_arg.update(env) diff --git a/toxbootstrap.py b/toxbootstrap.py index 39fb2f6..d375fb1 100644 --- a/toxbootstrap.py +++ b/toxbootstrap.py @@ -58,7 +58,7 @@ ToDo """ -__version__ = '1.0.dev3' +__version__ = '1.0.dev4' import sys import os -- cgit v1.2.1