Skip to content

Commit

Permalink
Replace spaces in platform names with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
tucked committed Jan 5, 2023
1 parent 2067970 commit eeea378
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/packaging/tags.py
Expand Up @@ -467,8 +467,12 @@ def mac_platforms(
)


def _normalized_sysconfig_platform() -> str:
return _normalize_string(sysconfig.get_platform().replace(" ", "_"))


def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:
linux = _normalize_string(sysconfig.get_platform())
linux = _normalized_sysconfig_platform()
if is_32bit:
if linux == "linux_x86_64":
linux = "linux_i686"
Expand All @@ -481,7 +485,7 @@ def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:


def _generic_platforms() -> Iterator[str]:
yield _normalize_string(sysconfig.get_platform())
yield _normalized_sysconfig_platform()


def platform_tags() -> Iterator[str]:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_tags.py
Expand Up @@ -603,6 +603,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 @@ -774,6 +781,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 @@ -901,6 +914,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

0 comments on commit eeea378

Please sign in to comment.