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

tags: add interpreter_abi #611

Open
wants to merge 1 commit into
base: main
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
6 changes: 6 additions & 0 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ def _version_nodot(version: PythonVersion) -> str:
return "".join(map(str, version))


def interpreter_abi() -> str:
if interpreter_name() == "cp":
return _cpython_abis(sys.version_info[:2])[0]
return next(_generic_abi())


def sys_tags(*, warn: bool = False) -> Iterator[Tag]:
"""
Returns the sequence of tag triples for the running interpreter.
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,3 +1239,18 @@ def test_cpython_first_none_any_tag(self, monkeypatch):

interpreter = f"cp{tags.interpreter_version()}"
assert tag == tags.Tag(interpreter, "none", "any")


def test_interpreter_abi(monkeypatch):
monkeypatch.setattr(tags, "interpreter_name", lambda: "pp")
monkeypatch.setattr(
sysconfig, "get_config_var", {"SOABI": "pypy39-pp73"}.__getitem__
)
assert tags.interpreter_abi() == "pypy39_pp73"

config = {"Py_DEBUG": 0, "WITH_PYMALLOC": 0, "Py_UNICODE_SIZE": 2}
monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__)
monkeypatch.setattr(tags, "interpreter_name", lambda: "cp")
assert (
tags.interpreter_abi() == f"cp{sys.version_info.major}{sys.version_info.minor}"
)