Skip to content

Commit

Permalink
Reintroduce support for arch-suffixed factors
Browse files Browse the repository at this point in the history
Apparently we need to support these.

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin committed Jan 9, 2023
1 parent c26da88 commit 66ff10d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/tox/tox_env/python/api.py
Expand Up @@ -130,11 +130,34 @@ def default_base_python(self, conf: Config, env_name: str | None) -> list[str]:
@classmethod
def extract_base_python(cls, env_name: str) -> str | None:
candidates: list[str] = []
for factor in env_name.split("-"):
factors = env_name.split("-")

def _parse_factor(factor: str) -> str | None:
spec = PythonSpec.from_string_spec(factor)
impl = spec.implementation or "python"
if impl.lower() in INTERPRETER_SHORT_NAMES and env_name is not None and spec.path is None:
candidates.append(factor)
return factor
return None

# unfortunately we have an exception to the "factors are delimited by dashes" rule: the architecture
# we must support e.g. py38-64, which means python3.8 (64 bit)
if len(factors) > 1 and "32" in factors or "64" in factors:
for arch in {"32", "64"}:
if arch not in factors:
continue
idx = factors.index(arch)
if idx == 0:
continue
factor = "-".join([factors[idx - 1], factors[idx]])
candidate = _parse_factor(factor)
if candidate:
candidates.append(candidate)
del factors[idx - 1 : idx + 1]

for factor in factors:
candidate = _parse_factor(factor)
if candidate:
candidates.append(candidate)
if candidates:
if len(candidates) > 1:
raise ValueError(f"conflicting factors {', '.join(candidates)} in {env_name}")
Expand Down
5 changes: 4 additions & 1 deletion tests/tox_env/python/test_python_api.py
Expand Up @@ -99,6 +99,9 @@ def test_base_python_env_no_conflict(env: str, base_python: list[str], ignore_co
("py310", ["py38", "py39"], "py310", ["py38", "py39"]),
("py3.11.1", ["py3.11.2"], "py3.11.1", ["py3.11.2"]),
("py3-64", ["py3-32"], "py3-64", ["py3-32"]),
("foo-py38-64-bar", ["python3"], "py38-64", ["python3"]),
("foo-py36-32", ["python3"], "py36-32", ["python3"]),
("py311-22", ["python3"], "py311", ["python3"]),
("py310-magic", ["py39"], "py310", ["py39"]),
],
ids=lambda a: "|".join(a) if isinstance(a, list) else str(a),
Expand All @@ -110,7 +113,7 @@ def test_base_python_env_conflict(
conflict: list[str],
ignore_conflict: bool,
) -> None:
if env == "py3-64":
if env == "py311-22":
raise pytest.skip("bug #2657")

if ignore_conflict:
Expand Down

0 comments on commit 66ff10d

Please sign in to comment.