From ba07d8287b4554754ac7178d177033ea3f75d489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sat, 28 Aug 2021 00:00:50 +0100 Subject: [PATCH] make tags._platform_tags public (#446) --- docs/tags.rst | 5 +++++ packaging/tags.py | 8 ++++---- tests/test_tags.py | 12 ++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/tags.rst b/docs/tags.rst index 4d7e10ab..bb82728f 100644 --- a/docs/tags.rst +++ b/docs/tags.rst @@ -150,6 +150,11 @@ to the implementation to provide. compatibility +.. function:: platform_tags(version=None, arch=None) + + Yields the :attr:`~Tag.platform` tags for the running interpreter. + + .. function:: compatible_tags(python_version=None, interpreter=None, platforms=None) Yields the tags for an interpreter compatible with the Python version diff --git a/packaging/tags.py b/packaging/tags.py index 82a47cda..e65890a9 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -207,7 +207,7 @@ def cpython_tags( except ValueError: pass - platforms = list(platforms or _platform_tags()) + platforms = list(platforms or platform_tags()) for abi in abis: for platform_ in platforms: yield Tag(interpreter, abi, platform_) @@ -251,7 +251,7 @@ def generic_tags( interpreter = "".join([interp_name, interp_version]) if abis is None: abis = _generic_abi() - platforms = list(platforms or _platform_tags()) + platforms = list(platforms or platform_tags()) abis = list(abis) if "none" not in abis: abis.append("none") @@ -290,7 +290,7 @@ def compatible_tags( """ if not python_version: python_version = sys.version_info[:2] - platforms = list(platforms or _platform_tags()) + platforms = list(platforms or platform_tags()) for version in _py_interpreter_range(python_version): for platform_ in platforms: yield Tag(version, "none", platform_) @@ -431,7 +431,7 @@ def _generic_platforms() -> Iterator[str]: yield _normalize_string(sysconfig.get_platform()) -def _platform_tags() -> Iterator[str]: +def platform_tags() -> Iterator[str]: """ Provides the platform tags for this installation. """ diff --git a/tests/test_tags.py b/tests/test_tags.py index aa922f24..3b0d3170 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -561,11 +561,11 @@ def test_linux_platforms_not_manylinux_abi( ("Generic", "_generic_platforms"), ], ) -def test__platform_tags(platform_name, dispatch_func, monkeypatch): +def test_platform_tags(platform_name, dispatch_func, monkeypatch): expected = ["sillywalk"] monkeypatch.setattr(platform, "system", lambda: platform_name) monkeypatch.setattr(tags, dispatch_func, lambda: expected) - assert tags._platform_tags() == expected + assert tags.platform_tags() == expected class TestCPythonABI: @@ -730,12 +730,12 @@ def test_abi_defaults_needs_underscore(self, monkeypatch): assert tags.Tag("cp311", "none", "any") in result def test_platforms_defaults(self, monkeypatch): - monkeypatch.setattr(tags, "_platform_tags", lambda: ["plat1"]) + monkeypatch.setattr(tags, "platform_tags", lambda: ["plat1"]) result = list(tags.cpython_tags((3, 8), abis=["whatever"])) assert tags.Tag("cp38", "whatever", "plat1") in result def test_platforms_defaults_needs_underscore(self, monkeypatch): - monkeypatch.setattr(tags, "_platform_tags", lambda: ["plat1"]) + monkeypatch.setattr(tags, "platform_tags", lambda: ["plat1"]) result = list(tags.cpython_tags((3, 11), abis=["whatever"])) assert tags.Tag("cp311", "whatever", "plat1") in result @@ -847,7 +847,7 @@ def test_abis_default(self, monkeypatch): ] def test_platforms_default(self, monkeypatch): - monkeypatch.setattr(tags, "_platform_tags", lambda: ["plat"]) + monkeypatch.setattr(tags, "platform_tags", lambda: ["plat"]) result = list(tags.generic_tags(interpreter="sillywalk", abis=["none"])) assert result == [tags.Tag("sillywalk", "none", "plat")] @@ -985,7 +985,7 @@ def test_default_interpreter(self): ] def test_default_platforms(self, monkeypatch): - monkeypatch.setattr(tags, "_platform_tags", lambda: iter(["plat", "plat2"])) + monkeypatch.setattr(tags, "platform_tags", lambda: iter(["plat", "plat2"])) result = list(tags.compatible_tags((3, 1), "cp31")) assert result == [ tags.Tag("py31", "none", "plat"),