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

feat: Include abiflags in version dectection (enabling 3.13t) #199

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ envlist =
black
flake8
mypy
{py37,py38,py39,py310,py311,pypy3}-toxlatest
{py37,py38,py39,py310,py311,py312,py313,pypy3}-toxlatest

[gh-actions]
python =
Expand All @@ -91,6 +91,7 @@ python =
3.10: py310
3.11: py311, black, flake8, mypy
3.12: py312
3.13: py313
pypy-3: pypy3

[testenv]
Expand Down
67 changes: 57 additions & 10 deletions src/tox_gh_actions/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from itertools import product
from itertools import permutations, product

from logging import getLogger
import os
import sys
from typing import Any, Dict, Iterable, List
import sysconfig
from typing import Any, Dict, Iterable, Iterator, List, Tuple

from tox.config.cli.parser import Parsed
from tox.config.loader.memory import MemoryLoader
Expand Down Expand Up @@ -159,29 +160,75 @@ def get_envlist_from_factors(
return result


def get_abiflags() -> str:
"""Return ABI flags as a string of character codes.

POSIX builds provide sys.abiflags. This function constructs
an equivalent character code sequence for Windows by
parsing the EXT_SUFFIX configuration variable.
"""
try:
return sys.abiflags
except AttributeError: # Windows
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
if not ext_suffix:
return ""

# Looks like [_d].cp314[t]-win_amd64.pyd
prefix, cp3, suffix = ext_suffix.partition(".cp3")
if not cp3: # Before Python 3.10, hard-coded as ".pyd"
return ""

abiflags = ""
if prefix == "_d":
abiflags += "d"

if suffix.split("-", 1)[0].endswith("t"):
abiflags += "t"

return abiflags


def permuted_combinations(seq: str) -> Iterator[Tuple[str, ...]]:
"""Generate all combinations of any length and ordering.

>>> list(permuted_combinations("t"))
[(), ('t',)]
>>> list(permuted_combinations("td"))
[(), ('t',), ('d',), ('t', 'd'), ('d', 't')]
"""
for n in range(len(seq) + 1):
yield from permutations(seq, n)


def get_python_version_keys() -> List[str]:
"""Get Python version in string for getting factors from gh-action's config

Examples:
- CPython 3.8.z => [3.8, 3]
- PyPy 3.6 (v7.3.z) => [pypy-3.6, pypy-3, pypy3]
- PyPy 3.6 (v7.3.z) => [pypy-3.6, pypy-3]
- Pyston based on Python CPython 3.8.8 (v2.2) => [pyston-3.8, pyston-3]
- CPython 3.13.z (free-threading build) => [3.13t, 3.13, 3]
"""
major_version = str(sys.version_info[0])
major_minor_version = ".".join([str(i) for i in sys.version_info[:2]])
major, minor = sys.version_info[:2]
if "PyPy" in sys.version:
return [
"pypy-" + major_minor_version,
"pypy-" + major_version,
f"pypy-{major}.{minor}",
f"pypy-{major}",
]
elif hasattr(sys, "pyston_version_info"): # Pyston
return [
"pyston-" + major_minor_version,
"pyston-" + major_version,
f"pyston-{major}.{minor}",
f"pyston-{major}",
]
else:
# Assume this is running on CPython
return [major_minor_version, major_version]
ret = [f"{major}"]
ret.extend(
f"{major}.{minor}{''.join(flags)}"
for flags in permuted_combinations(get_abiflags())
)
return sorted(ret, reverse=True)


def is_running_on_actions() -> bool:
Expand Down
20 changes: 19 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,29 +247,47 @@ def test_get_envlist_from_factors(


@pytest.mark.parametrize(
"version,info,expected",
"version,info,abiflags,expected",
[
(
"3.8.1 (default, Jan 22 2020, 06:38:00) \n[GCC 9.2.0]",
(3, 8, 1, "final", 0),
"",
["3.8", "3"],
),
(
"3.6.9 (1608da62bfc7, Dec 23 2019, 10:50:04)\n"
"[PyPy 7.3.0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]",
(3, 6, 9, "final", 0),
"",
["pypy-3.6", "pypy-3"],
),
(
"3.13.0 experimental free-threading build (main, Oct 16 2024, 03:26:14) "
"[Clang 18.1.8 ]\n",
(3, 13, 0, "final", 0),
"t",
["3.13t", "3.13", "3"],
),
(
"3.13.0 experimental free-threading build (main, Oct 16 2024, 03:26:14) "
"[Clang 18.1.8 ]\n",
(3, 13, 0, "final", 0),
"td",
["3.13td", "3.13t", "3.13dt", "3.13d", "3.13", "3"],
),
],
)
def test_get_version_keys(
mocker: MockerFixture,
version: str,
info: Tuple[int, int, int, str, int],
abiflags: str,
expected: List[str],
) -> None:
mocker.patch("tox_gh_actions.plugin.sys.version", version)
mocker.patch("tox_gh_actions.plugin.sys.version_info", info)
mocker.patch("tox_gh_actions.plugin.sys.abiflags", abiflags)
assert plugin.get_python_version_keys() == expected


Expand Down