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