pypurl
Releasing the support for PURLs from Ruby Gem repository
type
支持:每个组件的定义是:
this is the URL scheme with the constant value of "pkg". One of the
primary reason for this single scheme is to facilitate the future official
registration of the "pkg" scheme for package URLs. Required.
the package "type" or package "protocol" such as github, bitbucket,
maven, npm, nuget, gem, pypi, etc.
some name prefix such as a Maven groupid, a Docker image owner, a GitHub user
or organization. Optional and type-specific.
the name of the package.
the version of the package.
extra qualifying data for a package such as an OS, architecture, a distro, etc.
Type-specific.
extra subpath within a package, relative to the package root.
# install the package
$ cd pypurl /
$ pip install -e .
# enter interpreter mode
$ python
# import main module
>>> from pypurl .purl import Purl
>>> p = Purl()
# parse the Download URL to dictionary
>>> p.durl_to_dict('https://github.com/vBarbaros/pypurl/archive/refs/heads/main.zip')
{'scheme': 'pkg', 'type': 'github', 'namespace': 'vBarbaros', 'name': ' pypurl '}
# obtain the PURL from the Download URL only
>>> durl = 'https://github.com/vBarbaros/pypurl/archive/refs/heads/main.zip'
>>> p.durl_to_purl(durl)
'pkg:github/vBarbaros/ pypurl '
# obtain the PURL from the Download URL + version number/hash-commit
>>> durl = 'https://github.com/vBarbaros/pypurl/archive/refs/heads/main.zip'
>>> p.durl_to_purl(durl, '244fd47e07d1004f0aed9c')
'pkg:github/vBarbaros/ pypurl @244fd47e07d1004f0aed9c'
# obtain the PURL from the Download URL + version number/hash-commit + qualifiers
>>> p.durl_to_purl(durl, '244fd47e07d1004f0aed9c', 'param1=one¶m2=two¶m3=three')
'pkg:github/vBarbaros/ pypurl @244fd47e07d1004f0aed9c?param1=one¶m2=two¶m3=three'
# obtain the PURL from the Download URL + version number/hash-commit + qualifiers + subpath
>>> p.durl_to_purl(durl, '244fd47e07d1004f0aed9c', 'param1=one¶m2=two¶m3=three', 'some/dummy/path')
'pkg:github/vBarbaros/ pypurl @244fd47e07d1004f0aed9c?param1=one¶m2=two¶m3=three#some/dummy/path'
# parse the PURL containing main fields (+ version) to dictionary
>>> purl = 'pkg:github/vBarbaros/ pypurl @244fd47e07d1004f0aed9c'
>>> p.purl_to_dict(purl)
{'scheme': 'pkg', 'type': 'github', 'namespace': 'vBarbaros', 'name': ' pypurl ', 'version': '244fd47e07d1004f0aed9c'}
# parse the PURL containing all possible fields, to dictionary
>>> purl = 'pkg:github/vBarbaros/ pypurl @244fd47e07d1004f0aed9c?param1=one¶m2=two¶m3=three#some/dummy/path'
>>> p.purl_to_dict(purl)
{'scheme': 'pkg', 'type': 'github', 'namespace': 'vBarbaros', 'name': ' pypurl ', 'version': '244fd47e07d1004f0aed9c', 'qualifiers': 'param1=one¶m2=two¶m3=three', 'subpath': 'some/dummy/path'}
$ cd pypurl
$ pip install -e .
$ python -m unittest tests/*.py
# Expected output
...
Ran 163 tests in 0.006s
OK
虽然这个模块代表了我的一个简单练习,基于我听说人们在使用 PURL 时遇到的一些困难,但 purl-specs 页面帮助我定义了这个模块的路线图
麻省理工学院©维克多·巴巴罗斯,2021