Skip to content

Commit 8297153

Browse files
committed
Replace spaces in platform names with underscores
1 parent 606c71a commit 8297153

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,13 @@ def test_platform_tags(platform_name, dispatch_func, monkeypatch):
603603
assert tags.platform_tags() == expected
604604

605605

606+
def test_platform_tags_space(monkeypatch):
607+
"""Ensure spaces in platform tags are normalized to underscores."""
608+
monkeypatch.setattr(platform, "system", lambda: "Isilon OneFS")
609+
monkeypatch.setattr(sysconfig, "get_platform", lambda: "isilon onefs")
610+
assert list(tags.platform_tags()) == ["isilon_onefs"]
611+
612+
606613
class TestCPythonABI:
607614
@pytest.mark.parametrize(
608615
"py_debug,gettotalrefcount,result",
@@ -774,6 +781,12 @@ def test_platforms_defaults_needs_underscore(self, monkeypatch):
774781
result = list(tags.cpython_tags((3, 11), abis=["whatever"]))
775782
assert tags.Tag("cp311", "whatever", "plat1") in result
776783

784+
def test_platform_name_space_normalization(self, monkeypatch):
785+
"""Ensure that spaces are translated to underscores in platform names."""
786+
monkeypatch.setattr(sysconfig, "get_platform", lambda: "isilon onefs")
787+
for tag in tags.cpython_tags():
788+
assert " " not in tag.platform
789+
777790
def test_major_only_python_version(self):
778791
result = list(tags.cpython_tags((3,), ["abi"], ["plat"]))
779792
assert result == [
@@ -845,6 +858,12 @@ def test_generic_platforms(self):
845858
platform = platform.replace(".", "_")
846859
assert list(tags._generic_platforms()) == [platform]
847860

861+
def test_generic_platforms_space(self, monkeypatch):
862+
"""Ensure platform tags normalize spaces to underscores."""
863+
platform_ = "isilon onefs"
864+
monkeypatch.setattr(sysconfig, "get_platform", lambda: platform_)
865+
assert list(tags._generic_platforms()) == [platform_.replace(" ", "_")]
866+
848867
def test_iterator_returned(self):
849868
result_iterator = tags.generic_tags("sillywalk33", ["abi"], ["plat1", "plat2"])
850869
assert isinstance(result_iterator, collections.abc.Iterator)

0 commit comments

Comments
 (0)