Skip to content

Commit 38eac12

Browse files
expose KNOWN_ARCHITECTURES as public API (#56)
- Add KNOWN_ARCHITECTURES frozenset to _py_info.py and export it from the package's public API - Expand normalize_isa() to also normalize i386 and i586 → x86 - Update test to reference the new constant instead of a hardcoded set Co-authored-by: Rahul Devikar <radevika@microsoft.com>
1 parent eabb812 commit 38eac12

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/python_discovery/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
from ._cache import ContentStore, DiskCache, PyInfoCache
88
from ._discovery import get_interpreter
9-
from ._py_info import PythonInfo
9+
from ._py_info import KNOWN_ARCHITECTURES, PythonInfo
1010
from ._py_spec import PythonSpec
1111
from ._specifier import SimpleSpecifier, SimpleSpecifierSet, SimpleVersion
1212

1313
__version__ = version("python-discovery")
1414

1515
__all__ = [
16+
"KNOWN_ARCHITECTURES",
1617
"ContentStore",
1718
"DiskCache",
1819
"PyInfoCache",

src/python_discovery/_py_info.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,23 @@ def _possible_base(self) -> Generator[str, None, None]:
768768
yield upper
769769

770770

771+
KNOWN_ARCHITECTURES: frozenset[str] = frozenset({
772+
"arm64",
773+
"i686",
774+
"loongarch64",
775+
"ppc64",
776+
"ppc64le",
777+
"riscv64",
778+
"s390x",
779+
"x86",
780+
"x86_64",
781+
})
782+
"""Known CPU architecture (ISA) values after normalization."""
783+
784+
771785
def normalize_isa(isa: str) -> str:
772786
low = isa.lower()
773-
return {"amd64": "x86_64", "aarch64": "arm64"}.get(low, low)
787+
return {"amd64": "x86_64", "aarch64": "arm64", "i386": "x86", "i586": "x86"}.get(low, low)
774788

775789

776790
def _main() -> None: # pragma: no cover

tests/py_info/test_py_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pytest
1515
from setuptools.dist import Distribution
1616

17-
from python_discovery import DiskCache, PythonInfo, PythonSpec
17+
from python_discovery import KNOWN_ARCHITECTURES, DiskCache, PythonInfo, PythonSpec
1818
from python_discovery import _cached_py_info as cached_py_info
1919
from python_discovery._py_info import VersionInfo
2020

@@ -338,8 +338,7 @@ def test_py_info_machine_property() -> None:
338338
assert machine is not None
339339
assert isinstance(machine, str)
340340
assert len(machine) > 0
341-
known_isas = {"arm64", "i686", "loongarch64", "ppc64", "ppc64le", "riscv64", "s390x", "x86", "x86_64"}
342-
assert machine in known_isas, f"unexpected machine value: {machine}"
341+
assert machine in KNOWN_ARCHITECTURES, f"unexpected machine value: {machine}"
343342

344343

345344
def test_py_info_machine_in_spec() -> None:

0 commit comments

Comments
 (0)