Created
May 8, 2019 15:23
-
-
Save brettcannon/5a975a02fb3b1771838d61694e9826f1 to your computer and use it in GitHub Desktop.
Parse a wheel filename using packaging.tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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