Skip to content

Commit 6d37742

Browse files
authored
Merge pull request #149 from schischi/cran
url2purl: add cran ecosystem
2 parents dea7760 + c34054c commit 6d37742

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/packageurl/contrib/purl2url.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ def build_rubygems_repo_url(purl):
186186
return f"https://rubygems.org/gems/{name}"
187187

188188

189+
@repo_router.route("pkg:cran/.*")
190+
def build_cran_repo_url(purl):
191+
"""
192+
Return a cran repo URL from the `purl` string.
193+
"""
194+
purl_data = PackageURL.from_string(purl)
195+
196+
name = purl_data.name
197+
version = purl_data.version
198+
199+
return f"https://cran.r-project.org/src/contrib/{name}_{version}.tar.gz"
200+
201+
189202
@repo_router.route("pkg:npm/.*")
190203
def build_npm_repo_url(purl):
191204
"""

src/packageurl/contrib/url2purl.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,20 @@ def build_rubygems_purl(uri):
277277
return purl_from_pattern("gem", rubygems_pattern, uri)
278278

279279

280+
# https://cran.r-project.org/src/contrib/jsonlite_1.8.8.tar.gz
281+
# https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz"
282+
@purl_router.route(
283+
"https?://cran.r-project.org/.*",
284+
"https?://packagemanager.rstudio.com/cran/.*",
285+
)
286+
def build_cran_purl(uri):
287+
cran_pattern = r"^https?://(cran\.r-project\.org|packagemanager\.rstudio\.com/cran)/.*?src/contrib/(?P<name>.+)_(?P<version>.+)\.tar.gz$"
288+
qualifiers = {}
289+
if "//cran.r-project.org/" not in uri:
290+
qualifiers["download_url"] = uri
291+
return purl_from_pattern("cran", cran_pattern, uri, qualifiers)
292+
293+
280294
# https://pypi.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz
281295
# https://pypi.python.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz
282296
# https://pypi.python.org/packages/2.6/t/threadpool/threadpool-1.2.7-py2.6.egg

tests/contrib/data/url2purl.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,7 @@
267267
"https://salsa.debian.org/lxc-team/lxc/-/archive/master/lxc-master.tar.gz": "pkg:generic/lxc-master.tar.gz?download_url=https://salsa.debian.org/lxc-team/lxc/-/archive/master/lxc-master.tar.gz",
268268
"http://apt-rpm.org/": null,
269269
"": null,
270-
"https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm": "pkg:generic/code.google.com/android-notifier?download_url=https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm"
270+
"https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm": "pkg:generic/code.google.com/android-notifier?download_url=https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm",
271+
"https://cran.r-project.org/src/contrib/jsonlite_1.8.8.tar.gz": "pkg:cran/jsonlite@1.8.8",
272+
"https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz": "pkg:cran/curl@4.3.2?download_url=https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz"
271273
}

0 commit comments

Comments
 (0)