From 80e872eb25f7062ce17c2df12d498ccd31d4f680 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 1 Jun 2019 12:07:47 -0700 Subject: [PATCH] Improve --devenv help and ensure `--devenv ` does not delete --- src/tox/config/__init__.py | 17 +++++++++++------ tests/unit/test_z_cmdline.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index dc57f775e..2ef07a463 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -416,7 +416,12 @@ def tox_addoption(parser): help="work against specified environments (ALL selects all).", ) parser.add_argument( - "--devenv", help="sets up a development environment based on the tox configuration." + "--devenv", + metavar="ENVDIR", + help=( + "sets up a development environment at ENVDIR based on the env's tox " + "configuration specified by `-e` (-e defaults to py)." + ), ) parser.add_argument("--notest", action="store_true", help="skip invoking test commands.") parser.add_argument( @@ -501,7 +506,7 @@ def tox_addoption(parser): ) def _set_envdir_from_devenv(testenv_config, value): - if testenv_config.config.option.devenv: + if testenv_config.config.option.devenv is not None: return py.path.local(testenv_config.config.option.devenv) else: return value @@ -761,7 +766,7 @@ def pip_pre(testenv_config, value): def develop(testenv_config, value): option = testenv_config.config.option - return not option.installpkg and (value or option.develop or bool(option.devenv)) + return not option.installpkg and (value or option.develop or option.devenv is not None) parser.add_testenv_attribute( name="usedevelop", @@ -1116,10 +1121,10 @@ def run(name, section, subs, config): config.skipsdist = reader.getbool("skipsdist", all_develop) - if config.option.devenv: + if config.option.devenv is not None: config.option.notest = True - if config.option.devenv and len(config.envlist) != 1: + if config.option.devenv is not None and len(config.envlist) != 1: feedback("--devenv requires only a single -e", sysexit=True) def handle_provision(self, config, reader): @@ -1267,7 +1272,7 @@ def _getenvdata(self, reader, config): (os.environ.get(PARALLEL_ENV_VAR_KEY), True), (from_option, True), (from_environ, True), - ("py" if self.config.option.devenv else None, False), + ("py" if self.config.option.devenv is not None else None, False), (from_config, False), ) env_str, envlist_explicit = next(((i, e) for i, e in candidates if i), ([], False)) diff --git a/tests/unit/test_z_cmdline.py b/tests/unit/test_z_cmdline.py index f193df4dc..53a4e50c6 100644 --- a/tests/unit/test_z_cmdline.py +++ b/tests/unit/test_z_cmdline.py @@ -835,6 +835,27 @@ def test_devenv_does_not_allow_multiple_environments(initproj, cmd): assert result.err == "ERROR: --devenv requires only a single -e\n" +def test_devenv_does_not_delete_project(initproj, cmd): + initproj( + "example123", + filedefs={ + "setup.py": """\ + from setuptools import setup + setup(name='x') + """, + "tox.ini": """\ + [tox] + envlist=foo,bar,baz + """, + }, + ) + + result = cmd("--devenv", "") + result.assert_fail() + assert "would delete project" in result.out + assert "ERROR: ConfigError: envdir must not equal toxinidir" in result.out + + def test_PYC(initproj, cmd, monkeypatch): initproj("example123", filedefs={"tox.ini": ""}) monkeypatch.setenv("PYTHONDOWNWRITEBYTECODE", "1")