Commit 50bf0c55 authored by Luke Hendrick's avatar Luke Hendrick Committed by Pierre Smeyers
Browse files

feat(pdm): add support for PDM (Python Dependency Manager) as an additional build system

parent 20c75519
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ and/or `setup.py` and/or `requirements.txt`), but the build system might also be
| `poetry`         | [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/) ![Poetry](https://img.shields.io/badge/dependencies_%7C_build_%7C_test_%7C_packaging-blue)                           |
| `uv`             | [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://docs.astral.sh/uv/) ![uv](https://img.shields.io/badge/dependencies_%7C_build_%7C_test_%7C_packaging-blue)  |
| `hatch`          | [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://hatch.pypa.io/latest/) ![Hatch](https://img.shields.io/badge/dependencies_%7C_build_%7C_test_%7C_packaging-blue) |
| `pdm`            | [![pdm](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org) ![PDM](https://img.shields.io/badge/dependencies_%7C_build_%7C_test_%7C_packaging-blue)
| `pipenv`         | [![Pipenv](https://img.shields.io/badge/Pipenv-grey)](https://pipenv.pypa.io/) ![Pipenv](https://img.shields.io/badge/dependencies-blue)                                                  |
| `reqfile`        | [![Requirements Files](https://img.shields.io/badge/Requirements_Files-grey)](https://pip.pypa.io/en/stable/user_guide/#requirements-files) ![Pipenv](https://img.shields.io/badge/dependencies-blue) |

@@ -153,7 +154,7 @@ In addition to a textual report in the console, this job produces the following

| Report         | Format                                                                       | Usage             |
| -------------- | ---------------------------------------------------------------------------- | ----------------- |
| `$PYTHON_PROJECT_DIR/reports/py-lint.codeclimate.json` | [Code Climate](https://docs.codeclimate.com/docs/pylint) | [GitLab integration](https://docs.gitlab.com/ci/yaml/artifacts_reports/#artifactsreportscodequality) |
| `$PYTHON_PROJECT_DIR/reports/py-lint.codeclimate.json` | [Code Climate](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types) | [GitLab integration](https://docs.gitlab.com/ci/yaml/artifacts_reports/#artifactsreportscodequality) |
| `$PYTHON_PROJECT_DIR/reports/py-lint.parseable.txt` | [parseable](https://pylint.pycqa.org/en/latest/user_guide/usage/output.html) | [SonarQube integration](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/importing-external-issues/external-analyzer-reports/) |

### Test jobs
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
      "name": "PYTHON_BUILD_SYSTEM",
      "description": "Python build-system to use to install dependencies, build and package the project",
      "type": "enum",
      "values": ["auto", "setuptools", "poetry", "pipenv", "reqfile", "uv", "hatch"],
      "values": ["auto", "setuptools", "poetry", "pipenv", "reqfile", "uv", "hatch", "pdm"],
      "default": "auto",
      "advanced": true
    },
+52 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ spec:
      - reqfile
      - uv
      - hatch
      - pdm
      default: auto
    reqs-file:
      description: |-
@@ -640,7 +641,7 @@ variables:
    case "${PYTHON_BUILD_SYSTEM:-auto}" in
    auto)
      ;;
    poetry*|setuptools*|pipenv*|uv*|hatch*)
    poetry*|setuptools*|pipenv*|uv*|hatch*|pdm*)
      export PYTHON_BUILD_SYSTEM_CMD="${PYTHON_BUILD_SYSTEM%%[=<>]*}"
      log_info "--- Build system explicitly declared: ${PYTHON_BUILD_SYSTEM} cmd=\\e[33m$PYTHON_BUILD_SYSTEM_CMD\\e[0m"
      return
@@ -699,6 +700,12 @@ variables:
        export PYTHON_BUILD_SYSTEM="setuptools"
        return
        ;;
      pdm.backend)
        log_info "--- Build system auto-detected: PEP 517 with PDM backend"
        export PYTHON_BUILD_SYSTEM="pdm"
        export PYTHON_BUILD_SYSTEM_CMD="pdm"
        return
        ;;
      *)
        log_error "--- Build system auto-detected: PEP 517 with unsupported backend \\e[33;1m${build_backend}\\e[0m: please read template doc"
        exit 1
@@ -784,6 +791,10 @@ variables:
      maybe_install_build_system
      hatch env create
      ;;
    pdm*)
      maybe_install_build_system
      pdm sync --dev ${PYTHON_EXTRA_DEPS:+--extra "$PYTHON_EXTRA_DEPS"}
      ;;
    esac

    log_elapsed_time "install_requirements" "$_start_time"
@@ -791,7 +802,7 @@ variables:

  function _run() {
    case "$PYTHON_BUILD_SYSTEM" in
      poetry*|uv*|hatch*)
      poetry*|uv*|hatch*|pdm*)
        maybe_install_build_system
        $PYTHON_BUILD_SYSTEM_CMD run "$@"
        ;;
@@ -837,6 +848,11 @@ variables:
        log_info "--- build packages (hatch)..."
        $PYTHON_BUILD_SYSTEM_CMD build
        ;;
      pdm*)
        maybe_install_build_system
        log_info "--- build packages (pdm)..."
        pdm build ${TRACE+--verbose}
        ;;
      *)
        log_info "--- build packages ..."
        # shellcheck disable=SC2086
@@ -974,6 +990,23 @@ variables:
        hatch version "$py_next_version"
      fi

      py_git_tag_commit_release_change "$py_cur_version" "$py_next_version"
    elif [[ "$PYTHON_BUILD_SYSTEM" =~ ^pdm ]]
    then
      maybe_install_build_system
      if [[ -z "$py_next_version" ]]
      then
        py_cur_version=$(pdm show --version)
        log_info "[pdm version] increase \\e[1;94m${PYTHON_RELEASE_NEXT}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)"
        pdm self add pdm-bump
        pdm bump ${TRACE+--verbose} "$PYTHON_RELEASE_NEXT"
        py_next_version=$(pdm show --version)
      else
        log_info "[pdm] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
        pdm self add pdm-bump
        pdm bump ${TRACE+--verbose} "$py_next_version"
      fi

      py_git_tag_commit_release_change "$py_cur_version" "$py_next_version"
    else
      # Setuptools / bump-my-version
@@ -1046,6 +1079,12 @@ variables:

      log_info "--- publish packages (hatch) to $PYTHON_REPOSITORY_URL with user $PYTHON_REPOSITORY_USERNAME..."
      hatch publish ${TRACE+--verbose} --no-prompt --yes --user "$PYTHON_REPOSITORY_USERNAME" --auth "$PYTHON_REPOSITORY_PASSWORD" --repo "$PYTHON_REPOSITORY_URL"
    elif [[ "$PYTHON_BUILD_SYSTEM" =~ ^pdm ]]
    then
      maybe_install_build_system

      log_info "--- publish packages (pdm) to $PYTHON_REPOSITORY_URL with user $PYTHON_REPOSITORY_USERNAME..."
      pdm publish ${TRACE+--verbose} --username "$PYTHON_REPOSITORY_USERNAME" --password "$PYTHON_REPOSITORY_PASSWORD" --repository "$PYTHON_REPOSITORY_URL"
    else
      # shellcheck disable=SC2086
      pip install ${PIP_OPTS} build twine
@@ -1104,6 +1143,7 @@ stages:
    UV_CACHE_DIR: "$CI_PROJECT_DIR/.cache/uv"
    HATCH_CACHE_DIR: "$CI_PROJECT_DIR/.cache/hatch/.cache/"
    HATCH_DATA_DIR: "$CI_PROJECT_DIR/.cache/hatch/.local"
    PDM_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pdm"
    POETRY_VIRTUALENVS_IN_PROJECT: "false"
  cache:
    key: "$CI_COMMIT_REF_SLUG-python"
@@ -1435,6 +1475,11 @@ py-trivy:
          maybe_install_build_system
          hatch run python -m pip freeze > reports/requirements.txt # hatch dep show requirements not working and complete
          ;;
        pdm*)
          log_info "$PYTHON_BUILD_SYSTEM build system used (\\e[32mmust generate pinned requirements.txt\\e[0m)"
          maybe_install_build_system
          pdm export --format requirements > reports/requirements.txt 
          ;;
        *)
          log_info "$PYTHON_BUILD_SYSTEM build system used (\\e[32mmust generate pinned requirements.txt\\e[0m)"
          install_requirements
@@ -1499,6 +1544,11 @@ py-sbom:
          maybe_install_build_system
          hatch run python -m pip freeze > reports/requirements.txt # hatch dep show requirements not working and complete
          ;;
        pdm*)
          log_info "$PYTHON_BUILD_SYSTEM build system used (\\e[32mmust generate pinned requirements.txt from pdm.lock\\e[0m)"
          maybe_install_build_system
          pdm export --format requirements > reports/requirements.txt
          ;;
        *)
          log_info "$PYTHON_BUILD_SYSTEM build system used (\\e[32mmust generate pinned requirements.txt\\e[0m)"
          install_requirements