diff --git a/packaging/tags.py b/packaging/tags.py index a0e1ea23..99aba79c 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -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. diff --git a/tests/test_tags.py b/tests/test_tags.py index 39515e8d..baae8880 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -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}" + )