Skip to content

Commit 9ea1cea

Browse files
authored
Refactor the purl2url functions and utilities #42 (#102)
* Refactor purl2url into get_repo_url and get_download_url #42 Signed-off-by: Thomas Druez <[email protected]> * Add support for nuget in purl2url.get_download_url #42 Signed-off-by: Thomas Druez <[email protected]> * Add get_inferred_urls function to return all inferred URLs #42 Signed-off-by: Thomas Druez <[email protected]> * Include the `version_prefix` as a qualifier to infer valid URLs #42 Signed-off-by: Thomas Druez <[email protected]> * Fix formatting with black #42 Signed-off-by: Thomas Druez <[email protected]> * Add support for qualifiers in purl_from_pattern #42 Qualifier `download_url` is now supported in build_github_download_url Signed-off-by: Thomas Druez <[email protected]> * Return the download_url qualifier when available in get_download_url #42 Signed-off-by: Thomas Druez <[email protected]> * Add changelog entry #42 Signed-off-by: Thomas Druez <[email protected]>
1 parent e81d023 commit 9ea1cea

File tree

6 files changed

+455
-130
lines changed

6 files changed

+455
-130
lines changed

CHANGELOG.rst

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
Changelog
22
=========
33

4+
next ()
5+
-------
6+
7+
- Refactor the purl2url functions and utilities #42
8+
9+
- Split purl2url into `get_repo_url()` and `get_download_url()` returning
10+
accordingly a "Repository URL" and a "Download URL".
11+
- A new `get_inferred_urls` function is available to get return all
12+
inferred URLs (repository and download) values.
13+
- Add support in purl2url for npm, pypi, hackage, and nuget.
14+
- Package URL qualifiers can now be provided to `purl_from_pattern()`.
15+
- The `download_url` qualifier is returned in `get_download_url()` when available.
16+
17+
- Usage of `purl2url.purl2url` and `purl2url.get_url` is still available for
18+
backward compatibility but should be migrated to `purl2url.get_repo_url`.
19+
20+
- Include the `version_prefix` ("v" or "V") as a qualifier in build_github_purl #42
21+
This allow to infer valid URLs in the context of purl2url.
22+
423

524
0.10.3 (2022-09-15)
625
-------------------

README.rst

+43-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Join the discussion at https://gitter.im/package-url/Lobby or enter a ticket for
99

1010
License: MIT
1111

12-
1312
Tests and build status
1413
======================
1514

@@ -19,46 +18,79 @@ Tests and build status
1918
| |ci-tests| |
2019
+----------------------+
2120

21+
Install
22+
=======
23+
::
24+
25+
pip install packageurl-python
2226

2327
Usage
2428
=====
25-
2629
::
2730

2831
>>> from packageurl import PackageURL
32+
2933
>>> purl = PackageURL.from_string("pkg:maven/org.apache.commons/[email protected]")
3034
>>> print(purl.to_dict())
3135
{'type': 'maven', 'namespace': 'org.apache.commons', 'name': 'io', 'version': '1.3.4', 'qualifiers': None, 'subpath': None}
36+
3237
>>> print(purl.to_string())
3338
pkg:maven/org.apache.commons/[email protected]
39+
3440
>>> print(str(purl))
3541
pkg:maven/org.apache.commons/[email protected]
42+
3643
>>> print(repr(purl))
3744
PackageURL(type='maven', namespace='org.apache.commons', name='io', version='1.3.4', qualifiers={}, subpath=None)
3845

46+
Utilities
47+
=========
3948

40-
Other utilities:
49+
Django models
50+
^^^^^^^^^^^^^
4151

42-
- packageurl.contrib.django_models.PackageURLMixin is a Django abstract model mixin to use Package URLs in Django.
43-
- packageurl.contrib.purl2url.get_url(purl) returns the download URL inferred from a Package URL.
44-
- packageurl.contrib.url2purl.get_purl(url) returns a Package URL inferred from URL.
52+
`packageurl.contrib.django_models.PackageURLMixin` is a Django abstract model mixin to use Package URLs in Django.
4553

54+
URL to PURL
55+
^^^^^^^^^^^
56+
57+
`packageurl.contrib.url2purl.get_purl(url)` returns a Package URL inferred from an URL.
4658

47-
Install
48-
=======
4959
::
5060

51-
pip install packageurl-python
61+
>>> from packageurl.contrib import url2purl
62+
>>> url2purl.get_purl("https://github.com/package-url/packageurl-python")
63+
PackageURL(type='github', namespace='package-url', name='packageurl-python', version=None, qualifiers={}, subpath=None)
64+
65+
PURL to URL
66+
^^^^^^^^^^^
67+
68+
- `packageurl.contrib.purl2url.get_repo_url(purl)` returns a repository URL inferred from a Package URL.
69+
- `packageurl.contrib.purl2url.get_download_url(purl)` returns a download URL inferred from a Package URL.
70+
- `packageurl.contrib.purl2url.get_inferred_urls(purl)` return all inferred URLs (repository, download) from a Package URL.
71+
72+
::
73+
74+
>>> from packageurl.contrib import purl2url
75+
76+
>>> purl2url.get_repo_url("pkg:rubygems/[email protected]")
77+
"https://rubygems.org/gems/bundler/versions/2.3.23"
78+
79+
>>> purl2url.get_download_url("pkg:rubygems/[email protected]")
80+
"https://rubygems.org/downloads/bundler-2.3.23.gem"
81+
82+
>>> purl2url.get_inferred_urls("pkg:rubygems/[email protected]")
83+
["https://rubygems.org/gems/bundler/versions/2.3.23", "https://rubygems.org/downloads/bundler-2.3.23.gem",]
5284

5385
Run tests
5486
=========
5587

56-
install::
88+
Install test dependencies::
5789

5890
python3 thirdparty/virtualenv.pyz --never-download --no-periodic-update .
5991
bin/pip install -e ."[test]"
6092

61-
run tests::
93+
Run tests::
6294

6395
bin/py.test tests
6496

@@ -91,7 +123,6 @@ Make a new release
91123
bin/twine upload dist/*
92124

93125

94-
95126
.. |ci-tests| image:: https://github.com/package-url/packageurl-python/actions/workflows/ci.yml/badge.svg?branch=main
96127
:target: https://github.com/package-url/packageurl-python/actions/workflows/ci.yml
97128
:alt: CI Tests and build status

0 commit comments

Comments
 (0)