diff --git a/src/packaging/tags.py b/src/packaging/tags.py index 14bf982b..76d24341 100644 --- a/src/packaging/tags.py +++ b/src/packaging/tags.py @@ -120,7 +120,7 @@ def _get_config_var(name: str, warn: bool = False) -> Union[int, str, None]: def _normalize_string(string: str) -> str: - return string.replace(".", "_").replace("-", "_") + return string.replace(".", "_").replace("-", "_").replace(" ", "_") def _abi3_applies(python_version: PythonVersion) -> bool: diff --git a/tests/test_tags.py b/tests/test_tags.py index 7c854735..1ee62711 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -599,6 +599,13 @@ def test_platform_tags(platform_name, dispatch_func, monkeypatch): assert tags.platform_tags() == expected +def test_platform_tags_space(monkeypatch): + """Ensure spaces in platform tags are normalized to underscores.""" + monkeypatch.setattr(platform, "system", lambda: "Isilon OneFS") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "isilon onefs") + assert list(tags.platform_tags()) == ["isilon_onefs"] + + class TestCPythonABI: @pytest.mark.parametrize( "py_debug,gettotalrefcount,result", @@ -770,6 +777,12 @@ def test_platforms_defaults_needs_underscore(self, monkeypatch): result = list(tags.cpython_tags((3, 11), abis=["whatever"])) assert tags.Tag("cp311", "whatever", "plat1") in result + def test_platform_name_space_normalization(self, monkeypatch): + """Ensure that spaces are translated to underscores in platform names.""" + monkeypatch.setattr(sysconfig, "get_platform", lambda: "isilon onefs") + for tag in tags.cpython_tags(): + assert " " not in tag.platform + def test_major_only_python_version(self): result = list(tags.cpython_tags((3,), ["abi"], ["plat"])) assert result == [ @@ -839,9 +852,9 @@ def test__generic_abi_linux_cpython(self, monkeypatch): assert tags._generic_abi() == ["cp37m"] def test__generic_abi_jp(self, monkeypatch): - config = {"EXT_SUFFIX": ".return exactly this.so"} + config = {"EXT_SUFFIX": ".return_exactly_this.so"} monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__) - assert tags._generic_abi() == ["return exactly this"] + assert tags._generic_abi() == ["return_exactly_this"] def test__generic_abi_graal(self, monkeypatch): config = {"EXT_SUFFIX": ".graalpy-38-native-x86_64-darwin.so"} @@ -897,6 +910,12 @@ def test_generic_platforms(self): platform = platform.replace(".", "_") assert list(tags._generic_platforms()) == [platform] + def test_generic_platforms_space(self, monkeypatch): + """Ensure platform tags normalize spaces to underscores.""" + platform_ = "isilon onefs" + monkeypatch.setattr(sysconfig, "get_platform", lambda: platform_) + assert list(tags._generic_platforms()) == [platform_.replace(" ", "_")] + def test_iterator_returned(self): result_iterator = tags.generic_tags("sillywalk33", ["abi"], ["plat1", "plat2"]) assert isinstance(result_iterator, collections.abc.Iterator)