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

tags: make _platform_tags public #446

Merged
merged 2 commits into from Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions docs/tags.rst
Expand Up @@ -150,6 +150,11 @@ to the implementation to provide.
compatibility


.. function:: platform_tags(version=None, arch=None)

Yields the :attr:`~Tag.platform` tags for current installation.
brettcannon marked this conversation as resolved.
Show resolved Hide resolved


.. function:: compatible_tags(python_version=None, interpreter=None, platforms=None)

Yields the tags for an interpreter compatible with the Python version
Expand Down
8 changes: 4 additions & 4 deletions packaging/tags.py
Expand Up @@ -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_)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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_)
Expand Down Expand Up @@ -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.
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/test_tags.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")]

Expand Down Expand Up @@ -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"),
Expand Down