Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace spaces in platform names with underscores #620

Merged
merged 1 commit into from Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/packaging/tags.py
Expand Up @@ -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:
Expand Down
23 changes: 21 additions & 2 deletions tests/test_tags.py
Expand Up @@ -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",
Expand Down Expand Up @@ -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 == [
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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)
Expand Down