Skip to content

Commit

Permalink
Add support for GitLab "/archive/" URLs in url2purl #133 (#134)
Browse files Browse the repository at this point in the history
* Add support for GitLab "/archive/" URLs in `url2purl` #133

Signed-off-by: tdruez <[email protected]>

* Add a Makefile to simplify setup

Signed-off-by: tdruez <[email protected]>

* Bump version to 0.11.3

Signed-off-by: tdruez <[email protected]>

* Minor adjustments to the CI confs

Signed-off-by: tdruez <[email protected]>

* Upgrade python version to 3.7 in mypy conf

Signed-off-by: tdruez <[email protected]>

---------

Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez authored Dec 8, 2023
1 parent 0d33368 commit 7b1f4c4
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python environment
uses: actions/setup-python@v4
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python environment
uses: actions/setup-python@v4
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Create library release archives, create a GH release and publish PyPI wheel and sdist on tag in main branch


# This is executed automatically on a tag in the main branch

# Summary of the steps:
Expand All @@ -21,14 +20,15 @@ on:
jobs:
build-pypi-distribs:
name: Build and publish library to PyPI
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11

- name: Install pypa/build
run: python -m pip install build --user
Expand All @@ -42,12 +42,11 @@ jobs:
name: pypi_archives
path: dist/*


create-gh-release:
name: Create GH release
needs:
- build-pypi-distribs
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Download built archives
Expand All @@ -62,12 +61,11 @@ jobs:
draft: true
files: dist/*


create-pypi-release:
name: Create PyPI release
needs:
- create-gh-release
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Download built archives
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

0.11.3 (2023-12-08)
--------------------

- Add support for GitLab "/archive/" URLs in `url2purl`.
https://github.com/package-url/packageurl-python/issues/133

0.11.2 (2022-07-25)
--------------------

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include mit.LICENSE
include setup.py
include setup.cfg
include README.rst
include Makefile
include MANIFEST.in
include CHANGELOG.rst
include CONTRIBUTING.rst
Expand Down
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) the purl authors
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# 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.

# Python version can be specified with `$ PYTHON_EXE=python3.x make conf`
PYTHON_EXE?=python3
ACTIVATE?=. bin/activate;
VIRTUALENV_PYZ=thirdparty/virtualenv.pyz
BLACK_ARGS=--exclude=".cache|migrations|data|lib|bin|var"

virtualenv:
@echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}"
@${PYTHON_EXE} ${VIRTUALENV_PYZ} --never-download --no-periodic-update .

conf: virtualenv
@echo "-> Install dependencies"
@${ACTIVATE} pip install -e .

dev: virtualenv
@echo "-> Configure and install development dependencies"
@${ACTIVATE} pip install -e .[test]

clean:
@echo "-> Clean the Python env"
rm -rf bin/ lib*/ include/ build/ dist/ .*cache/ pip-selfcheck.json pyvenv.cfg
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ \
-delete -type d -name '*.egg-info' -delete

test:
@echo "-> Run the test suite"
${MANAGE} test --noinput
bin/py.test tests

.PHONY: virtualenv conf dev clean test
15 changes: 10 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ Utilities
Django models
^^^^^^^^^^^^^

`packageurl.contrib.django.models.PackageURLMixin` is a Django abstract model mixin to use Package URLs in Django.
`packageurl.contrib.django.models.PackageURLMixin` is a Django abstract model mixin to
use Package URLs in Django.

SQLAlchemy mixin
^^^^^^^^^^^^^^^^

`packageurl.contrib.sqlalchemy.mixin.PackageURLMixin` is a SQLAlchemy declarative mixin to use Package URLs in SQLAlchemy models.
`packageurl.contrib.sqlalchemy.mixin.PackageURLMixin` is a SQLAlchemy declarative mixin
to use Package URLs in SQLAlchemy models.

URL to PURL
^^^^^^^^^^^
Expand All @@ -70,9 +72,12 @@ URL to PURL
PURL to URL
^^^^^^^^^^^

- `packageurl.contrib.purl2url.get_repo_url(purl)` returns a repository URL inferred from a Package URL.
- `packageurl.contrib.purl2url.get_download_url(purl)` returns a download URL inferred from a Package URL.
- `packageurl.contrib.purl2url.get_inferred_urls(purl)` return all inferred URLs (repository, download) from a Package URL.
- `packageurl.contrib.purl2url.get_repo_url(purl)` returns a repository URL inferred
from a Package URL.
- `packageurl.contrib.purl2url.get_download_url(purl)` returns a download URL inferred
from a Package URL.
- `packageurl.contrib.purl2url.get_inferred_urls(purl)` return all inferred URLs
(repository, download) from a Package URL.

::

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = packageurl-python
version = 0.11.2
version = 0.11.3
license = MIT
description = A purl aka. Package URL parser and builder
long_description = file:README.rst
Expand Down Expand Up @@ -66,7 +66,7 @@ known_django = django
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

[mypy]
python_version = 3.6
python_version = 3.7

files = src/packageurl/__init__.py
show_error_codes = True
Expand Down
13 changes: 12 additions & 1 deletion src/packageurl/contrib/url2purl.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def build_bitbucket_purl(url):
)


@purl_router.route("https?://gitlab\\.com/.*")
@purl_router.route("https?://gitlab\\.com/(?!.*/archive/).*")
def build_gitlab_purl(url):
"""
Return a PackageURL object from Gitlab `url`.
Expand Down Expand Up @@ -602,6 +602,17 @@ def build_gitlab_purl(url):
)


# https://gitlab.com/hoppr/hoppr/-/archive/v1.11.1-dev.2/hoppr-v1.11.1-dev.2.tar.gz
gitlab_archive_pattern = (
r"^https?://gitlab.com/"
r"(?P<namespace>.+)/(?P<name>.+)/-/archive/(?P<version>.+)/"
r"(?P=name)-(?P=version).*"
r"[^/]$"
)

register_pattern("gitlab", gitlab_archive_pattern)


# https://hackage.haskell.org/package/cli-extras-0.2.0.0/cli-extras-0.2.0.0.tar.gz
hackage_download_pattern = (
r"^https?://hackage.haskell.org/package/"
Expand Down
1 change: 1 addition & 0 deletions tests/contrib/data/url2purl.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
"https://gitlab.com/TG1999/firebase/-/tree/master": "pkg:gitlab/tg1999/firebase@master",
"https://gitlab.com/tg1999/Firebase/-/tree/master": "pkg:gitlab/tg1999/firebase@master",
"https://gitlab.com/TG1999/FIREBASE": "pkg:gitlab/tg1999/firebase",
"https://gitlab.com/hoppr/hoppr/-/archive/v1.11.1-dev.2/hoppr-v1.11.1-dev.2.tar.gz": "pkg:gitlab/hoppr/[email protected]",
"https://hackage.haskell.org/package/a50-0.5/a50-0.5.tar.gz": "pkg:hackage/[email protected]",
"https://hackage.haskell.org/package/AC-HalfInteger-1.2.1/AC-HalfInteger-1.2.1.tar.gz": "pkg:hackage/[email protected]",
"https://hackage.haskell.org/package/3d-graphics-examples-0.0.0.2/3d-graphics-examples-0.0.0.2.tar.gz": "pkg:hackage/[email protected]",
Expand Down

0 comments on commit 7b1f4c4

Please sign in to comment.