Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Dec 15, 2022
1 parent c13c9db commit 924e32c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
3 changes: 1 addition & 2 deletions docs/changelog/2698.bugfix.rst
@@ -1,2 +1 @@
``TOX_SKIP_ENV`` environment variable now works again (it was unintentionally
broken in the tox 4.0.0 release)
``TOX_SKIP_ENV`` environment variable now works again - by :user:`mgedmin`.
13 changes: 5 additions & 8 deletions src/tox/session/env_select.py
Expand Up @@ -107,15 +107,12 @@ class _ToxEnvInfo:


class EnvSelector:

_warned_about: set[str] #: shared set of skipped environments that were already warned about

def __init__(self, state: State) -> None:
# needs core to load the default tox environment list
# to load the package environments of a run environments we need the run environment builder
# to load labels we need core + the run environment
self.on_empty_fallback_py = True
self._warned_about = set()
self._warned_about: set[str] = set() #: shared set of skipped environments that were already warned about
self._state = state
self._cli_envs: CliEnv | None = getattr(self._state.conf.options, "env", None)
self._defined_envs_: None | dict[str, _ToxEnvInfo] = None
Expand All @@ -128,6 +125,8 @@ def __init__(self, state: State) -> None:
self._provision: None | tuple[bool, str, MemoryLoader] = None

self._state.conf.core.add_config("labels", Dict[str, EnvList], {}, "core labels")
tox_env_filter_regex = os.environ.get("TOX_SKIP_ENV", "").strip()
self._filter_re = re.compile(tox_env_filter_regex) if tox_env_filter_regex else None

def _collect_names(self) -> Iterator[tuple[Iterable[str], bool]]:
""":return: sources of tox environments defined with name and if is marked as target to run"""
Expand Down Expand Up @@ -330,17 +329,15 @@ def iter(
:return: an iteration of tox environments
"""
tox_env_filter = os.environ.get("TOX_SKIP_ENV")
tox_env_filter_re = re.compile(tox_env_filter) if tox_env_filter is not None else None
for name, env_info in self._defined_envs.items():
if only_active and not env_info.is_active:
continue
if not package and not isinstance(env_info.env, RunToxEnv):
continue
if tox_env_filter_re is not None and tox_env_filter_re.match(name):
if self._filter_re is not None and self._filter_re.match(name):
if name not in self._warned_about:
LOGGER.warning("skip environment %s, matches filter %r", name, tox_env_filter_re.pattern)
self._warned_about.add(name)
LOGGER.warning("skip environment %s, matches filter %r", name, self._filter_re.pattern)
continue
yield name

Expand Down
12 changes: 2 additions & 10 deletions tests/session/test_env_select.py
Expand Up @@ -74,23 +74,15 @@ def test_factor_select(tox_project: ToxProjectCreator) -> None:

def test_tox_skip_env(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch) -> None:
monkeypatch.setenv("TOX_SKIP_ENV", "m[y]py")
ini = """
[tox]
env_list = py3{10,9},mypy
"""
project = tox_project({"tox.ini": ini})
project = tox_project({"tox.ini": "[tox]\nenv_list = py3{10,9},mypy"})
outcome = project.run("l", "--no-desc", "-q")
outcome.assert_success()
outcome.assert_out_err("py310\npy39\n", "")


def test_tox_skip_env_logs(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch) -> None:
monkeypatch.setenv("TOX_SKIP_ENV", "m[y]py")
ini = """
[tox]
env_list = py3{10,9},mypy
"""
project = tox_project({"tox.ini": ini})
project = tox_project({"tox.ini": "[tox]\nenv_list = py3{10,9},mypy"})
outcome = project.run("l", "--no-desc")
outcome.assert_success()
outcome.assert_out_err("ROOT: skip environment mypy, matches filter 'm[y]py'\npy310\npy39\n", "")

0 comments on commit 924e32c

Please sign in to comment.