Skip to content

Commit

Permalink
Consider complete envs, not factors
Browse files Browse the repository at this point in the history
To determine whether we have been given a valid *env*, we compare the
*factors* of the *env* to our known set of *factors*. If a testenv
contains a series of valid factors, we assume the testenv is valid. This
is an incorrect assumption: a testenv is only valid if it defined in the
configuration file *or* is one of the "special" auto-generated testenvs
like e.g. 'py310'. Correct this mistake.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #3219
  • Loading branch information
stephenfin committed Feb 15, 2024
1 parent 47bcea6 commit 8e99154
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/tox/session/env_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
from collections import Counter
from dataclasses import dataclass
from difflib import get_close_matches
from itertools import chain
from typing import TYPE_CHECKING, Dict, Iterable, Iterator, List, cast

Expand Down Expand Up @@ -183,30 +182,21 @@ def _collect_names(self) -> Iterator[tuple[Iterable[str], bool]]:
yield label_envs.keys(), False

def _ensure_envs_valid(self) -> None:
valid_factors = set(chain.from_iterable(env.split("-") for env in self._state.conf))
valid_factors.add(".pkg") # packaging factor
defined_envs = set(self._state.conf)
defined_envs.add(".pkg") # packaging factor
invalid_envs: dict[str, str | None] = {}
for env in self._cli_envs or []:
if env.startswith(".pkg_external"): # external package
continue
factors: dict[str, str | None] = dict.fromkeys(env.split("-"))
found_factors: set[str] = set()
for factor in factors:
if (
_DYNAMIC_ENV_FACTORS.fullmatch(factor)
or _PY_PRE_RELEASE_FACTOR.fullmatch(factor)
or factor in valid_factors
):
found_factors.add(factor)
else:
closest = get_close_matches(factor, valid_factors, n=1)
factors[factor] = closest[0] if closest else None
if set(factors) - found_factors:
invalid_envs[env] = (
None
if any(i is None for i in factors.values())
else "-".join(cast(Iterable[str], factors.values()))
)

found_envs: set[str] = set()

if _DYNAMIC_ENV_FACTORS.fullmatch(env) or _PY_PRE_RELEASE_FACTOR.fullmatch(env) or env in defined_envs:
found_envs.add(env)

if set(self._cli_envs) - found_envs:
invalid_envs[env] = None

if invalid_envs:
msg = "provided environments not found in configuration file:\n"
first = True
Expand Down

0 comments on commit 8e99154

Please sign in to comment.