|
38 | 38 | from urllib.parse import urlparse # Python 3
|
39 | 39 | from urllib.parse import unquote_plus
|
40 | 40 |
|
41 |
| -from pip._internal.wheel import Wheel |
42 |
| -from pip._internal.exceptions import InvalidWheelFilename |
43 |
| - |
44 | 41 | from packageurl import PackageURL
|
45 | 42 | from packageurl.contrib.route import Router
|
46 | 43 | from packageurl.contrib.route import NoRouteAvailable
|
@@ -187,25 +184,39 @@ def build_rubygems_purl(uri):
|
187 | 184 | return purl_from_pattern('rubygems', rubygems_pattern, uri)
|
188 | 185 |
|
189 | 186 |
|
190 |
| -# https://pypi.python.org/packages/source/p/python-openid/python-openid-2.2.5.zip |
| 187 | +# https://pypi.python.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz |
191 | 188 | pypi_pattern = (
|
192 | 189 | r"(?P<name>.+)-(?P<version>.+)"
|
193 |
| - r"\.(zip|tar.gz|tar.bz2)$" |
| 190 | + r"\.(zip|tar.gz|tar.bz2|.tgz)$" |
| 191 | +) |
| 192 | + |
| 193 | +# This pattern can be found in the following locations: |
| 194 | +# - wheel.wheelfile.WHEEL_INFO_RE |
| 195 | +# - distlib.wheel.FILENAME_RE |
| 196 | +# - setuptools.wheel.WHEEL_NAME |
| 197 | +# - pip._internal.wheel.Wheel.wheel_file_re |
| 198 | +wheel_file_re = re.compile( |
| 199 | + r"^(?P<namever>(?P<name>.+?)-(?P<version>.*?))" |
| 200 | + r"((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)" |
| 201 | + r"\.whl)$", |
| 202 | + re.VERBOSE |
194 | 203 | )
|
195 | 204 |
|
196 | 205 |
|
197 |
| -@purl_router.route('https?://pypi.python.org/packages/.*') |
| 206 | +@purl_router.route('https?://.+python.+org/packages/.*') |
198 | 207 | def build_pypi_purl(uri):
|
199 | 208 | path = unquote_plus(urlparse(uri).path)
|
200 | 209 | last_segment = path.split('/')[-1]
|
201 | 210 |
|
202 |
| - # https://pypi.python.org/packages/py2.py3/w/wheel/wheel-0.29.0-py2.py3-none-any.whl |
| 211 | + # /wheel-0.29.0-py2.py3-none-any.whl |
203 | 212 | if last_segment.endswith('.whl'):
|
204 |
| - try: |
205 |
| - wheel = Wheel(last_segment) |
206 |
| - except InvalidWheelFilename: |
207 |
| - return |
208 |
| - return PackageURL('pypi', name=wheel.name, version=wheel.version) |
| 213 | + match = wheel_file_re.match(last_segment) |
| 214 | + if match: |
| 215 | + return PackageURL( |
| 216 | + 'pypi', |
| 217 | + name=match.group('name'), |
| 218 | + version=match.group('version'), |
| 219 | + ) |
209 | 220 |
|
210 | 221 | return purl_from_pattern('pypi', pypi_pattern, last_segment)
|
211 | 222 |
|
|
0 commit comments