Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse a wheel filename using packaging.tags
import packaging.tags
def parse_wheel_filename(path):
name = os.path.splitext(_compat.fspath(path))[0]
index = len(name)
for _ in range(3): # interpreter, ABI, platform.
index = name.rindex("-", 0, index)
return packaging.tags.parse_tag(name[index + 1 :])
def test_parse_wheel_filename_simple(example_tag):
given = tags.parse_wheel_filename("gidgethub-3.0.0-py3-none-any.whl")
assert given == {example_tag}
def test_parse_wheel_filename_path(example_tag):
path = os.path.join("some", "location", "gidgethub-3.0.0-py3-none-any.whl")
given = tags.parse_wheel_filename(path)
assert given == {example_tag}
if pathlib and sys.version_info[:2] >= (3, 6):
filename = "gidgethub-3.0.0-py3-none-any.whl"
given = tags.parse_wheel_filename(
pathlib.PurePath("some") / "location" / filename
)
assert given == {example_tag}
def test_parse_wheel_filename_multi_interpreter(example_tag):
expected = {example_tag, tags.Tag("py2", "none", "any")}
given = tags.parse_wheel_filename("pip-18.0-py2.py3-none-any.whl")
assert given == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment