Skip to content

Commit

Permalink
tags: add interpreter_abi
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <[email protected]>
  • Loading branch information
FFY00 committed Nov 8, 2022
1 parent 606c71a commit 4ecc5ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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
13 changes: 13 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,3 +1239,16 @@ 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}"

0 comments on commit 4ecc5ee

Please sign in to comment.