From 4bd76d5066741ad357cf8fa90c1680c004dbc9c0 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Mon, 8 Apr 2024 15:43:15 -0700 Subject: [PATCH 1/5] Add repo URL support and testing for cocoapods #143 Reference: https://github.com/package-url/packageurl-python/issues/143 Signed-off-by: John M. Horan --- src/packageurl/contrib/purl2url.py | 14 ++++++++++++++ tests/contrib/test_purl2url.py | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/packageurl/contrib/purl2url.py b/src/packageurl/contrib/purl2url.py index 69d3e4c..54c5e37 100644 --- a/src/packageurl/contrib/purl2url.py +++ b/src/packageurl/contrib/purl2url.py @@ -304,6 +304,20 @@ def build_golang_repo_url(purl): return f"https://pkg.go.dev/{namespace}/{name}" +@repo_router.route("pkg:cocoapods/.*") +def build_cocoapods_repo_url(purl): + """ + Return a CocoaPods repo URL from the `purl` string. + """ + purl_data = PackageURL.from_string(purl) + name = purl_data.name + + if name: + repository_homepage_url = f"https://cocoapods.org/pods/{name}" + + return repository_homepage_url + + # Download URLs: diff --git a/tests/contrib/test_purl2url.py b/tests/contrib/test_purl2url.py index c76fa52..20086f9 100644 --- a/tests/contrib/test_purl2url.py +++ b/tests/contrib/test_purl2url.py @@ -64,6 +64,8 @@ def test_purl2url_get_repo_url(): "pkg:golang/xorm.io/xorm": "https://pkg.go.dev/xorm.io/xorm", "pkg:golang/xorm.io/xorm@v0.8.2": "https://pkg.go.dev/xorm.io/xorm@v0.8.2", "pkg:golang/gopkg.in/ldap.v3@v3.1.0": "https://pkg.go.dev/gopkg.in/ldap.v3@v3.1.0", + "pkg:cocoapods/AFNetworking@4.0.1": "https://cocoapods.org/pods/AFNetworking", + "pkg:cocoapods/MapsIndoors@3.24.0": "https://cocoapods.org/pods/MapsIndoors", } for purl, url in purls_url.items(): @@ -134,7 +136,10 @@ def test_purl2url_get_inferred_urls(): "https://gitlab.com/tg1999/firebase", "https://gitlab.com/tg1999/firebase/-/archive/1a122122/firebase-1a122122.tar.gz", ], - "pkg:pypi/sortedcontainers@2.4.0": ["https://pypi.org/project/sortedcontainers/2.4.0/"], + "pkg:pypi/sortedcontainers@2.4.0": [ + "https://pypi.org/project/sortedcontainers/2.4.0/" + ], + "pkg:cocoapods/AFNetworking@4.0.1": ["https://cocoapods.org/pods/AFNetworking"], "pkg:composer/psr/log@1.1.3": ["https://packagist.org/packages/psr/log#1.1.3"], "pkg:rubygems/package-name": ["https://rubygems.org/gems/package-name"], "pkg:bitbucket/birkenfeld": [], From aee327c18d85545f983c772c477ef43674e87d9a Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Wed, 29 May 2024 17:27:08 -0700 Subject: [PATCH 2/5] Add code and tests to handle cocoapods PURL with no name #143 Reference: https://github.com/package-url/packageurl-python/issues/143 Signed-off-by: John M. Horan --- src/packageurl/contrib/purl2url.py | 25 ++++++++++++++++++------- tests/contrib/test_purl2url.py | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/packageurl/contrib/purl2url.py b/src/packageurl/contrib/purl2url.py index 54c5e37..7d0bd52 100644 --- a/src/packageurl/contrib/purl2url.py +++ b/src/packageurl/contrib/purl2url.py @@ -24,6 +24,7 @@ # Visit https://github.com/package-url/packageurl-python for support and # download. + from packageurl import PackageURL from packageurl.contrib.route import NoRouteAvailable from packageurl.contrib.route import Router @@ -75,7 +76,12 @@ def get_download_url(purl): return download_url # Fallback on the `download_url` qualifier when available. - purl_data = PackageURL.from_string(purl) + purl_data = None + try: + purl_data = PackageURL.from_string(purl) + except Exception as e: + print(f"An error occurred in get_download_url(): {e}") + return return purl_data.qualifiers.get("download_url", None) @@ -309,13 +315,18 @@ def build_cocoapods_repo_url(purl): """ Return a CocoaPods repo URL from the `purl` string. """ - purl_data = PackageURL.from_string(purl) - name = purl_data.name - - if name: - repository_homepage_url = f"https://cocoapods.org/pods/{name}" + purl_data = None + name = None + try: + purl_data = PackageURL.from_string(purl) + name = purl_data.name + except Exception as e: + print(f"An error occurred in build_cocoapods_repo_url(): {e}") + return - return repository_homepage_url + if not name: + return + return f"https://cocoapods.org/pods/{name}" # Download URLs: diff --git a/tests/contrib/test_purl2url.py b/tests/contrib/test_purl2url.py index 20086f9..bd78ee1 100644 --- a/tests/contrib/test_purl2url.py +++ b/tests/contrib/test_purl2url.py @@ -66,6 +66,7 @@ def test_purl2url_get_repo_url(): "pkg:golang/gopkg.in/ldap.v3@v3.1.0": "https://pkg.go.dev/gopkg.in/ldap.v3@v3.1.0", "pkg:cocoapods/AFNetworking@4.0.1": "https://cocoapods.org/pods/AFNetworking", "pkg:cocoapods/MapsIndoors@3.24.0": "https://cocoapods.org/pods/MapsIndoors", + "pkg:cocoapods/": None, } for purl, url in purls_url.items(): @@ -140,6 +141,7 @@ def test_purl2url_get_inferred_urls(): "https://pypi.org/project/sortedcontainers/2.4.0/" ], "pkg:cocoapods/AFNetworking@4.0.1": ["https://cocoapods.org/pods/AFNetworking"], + "pkg:cocoapods/": [], "pkg:composer/psr/log@1.1.3": ["https://packagist.org/packages/psr/log#1.1.3"], "pkg:rubygems/package-name": ["https://rubygems.org/gems/package-name"], "pkg:bitbucket/birkenfeld": [], From 486be44ef0fd4bedf6e7039a4759a60b4a897eb7 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Wed, 5 Jun 2024 10:49:41 -0700 Subject: [PATCH 3/5] Remove cocoapods try/except blocks and update code and tests #143 Reference: https://github.com/package-url/packageurl-python/issues/143 Signed-off-by: John M. Horan --- src/packageurl/contrib/purl2url.py | 25 ++++--------------------- tests/contrib/test_purl2url.py | 4 ---- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/packageurl/contrib/purl2url.py b/src/packageurl/contrib/purl2url.py index 7d0bd52..ffd4968 100644 --- a/src/packageurl/contrib/purl2url.py +++ b/src/packageurl/contrib/purl2url.py @@ -21,9 +21,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# Visit https://github.com/package-url/packageurl-python for support and -# download. - from packageurl import PackageURL from packageurl.contrib.route import NoRouteAvailable @@ -76,12 +73,7 @@ def get_download_url(purl): return download_url # Fallback on the `download_url` qualifier when available. - purl_data = None - try: - purl_data = PackageURL.from_string(purl) - except Exception as e: - print(f"An error occurred in get_download_url(): {e}") - return + purl_data = PackageURL.from_string(purl) return purl_data.qualifiers.get("download_url", None) @@ -315,18 +307,9 @@ def build_cocoapods_repo_url(purl): """ Return a CocoaPods repo URL from the `purl` string. """ - purl_data = None - name = None - try: - purl_data = PackageURL.from_string(purl) - name = purl_data.name - except Exception as e: - print(f"An error occurred in build_cocoapods_repo_url(): {e}") - return - - if not name: - return - return f"https://cocoapods.org/pods/{name}" + purl_data = PackageURL.from_string(purl) + name = purl_data.name + return name and f"https://cocoapods.org/pods/{name}" # Download URLs: diff --git a/tests/contrib/test_purl2url.py b/tests/contrib/test_purl2url.py index bd78ee1..a549a41 100644 --- a/tests/contrib/test_purl2url.py +++ b/tests/contrib/test_purl2url.py @@ -21,8 +21,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# Visit https://github.com/package-url/packageurl-python for support and -# download. import pytest @@ -66,7 +64,6 @@ def test_purl2url_get_repo_url(): "pkg:golang/gopkg.in/ldap.v3@v3.1.0": "https://pkg.go.dev/gopkg.in/ldap.v3@v3.1.0", "pkg:cocoapods/AFNetworking@4.0.1": "https://cocoapods.org/pods/AFNetworking", "pkg:cocoapods/MapsIndoors@3.24.0": "https://cocoapods.org/pods/MapsIndoors", - "pkg:cocoapods/": None, } for purl, url in purls_url.items(): @@ -141,7 +138,6 @@ def test_purl2url_get_inferred_urls(): "https://pypi.org/project/sortedcontainers/2.4.0/" ], "pkg:cocoapods/AFNetworking@4.0.1": ["https://cocoapods.org/pods/AFNetworking"], - "pkg:cocoapods/": [], "pkg:composer/psr/log@1.1.3": ["https://packagist.org/packages/psr/log#1.1.3"], "pkg:rubygems/package-name": ["https://rubygems.org/gems/package-name"], "pkg:bitbucket/birkenfeld": [], From f7a88bac736b16234072e16bc0926a1ea946eb68 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Fri, 7 Jun 2024 09:47:23 -0700 Subject: [PATCH 4/5] Restore comments re support/download URL #143 Reference: https://github.com/package-url/packageurl-python/issues/143 Signed-off-by: John M. Horan --- src/packageurl/contrib/purl2url.py | 2 ++ tests/contrib/test_purl2url.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/packageurl/contrib/purl2url.py b/src/packageurl/contrib/purl2url.py index ffd4968..1d43c68 100644 --- a/src/packageurl/contrib/purl2url.py +++ b/src/packageurl/contrib/purl2url.py @@ -21,6 +21,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +# Visit https://github.com/package-url/packageurl-python for support and +# download. from packageurl import PackageURL from packageurl.contrib.route import NoRouteAvailable diff --git a/tests/contrib/test_purl2url.py b/tests/contrib/test_purl2url.py index a549a41..20086f9 100644 --- a/tests/contrib/test_purl2url.py +++ b/tests/contrib/test_purl2url.py @@ -21,6 +21,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +# Visit https://github.com/package-url/packageurl-python for support and +# download. import pytest From 7ebe68192b7995d11b209e8fcb45ffed63f190a1 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Fri, 7 Jun 2024 17:58:10 -0700 Subject: [PATCH 5/5] Restore prior formatting #143 Reference: https://github.com/package-url/packageurl-python/issues/143 Signed-off-by: John M. Horan --- tests/contrib/test_purl2url.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/contrib/test_purl2url.py b/tests/contrib/test_purl2url.py index 20086f9..3bc6f1d 100644 --- a/tests/contrib/test_purl2url.py +++ b/tests/contrib/test_purl2url.py @@ -136,9 +136,7 @@ def test_purl2url_get_inferred_urls(): "https://gitlab.com/tg1999/firebase", "https://gitlab.com/tg1999/firebase/-/archive/1a122122/firebase-1a122122.tar.gz", ], - "pkg:pypi/sortedcontainers@2.4.0": [ - "https://pypi.org/project/sortedcontainers/2.4.0/" - ], + "pkg:pypi/sortedcontainers@2.4.0": ["https://pypi.org/project/sortedcontainers/2.4.0/"], "pkg:cocoapods/AFNetworking@4.0.1": ["https://cocoapods.org/pods/AFNetworking"], "pkg:composer/psr/log@1.1.3": ["https://packagist.org/packages/psr/log#1.1.3"], "pkg:rubygems/package-name": ["https://rubygems.org/gems/package-name"],