@@ -81,6 +81,30 @@ def get_pip_env(platform: str, python_version: Version) -> dict[str, str]:
81
81
class PyPILink :
82
82
"""Link returned by PyPI simple API."""
83
83
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
+
84
108
def __init__ (
85
109
self ,
86
110
identifier : str ,
@@ -109,12 +133,16 @@ def __init__(
109
133
py_tags = ""
110
134
abi_tags = ""
111
135
platform_tags = ""
136
+
137
+ wheel_filename = self .WHEEL_FILENAME_REGEX .match (self .filename )
112
138
# Retreive a package version.
113
- if self . filename . endswith ( ".whl" ) :
139
+ if wheel_filename :
114
140
# 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" ]
118
146
else :
119
147
package_filename = self .filename
120
148
if any (package_filename .endswith (ext ) for ext in (".tar.gz" , ".tar.bz2" )):
0 commit comments