Skip to content

Improve --devenv help and ensure --devenv does not delete #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_z_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down