Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions docs/changelog/59.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export normalize_isa and deprecate KNOWN_ARCHITECTURES - by :user:`rahuldevikar`.
8 changes: 7 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
"sphinxcontrib.mermaid",
]

extlinks = {
"issue": ("https://github.com/tox-dev/python-discovery/issues/%s", "#%s"),
"pull": ("https://github.com/tox-dev/python-discovery/pull/%s", "PR #%s"),
"user": ("https://github.com/%s", "@%s"),
}

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
}

templates_path = []
source_suffix = ".rst"
exclude_patterns = ["_build"]
exclude_patterns = ["_build", "changelog/*.rst"]

main_doc = "index"
pygments_style = "default"
Expand Down
3 changes: 2 additions & 1 deletion src/python_discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ._cache import ContentStore, DiskCache, PyInfoCache
from ._discovery import get_interpreter
from ._py_info import KNOWN_ARCHITECTURES, PythonInfo
from ._py_info import KNOWN_ARCHITECTURES, PythonInfo, normalize_isa
from ._py_spec import PythonSpec
from ._specifier import SimpleSpecifier, SimpleSpecifierSet, SimpleVersion

Expand All @@ -24,4 +24,5 @@
"SimpleVersion",
"__version__",
"get_interpreter",
"normalize_isa",
]
12 changes: 11 additions & 1 deletion src/python_discovery/_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,20 @@ def _possible_base(self) -> Generator[str, None, None]:
"x86",
"x86_64",
})
"""Known CPU architecture (ISA) values after normalization."""
"""Known CPU architecture (ISA) values after normalization.

.. deprecated::
Use :func:`normalize_isa` instead, which handles both known and unknown architectures.
"""


def normalize_isa(isa: str) -> str:
"""
Normalize an ISA (instruction set architecture) string to a canonical form.

Known aliases are mapped (e.g. ``amd64`` → ``x86_64``, ``aarch64`` → ``arm64``).
Unrecognized values are lowercased and returned as-is.
"""
low = isa.lower()
return {"amd64": "x86_64", "aarch64": "arm64", "i386": "x86", "i586": "x86"}.get(low, low)
Comment thread
rahuldevikar marked this conversation as resolved.
Outdated

Expand Down
4 changes: 2 additions & 2 deletions tests/py_info/test_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest
from setuptools.dist import Distribution

from python_discovery import KNOWN_ARCHITECTURES, DiskCache, PythonInfo, PythonSpec
from python_discovery import DiskCache, PythonInfo, PythonSpec
from python_discovery import _cached_py_info as cached_py_info
from python_discovery._py_info import VersionInfo

Expand Down Expand Up @@ -338,7 +338,7 @@ def test_py_info_machine_property() -> None:
assert machine is not None
assert isinstance(machine, str)
assert len(machine) > 0
assert machine in KNOWN_ARCHITECTURES, f"unexpected machine value: {machine}"
assert machine == machine.lower(), f"machine value should be lowercase: {machine}"


def test_py_info_machine_in_spec() -> None:
Expand Down
Loading