Skip to content

Commit bed76e6

Browse files
asottilegaborbernat
authored andcommitted
Improve --devenv help and ensure --devenv does not delete (#1333)
1 parent 1554104 commit bed76e6

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/tox/config/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,12 @@ def tox_addoption(parser):
416416
help="work against specified environments (ALL selects all).",
417417
)
418418
parser.add_argument(
419-
"--devenv", help="sets up a development environment based on the tox configuration."
419+
"--devenv",
420+
metavar="ENVDIR",
421+
help=(
422+
"sets up a development environment at ENVDIR based on the env's tox "
423+
"configuration specified by `-e` (-e defaults to py)."
424+
),
420425
)
421426
parser.add_argument("--notest", action="store_true", help="skip invoking test commands.")
422427
parser.add_argument(
@@ -501,7 +506,7 @@ def tox_addoption(parser):
501506
)
502507

503508
def _set_envdir_from_devenv(testenv_config, value):
504-
if testenv_config.config.option.devenv:
509+
if testenv_config.config.option.devenv is not None:
505510
return py.path.local(testenv_config.config.option.devenv)
506511
else:
507512
return value
@@ -761,7 +766,7 @@ def pip_pre(testenv_config, value):
761766

762767
def develop(testenv_config, value):
763768
option = testenv_config.config.option
764-
return not option.installpkg and (value or option.develop or bool(option.devenv))
769+
return not option.installpkg and (value or option.develop or option.devenv is not None)
765770

766771
parser.add_testenv_attribute(
767772
name="usedevelop",
@@ -1116,10 +1121,10 @@ def run(name, section, subs, config):
11161121

11171122
config.skipsdist = reader.getbool("skipsdist", all_develop)
11181123

1119-
if config.option.devenv:
1124+
if config.option.devenv is not None:
11201125
config.option.notest = True
11211126

1122-
if config.option.devenv and len(config.envlist) != 1:
1127+
if config.option.devenv is not None and len(config.envlist) != 1:
11231128
feedback("--devenv requires only a single -e", sysexit=True)
11241129

11251130
def handle_provision(self, config, reader):
@@ -1267,7 +1272,7 @@ def _getenvdata(self, reader, config):
12671272
(os.environ.get(PARALLEL_ENV_VAR_KEY), True),
12681273
(from_option, True),
12691274
(from_environ, True),
1270-
("py" if self.config.option.devenv else None, False),
1275+
("py" if self.config.option.devenv is not None else None, False),
12711276
(from_config, False),
12721277
)
12731278
env_str, envlist_explicit = next(((i, e) for i, e in candidates if i), ([], False))

tests/unit/test_z_cmdline.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,27 @@ def test_devenv_does_not_allow_multiple_environments(initproj, cmd):
835835
assert result.err == "ERROR: --devenv requires only a single -e\n"
836836

837837

838+
def test_devenv_does_not_delete_project(initproj, cmd):
839+
initproj(
840+
"example123",
841+
filedefs={
842+
"setup.py": """\
843+
from setuptools import setup
844+
setup(name='x')
845+
""",
846+
"tox.ini": """\
847+
[tox]
848+
envlist=foo,bar,baz
849+
""",
850+
},
851+
)
852+
853+
result = cmd("--devenv", "")
854+
result.assert_fail()
855+
assert "would delete project" in result.out
856+
assert "ERROR: ConfigError: envdir must not equal toxinidir" in result.out
857+
858+
838859
def test_PYC(initproj, cmd, monkeypatch):
839860
initproj("example123", filedefs={"tox.ini": ""})
840861
monkeypatch.setenv("PYTHONDOWNWRITEBYTECODE", "1")

0 commit comments

Comments
 (0)