8000 Replace spaces in platform names with underscores (#620) · pypa/packaging@7013a60 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 7013a60

Browse files
authored
Replace spaces in platform names with underscores (#620)
1 parent 28c1a05 commit 7013a60

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/packaging/tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _get_config_var(name: str, warn: bool = False) -> Union[int, str, None]:
120120

121121

122122
def _normalize_string(string: str) -> str:
123-
return string.replace(".", "_").replace("-", "_")
123+
return string.replace(".", "_").replace("-", "_").replace(" ", "_")
124124

125125

126126
def _abi3_applies(python_version: PythonVersion) -> bool:

tests/test_tags.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ def test_platform_tags(platform_name, dispatch_func, monkeypatch):
599599
assert tags.platform_tags() == expected
600600

601601

602+
def test_platform_tags_space(monkeypatch):
603+
"""Ensure spaces in platform tags are normalized to underscores."""
604+
monkeypatch.setattr(platform, "system", lambda: "Isilon OneFS")
605+
monkeypatch.setattr(sysconfig, "get_platform", lambda: "isilon onefs")
606+
assert list(tags.platform_tags()) == ["isilon_onefs"]
607+
608+
602609
class TestCPythonABI:
603610
@pytest.mark.parametrize(
604611
"py_debug,gettotalrefcount,result",
@@ -770,6 +777,12 @@ def test_platforms_defaults_needs_underscore(self, monkeypatch):
770777
result = list(tags.cpython_tags((3, 11), abis=["whatever"]))
771778
assert tags.Tag("cp311", "whatever", "plat1") in result
772779

780+
def test_platform_name_space_normalization(self, monkeypatch):
781+
"""Ensure that spaces are translated to underscores in platform names."""
782+
monkeypatch.setattr(sysconfig, "get_platform", lambda: "isilon onefs")
783+
for tag in tags.cpython_tags():
784+
assert " " not in tag.platform
785+
773786
def test_major_only_python_version(self):
774787
result = list(tags.cpython_tags((3,), ["abi"], ["plat"]))
775788
assert result == [
@@ -839,9 +852,9 @@ def test__generic_abi_linux_cpython(self, monkeypatch):
839852
assert tags._generic_abi() == ["cp37m"]
840853

841854
def test__generic_abi_jp(self, monkeypatch):
842-
config = {"EXT_SUFFIX": ".return exactly this.so"}
855+
config = {"EXT_SUFFIX": ".return_exactly_this.so"}
843856
monkeypatch.setattr(sysconfig, "get_config_var", config.__getitem__)
844-
assert tags._generic_abi() == ["return exactly this"]
857+
assert tags._generic_abi() == ["return_exactly_this"]
845858

846859
def test__generic_abi_graal(self, monkeypatch):
847860
config = {"EXT_SUFFIX": ".graalpy-38-native-x86_64-darwin.so"}
@@ -897,6 +910,12 @@ def test_generic_platforms(self):
897910
platform = platform.replace(".", "_")
898911
assert list(tags._generic_platforms()) == [platform]
899912

913+
def test_generic_platforms_space(self, monkeypatch):
914+
"""Ensure platform tags normalize spaces to underscores."""
915+
platform_ = "isilon onefs"
916+
monkeypatch.setattr(sysconfig, "get_platform", lambda: platform_)
917+
assert list(tags._generic_platforms()) == [platform_.replace(" ", "_")]
918+
900919
def test_iterator_returned(self):
901920
result_iterator = tags.generic_tags("sillywalk33", ["abi"], ["plat1", "plat2"])
902921
assert isinstance(result_iterator, collections.abc.Iterator)

0 commit comments

Comments
 (0)
0