Commit d9053991 authored by Federico Falconieri's avatar Federico Falconieri
Browse files

Merge branch '110-include-package-extras-in-python-jobs' into 'master'

feat: check licences of python extras

Closes #110

See merge request ci/templates!128
parents d47e4108 19c81abc
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ include:
  - local: "python/flake8.yml"
  - local: "python/pylic.yml"
  - local: "python/vulture.yml"
  - local: "python/poetry/pip-licenses.yml"
  - local: "python/pip-licenses.yml"

  - local: "c/cppcheck.yml"
  - local: "c/flawfinder.yml"
@@ -87,11 +87,11 @@ python:twine:
  before_script:
    - cd templates_tests/python

python:poetry:pip-licenses:
python:pip-licenses:
  before_script:
    - cd templates_tests/python
  variables:
    ALLOWED: MIT License
    ALLOWED: "MIT License;UNKNOWN"

c:cppcheck:
  variables:
+44 −0
Original line number Diff line number Diff line
---
# Check the package page on how to configure this job
# https://pypi.org/project/pip-licenses/

python:pip-licenses:
  stage: test
  image: registry.gitlab.com/notno/python-tests:latest
  variables:
    ALLOWED: ""  # Empty means all. Semicolon separated list. See https://pypi.org/project/pip-licenses/#option-allow-only
    PACKAGE_NAME: ""  # Name of the package that is to be verified; provide if auto-discovery fails
    SKIP_EXTRAS: ""  # Comma-separated list of extras that are to be skipped
  script:
    # work in venv
    - python -m venv .venv
    - source .venv/bin/activate
    - |
      if [ ! -z "${PACKAGE_NAME}" ]; then
        pip install . --no-deps
        echo "[*] Installed the provided package:" ${PACKAGE_NAME}
      else
        # Extract package name from pip stdout and write to temporary file
        DISCOVERY_PATTERN="Installing collected packages: "
        TEMP_FILE=$(mktemp)
        pip install . --no-deps | tee >(grep "${DISCOVERY_PATTERN}" | sed 's/.*'"${DISCOVERY_PATTERN}"'\(.*\)$/\1/' > ${TEMP_FILE})
        # Store package name in variable
        PACKAGE=$(cat ${TEMP_FILE}); rm ${TEMP_FILE}
        echo "[*] Installed the package that was auto-discovered:" ${PACKAGE}
        echo "[*] If this is not the package of interest, please provide the correct package name manually via PACKAGE_NAME."
      fi
    - |
      # Extract package extras from metadata and install those that are not explicitly set to be skipped
      pip install importlib_metadata
      EXTRAS=$(python -c "from importlib_metadata import metadata; print(','.join((extra for extra in metadata('${PACKAGE}').get_all('Provides-Extra', []) if not extra in '${SKIP_EXTRAS}'.split(','))), end='')")
      pip uninstall -y importlib_metadata
      if [ -z "${EXTRAS}" ]; then
        echo "[*] Installing package" ${PACKAGE} "without extras."
        pip install .
      else
        echo "[*] Installing package" ${PACKAGE} "with extras:" ${EXTRAS}
        pip install .[${EXTRAS}]
      fi
    - pip install pip-licenses
    - pip-licenses --allow-only="${ALLOWED}"
  needs: []

python/poetry/pip-licenses.yml

deleted100644 → 0
+0 −15
Original line number Diff line number Diff line
---
# Check the package page on how to configure this job
# https://pypi.org/project/pip-licenses/

python:poetry:pip-licenses:
  stage: test
  image: registry.gitlab.com/notno/python-tests:latest
  variables:
    ALLOWED: ""  # Empty means all. Semicolon separated list. See https://pypi.org/project/pip-licenses/#option-allow-only
  script:
    - pip install .
    - pip install pip-licenses
    - PACKAGES=$(dasel select -f pyproject.toml "tool.poetry.dependencies" | cut -d' ' -f1 | tr '\n' ' ')
    - pip-licenses --allow-only="${ALLOWED}" --packages ${PACKAGES}
  needs: []
+1 −1
Original line number Diff line number Diff line
@@ -17,5 +17,5 @@ python:pylic:
    - pip install pylic
    - echo "[*] The following packages, with their respective version, will be checked:"
    - pip freeze --all
    - pylic
    - pylic check
  needs: []
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ version_variable = "pyproject.toml:version"
[tool.pylic]
safe_licenses = [
    "Apache Software License",
    "MIT License"
    "MIT License",
    "BSD License"
]
unsafe_packages = [
    "mypackage",