Skip to content
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

-eALL should also include environment from envlist #1155

Merged
merged 1 commit into from
Feb 5, 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
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Eugene Yunak
Fernando L. Pereira
Florian Preinstorfer
Florian Schulze
Gonéri Le Bouder
Hazal Ozturk
Henk-Jaap Wagenaar
Ian Stapleton Cordasco
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1155.bugix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``-eALL`` command line argument now expands the ``envlist`` key and includes all its environment.
51 changes: 33 additions & 18 deletions src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,39 +1155,54 @@ def make_envconfig(self, name, section, subs, config, replace=True):
reader.addsubstitutions(**{env_attr.name: res})
return tc

def _getenvdata(self, reader, config):
candidates = (
os.environ.get(PARALLEL_ENV_VAR_KEY),
self.config.option.env,
os.environ.get("TOXENV"),
reader.getstring("envlist", replace=False),
)
env_str = next((i for i in candidates if i), [])
def _getallenvs(self, reader, extra_env_list=None):
extra_env_list = extra_env_list or []
env_str = reader.getstring("envlist", replace=False)
env_list = _split_env(env_str)
for env in extra_env_list:
if env not in env_list:
env_list.append(env)

# collect section envs
all_envs = OrderedDict((i, None) for i in env_list)
if "ALL" in all_envs:
all_envs.pop("ALL")
for section in self._cfg:
if section.name.startswith(testenvprefix):
all_envs[section.name[len(testenvprefix) :]] = None
if not all_envs:
all_envs["python"] = None
return list(all_envs.keys())

def _getenvdata(self, reader, config):
from_option = self.config.option.env
from_environ = os.environ.get("TOXENV")
from_config = reader.getstring("envlist", replace=False)

env_list = []
if (from_option and "ALL" in from_option) or (
not from_option and from_environ and "ALL" in from_environ.split(",")
):
all_envs = self._getallenvs(reader)
else:
candidates = (
os.environ.get(PARALLEL_ENV_VAR_KEY),
from_option,
from_environ,
from_config,
)
env_str = next((i for i in candidates if i), [])
env_list = _split_env(env_str)
all_envs = self._getallenvs(reader, env_list)

if not env_list:
env_list = all_envs

package_env = config.isolated_build_env
if config.isolated_build is True and package_env in all_envs:
all_envs.pop(package_env)

if not env_list or "ALL" in env_list:
env_list = list(all_envs.keys())
all_envs.remove(package_env)

if config.isolated_build is True and package_env in env_list:
msg = "isolated_build_env {} cannot be part of envlist".format(package_env)
raise tox.exception.ConfigError(msg)

all_env_list = list(all_envs.keys())
return env_list, all_env_list
return env_list, all_envs


def _split_env(env):
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ def test_sdist_specification(self, newconfig):
config = newconfig([], "")
assert not config.sdistsrc

def test_env_selection(self, newconfig, monkeypatch):
def test_env_selection_with_section_name(self, newconfig, monkeypatch):
inisource = """
[tox]
envlist = py36
Expand All @@ -2091,6 +2091,18 @@ def test_env_selection(self, newconfig, monkeypatch):
config = newconfig(["-espam"], inisource)
assert config.envlist == ["spam"]

def test_env_selection_expanded_envlist(self, newconfig, monkeypatch):
inisource = """
[tox]
envlist = py{36,35,27}
[testenv:py36]
basepython=python3.6
"""
config = newconfig([], inisource)
assert config.envlist == ["py36", "py35", "py27"]
config = newconfig(["-eALL"], inisource)
assert config.envlist == ["py36", "py35", "py27"]

def test_py_venv(self, newconfig):
config = newconfig(["-epy"], "")
env = config.envconfigs["py"]
Expand Down