packageurl-python icon indicating copy to clipboard operation
packageurl-python copied to clipboard

Get URL from PURL

Open TG1999 opened this issue 3 years ago • 2 comments

From gitter chat https://gitter.im/package-url/Lobby

@tclasen :

Anyone know why the python package isn't letting me get a url from a purl?
@app.command()
def get(purl: str):
    parsed = PackageURL.from_string(purl)
    typer.echo(f"Grabbing {parsed}")
    typer.echo("A", purl2url.get_url(purl))
    typer.echo("B", purl2url.get_url(parsed.to_string()))
    typer.echo("C", purl2url.get_url(str(parsed)))
    typer.echo("D", purl2url.get_url(parsed.to_string()))
For this I've tried the two following PURLs:

pkg:maven/org.apache.commons/[email protected]
pkg:pypi/[email protected]
And for both of them I successfully parse and can print the purl, but the A, B, C, D echos after that are all empty (but don't crash).

@pombredanne :

@tclasen because it has not been implemented yet : https://github.com/package-url/packageurl-python/blob/main/src/packageurl/contrib/purl2url.py :)
It should be reasonably straightforward using tidbits of code from https://github.com/nexB/fetchcode/blob/master/src/fetchcode/package.py and the expansive set in https://github.com/nexB/scancode-toolkit/tree/develop/src/packagedcode

TG1999 avatar Apr 27 '22 13:04 TG1999

@tclasen one work around for now could be to use fetchcode for this, since many package types are not supported in purl2url

>>> from fetchcode.package import *
>>> pkgs = list(info("pkg:npm/[email protected]"))
>>> package = pkgs[0]
>>> package.bug_tracking_url
>>> package.homepage_url
>>> package.download_url

You can additionally get more information from a package like this

TG1999 avatar Apr 27 '22 14:04 TG1999

one work around for now could be to use fetchcode for this

fetchcode does not support the provided example pkg:maven/org.apache.commons/[email protected]

>>> from fetchcode.package import *
>>> info("pkg:maven/org.apache.commons/[email protected]")

And for pkg:pypi/[email protected], the bug_tracking_url and homepage_url are not consistent with the purl2url.get_repo_url


>>> from fetchcode.package import *
>>> pkgs = list(info("pkg:pypi/[email protected]"))
>>> package = pkgs[0]
>>> package.bug_tracking_url
'https://code.djangoproject.com/'
>>> package.homepage_url
'https://www.djangoproject.com/'
>>> package.download_url
>>>

Let's see if we could improve support in purl2url for the following:

>>> from packageurl.contrib import purl2url

>>> purl2url.get_repo_url("pkg:maven/org.apache.commons/[email protected]")
None

>>> purl2url.get_download_url("pkg:maven/org.apache.commons/[email protected]")
None

>>> purl2url.get_repo_url("pkg:pypi/[email protected]")
'https://pypi.org/project/django/1.11.1/'

>>> purl2url.get_download_url("pkg:pypi/[email protected]")
None

tdruez avatar Dec 08 '23 07:12 tdruez