Skip to content

Commit

Permalink
Update PyPI route pattern in url2purl #76
Browse files Browse the repository at this point in the history
    * Handle PyPI package names with hyphens and dots in it
    * Update test data and expectations

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Feb 11, 2022
1 parent e3cd36d commit 34fe6c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
- Do not create a generic PackageURL for URLs without a path in url2purl #72
- Increase the name field size for packageurl.contrib.django.models.PackageURLMixin to 255 #73
- Use project name as the Package name when creating generic sourceforge PackageURLs #74
- Update PyPI route pattern in url2purl to handle different file name formats #76

0.9.7 (2022-02-07)
------------------
Expand Down
7 changes: 5 additions & 2 deletions src/packageurl/contrib/url2purl.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,12 @@ def build_rubygems_purl(uri):


# https://pypi.python.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz
# https://pypi.python.org/packages/2.6/t/threadpool/threadpool-1.2.7-py2.6.egg
# https://pypi.python.org/packages/any/s/setuptools/setuptools-0.6c11-1.src.rpm
# https://files.pythonhosted.org/packages/84/d8/451842a5496844bb5c7634b231a2e4caf0d867d2e25f09b840d3b07f3d4b/multi_key_dict-2.0.win32.exe
pypi_pattern = (
r"(?P<name>.+)-(?P<version>.+)"
r"\.(zip|tar.gz|tar.bz2|.tgz)$"
r"(?P<name>(\w\.?)+(-\w+)*)-(?P<version>.+)"
r"\.(zip|tar.gz|tar.bz2|tgz|egg|rpm|exe)$"
)

# This pattern can be found in the following locations:
Expand Down
6 changes: 6 additions & 0 deletions tests/contrib/data/url2purl.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
"https://pypi.python.org/packages/f6/ae/bbc6a204f33d9d57c798fb3857a072cd14b836792244eea4b446fdb674c6/pycryptodome-3.4.7-cp27-cp27m-win32.whl#md5=78b341de1cd686077745cd9e3a93d8d3": "pkg:pypi/[email protected]",
"https://pypi.python.org/packages/bd/e8/ea44ba5357a0b4fd16e5fb60c355fc8722eae31b93d7597eec50f7c35a52/pycryptodome-3.4.7-cp27-cp27m-win_amd64.whl#md5=f20bb847322baf7ae24700e5cbb15e07": "pkg:pypi/[email protected]",
"https://pypi.python.org/packages/1e/75/8005d086cac4cc41d3b320d338972c5e5c6a21f88472f21ac9d0e031d300/pyahocorasick-1.1.4.tar.bz2#md5=ad445b6648dc06e9040705ce1ccb4384": "pkg:pypi/[email protected]",
"https://pypi.python.org/packages/2.6/t/threadpool/threadpool-1.2.7-py2.6.egg": "pkg:pypi/[email protected]",
"https://pypi.python.org/packages/any/s/setuptools/setuptools-0.6c11-1.src.rpm": "pkg:pypi/[email protected]",
"https://files.pythonhosted.org/packages/84/d8/451842a5496844bb5c7634b231a2e4caf0d867d2e25f09b840d3b07f3d4b/multi_key_dict-2.0.win32.exe": "pkg:pypi/[email protected]",
"https://pypi.python.org/packages/source/d/django-contrib-comments/django-contrib-comments-1.5.tar.gz": "pkg:pypi/[email protected]",
"https://files.pythonhosted.org/packages/40/90/df4cb5541c4f5016bbbe04dd09135c7f5af294efa3421f9ab6332cf30dc2/zc.buildout.languageserver-0.6.2.tar.gz": "pkg:pypi/[email protected]",
"https://files.pythonhosted.org/packages/b0/42/cac00d0570ff45c8d3b66aa32bf1aba7a527e5908123b0164e42f6af6ae1/zc.buildout.languageserver-0.6.2-py3-none-any.whl": "pkg:pypi/[email protected]",
"http://nuget.org/packages/EntityFramework/4.2.0.0": "pkg:nuget/[email protected]",
"http://www.nuget.org/packages/SharpGIS.GZipWebClient/1.2.0": "pkg:nuget/[email protected]",
"https://www.nuget.org/api/v2/package/Newtonsoft.Json/11.0.1": "pkg:nuget/[email protected]",
Expand Down

0 comments on commit 34fe6c2

Please sign in to comment.