Skip to content

Commit 69e5387

Browse files
committed
Merge branch 'mr/cardao/fix-e3-pypi-closure-bug' into 'master'
Fix wheel parsing See merge request it/e3-core!140
2 parents ddd6ff7 + 4e973de commit 69e5387

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/e3/python/pypi.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ def get_pip_env(platform: str, python_version: Version) -> dict[str, str]:
8181
class PyPILink:
8282
"""Link returned by PyPI simple API."""
8383

84+
# According to PEP0427 (https://peps.python.org/pep-0427/#file-name-convention)
85+
# The filename is:
86+
# {distribution}-{version}(-{build tags})?-{python tags}-{abi tags}-{platform tags}.whl # noqa: B950
87+
WHEEL_FILENAME_REGEX = re.compile(
88+
r"""
89+
^ # Start of the string
90+
(?P<distribution>[\w.-]+?) # Distribution name (aka identifier)
91+
-
92+
(?P<version>[\w.!+-]+) # Package version
93+
(?:- # Optional 'build tags' group
94+
(?P<build_tags>\d[a-zA-Z0-9_.]*) # Build tags (start with a number)
95+
)?
96+
-
97+
(?P<py_tags>py\d+|[a-zA-Z0-9_.]+) # Python tags (ex: py3, cp310, py2.py3)
98+
-
99+
(?P<abi_tags>[a-zA-Z0-9_.]+) # ABI tags (ex: abi3, cp310m, none)
100+
-
101+
(?P<platform_tags>[a-zA-Z0-9_.]+) # Plateform tags (ex: win_amd64, manylinux_x86_64, any) # noqa: B950
102+
\.whl # File extension .whl
103+
$ # End of the string
104+
""",
105+
re.VERBOSE | re.IGNORECASE,
106+
)
107+
84108
def __init__(
85109
self,
86110
identifier: str,
@@ -109,12 +133,16 @@ def __init__(
109133
py_tags = ""
110134
abi_tags = ""
111135
platform_tags = ""
136+
137+
wheel_filename = self.WHEEL_FILENAME_REGEX.match(self.filename)
112138
# Retreive a package version.
113-
if self.filename.endswith(".whl"):
139+
if wheel_filename:
114140
# Wheel filenames contain compatibility information
115-
_, version, py_tags, abi_tags, platform_tags = self.filename[:-4].rsplit(
116-
"-", 4
117-
)
141+
data = wheel_filename.groupdict()
142+
version = data["version"]
143+
py_tags = data["py_tags"]
144+
abi_tags = data["abi_tags"]
145+
platform_tags = data["platform_tags"]
118146
else:
119147
package_filename = self.filename
120148
if any(package_filename.endswith(ext) for ext in (".tar.gz", ".tar.bz2")):

0 commit comments

Comments
 (0)