diff --git a/packaging/tags.py b/packaging/tags.py index 6b404b43..034c16bb 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -233,12 +233,13 @@ def _generic_abi() -> List[str]: # - linux: '.cpython-310-x86_64-linux-gnu.so' => cp310 # - mac: '.cpython-310-darwin.so' => cp310 # - win: '.cp310-win_amd64.pyd' => cp310 - # - pypy: '.pypy38-pp73-x86_64-linux-gnu.so' => pypy38-pp73 + # - pypy: '.pypy38-pp73-x86_64-linux-gnu.so' => pypy38_pp73 # - graalpy: '.graalpy-38-native-x86_64-darwin.dylib' - # => graalpy-38-native + # => graalpy_38_native ext_suffix = _get_config_var("EXT_SUFFIX", warn=True) - assert ext_suffix[0] == "." + if not isinstance(ext_suffix, str) or ext_suffix[0] != ".": + raise SystemError("invalid sysconfig.get_config_var('EXT_SUFFIX')") _, soabi, ext = ext_suffix.split(".") if soabi.startswith("cpython"): abi = "cp" + soabi.split("-")[1] diff --git a/tests/test_tags.py b/tests/test_tags.py index 873cf9be..c135da2e 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -845,9 +845,25 @@ def test__generic_abi_linux_cpython(self, monkeypatch): def test__generic_abi_jp(self, monkeypatch): config = {"EXT_SUFFIX": ".return exactly this.so"} monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__) - monkeypatch.setattr(tags, "interpreter_name", lambda: "other") assert tags._generic_abi() == ["return exactly this"] + def test__generic_abi_graal(self, monkeypatch): + config = {"EXT_SUFFIX": ".graalpy-38-native-x86_64-darwin.so"} + monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__) + assert tags._generic_abi() == ["graalpy_38_native"] + + def test__generic_abi_none(self, monkeypatch): + config = {"EXT_SUFFIX": "..so"} + monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__) + assert tags._generic_abi() == [] + + def test__generic_abi_none(self, monkeypatch): + config = {"EXT_SUFFIX": "invalid"} + monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__) + with pytest.raises(SystemError) as e: + tags._generic_abi() + assert "EXT_SUFFIX" in str(e.value) + def test__generic_abi_linux_pypy(self, monkeypatch): # issue gh-606 config = {