Skip to content

ci: update PDM to v2.20.1, cache lockfile between runs #1278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# force LF for pyproject to make hashFiles in CI consistent (windows <3)
# (see https://github.com/actions/runner/issues/498)
pyproject.toml text eol=lf
42 changes: 42 additions & 0 deletions .github/actions/cache-pdm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: MIT

name: Configure PDM cache
description: .
inputs:
env-already-initialized:
description: Whether Python/PDM is already configured
required: false
default: 'true'

runs:
using: composite
steps:
- name: Get metadata for cache
id: get-cache-meta
shell: bash
run: |
echo "date=$(date -u "+%Y%m%d")" >> $GITHUB_OUTPUT

- name: Setup/Restore cache
id: cache
uses: actions/cache@v4
with:
path: |
pdm.lock
# cache lockfile for the current day, roughly
key: pdm-${{ steps.get-cache-meta.outputs.date }}-${{ hashFiles('pyproject.toml') }}
# pdm lockfiles should be platform-agnostic
enableCrossOsArchive: true

- if: ${{ steps.cache.outputs.cache-hit != 'true' && inputs.env-already-initialized != 'true' }}
name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: 3.8
version: "2.20.1"

- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
name: Lock all dependencies
shell: bash
run: |
pdm lock -G:all # create pdm.lock
15 changes: 4 additions & 11 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ inputs:
python-version:
description: The python version to install
required: true
cache-dependency-path:
description: The path(s) to use for pip caching, defaults to setup + pdm
required: false
default: |
pyproject.toml
setup.py
outputs:
python-version:
description: The python version that was installed.
Expand All @@ -25,12 +19,8 @@ runs:
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ inputs.python-version }}
version: "2.4.6"
version: "2.20.1" # last version to support python 3.8
cache: false
cache-dependency-path: ${{ inputs.cache-dependency-path }}
enable-pep582: false # Disable PEP 582 package loading globally
env:
PDM_DEPS: 'importlib-metadata<8; python_version < "3.10"'

- name: Disable PDM version check
shell: bash
Expand All @@ -54,3 +44,6 @@ runs:
id: python-version
shell: bash
run: echo "python-version=$(python -c 'import sys; print(".".join(map(str,sys.version_info[:2])))')" >> $GITHUB_OUTPUT

- name: Configure cache
uses: ./.github/actions/cache-pdm
27 changes: 23 additions & 4 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,25 @@ defaults:
shell: bash

jobs:
lint:
lock-dependencies:
# The only purpose of this is to create a lockfile, which will be cached
# to be used with subsequent jobs.
# This provides somewhat of a middle ground and avoids having each job lock dependencies on its own,
# while still not needing to commit a lockfile to the repo, which is discouraged for libraries as per
# https://pdm-project.org/en/latest/usage/lockfile/
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Instead of setup-env, we call the cache-pdm action here directly.
# This avoids having to install PDM, only to find out the cache is already up to date sometimes.
- name: Configure cache
uses: ./.github/actions/cache-pdm
with:
env-already-initialized: false

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Expand All @@ -39,6 +55,7 @@ jobs:
# unlike the other workflows, we explicitly use the same version as
# readthedocs (see .readthedocs.yml) here for consistency
runs-on: ubuntu-24.04
needs: lock-dependencies
steps:
- uses: actions/checkout@v4

Expand All @@ -52,10 +69,10 @@ jobs:

pyright:
runs-on: ubuntu-latest
needs: lock-dependencies
strategy:
matrix:
# FIXME: using specific patch version for 3.12 due to pdm bug
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.7"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
experimental: [false]
fail-fast: false
continue-on-error: ${{ matrix.experimental }}
Expand Down Expand Up @@ -105,6 +122,7 @@ jobs:

misc:
runs-on: ubuntu-latest
needs: lock-dependencies
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -148,9 +166,10 @@ jobs:

pytest:
runs-on: ${{ matrix.os }}
needs: lock-dependencies
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.7"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
experimental: [false]
fail-fast: true
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
args: [--negate]
types: [text]
exclude_types: [json, pofile]
exclude: 'changelog/|py.typed|disnake/bin/COPYING|.github/PULL_REQUEST_TEMPLATE.md|.github/CODEOWNERS|LICENSE|MANIFEST.in'
exclude: 'changelog/|py.typed|disnake/bin/COPYING|.github/PULL_REQUEST_TEMPLATE.md|.github/CODEOWNERS|LICENSE|MANIFEST.in|.gitattributes'

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.9.3
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Specific development aspects are further explained below.

### Initial setup

We use [`PDM`](https://pdm.fming.dev/) as our dependency manager. If it isn't already installed on your system, you can follow the installation steps [here](https://pdm.fming.dev/latest/#installation) to get started.
We use [`PDM`](https://pdm-project.org/) as our dependency manager. If it isn't already installed on your system, you can follow the installation steps [here](https://pdm-project.org/latest/#installation) to get started.

Once PDM is installed, use the following command to initialize a virtual environment, install the necessary development dependencies, and install the [`pre-commit`](#pre-commit) hooks.
```
Expand Down
1 change: 1 addition & 0 deletions changelog/1278.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update internal package management tooling to latest versions, speed up CI by caching dependency metadata.
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NoxSessionFunc = Callable[Concatenate[nox.Session, P], T]


# see https://pdm.fming.dev/latest/usage/advanced/#use-nox-as-the-runner
# see https://pdm-project.org/latest/usage/advanced/#use-nox-as-the-runner
os.environ.update(
{
"PDM_IGNORE_SAVED_PYTHON": "1",
Expand Down
22 changes: 9 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ docs = [
"sphinx-notfound-page==0.8.3",
]

[tool.pdm.dev-dependencies]
[dependency-groups]
nox = [
"nox==2022.11.21",
]
Expand Down Expand Up @@ -104,25 +104,21 @@ build = [
"twine~=5.1.1",
]


[tool.pdm]
# Ignore `requires-python` warnings when locking, the latest versions of some
# dependencies already require >=3.9
# See also https://pdm-project.org/en/latest/usage/config/#ignore-package-warnings
ignore_package_warnings = ["*"]

[tool.pdm.scripts]
docs = { cmd = "nox -Rs docs --", help = "Build the documentation for development" }
lint = { cmd = "nox -Rs lint --", help = "Check all files for linting errors" }
pyright = { cmd = "nox -Rs pyright --", help = "Run pyright" }
setup_env = { cmd = "pdm install -d -G speed -G docs -G voice", help = "Set up the local environment and all dependencies" }
setup_env = { cmd = "{pdm} install -G:all", help = "Set up the local environment and all dependencies" }
post_setup_env = { composite = ["python -m ensurepip --default-pip", "pre-commit install --install-hooks"] }
test = { cmd = "nox -Rs test --", help = "Run pytest" }

# legacy tasks for those who still type `task`
[tool.taskipy.tasks]
docs = { cmd = "docs", help = "Build the documentation for development" }
lint = { cmd = "lint", help = "Check all files for linting errors" }
pyright = { cmd = "pyright", help = "Run pyright" }
setup_env = { cmd = "setup_env", help = "Setup the local environment and set up all dependencies" }
test = { cmd = "test", help = "Run pytest" }

[tool.taskipy.settings]
runner = "pdm run"

[tool.ruff]
line-length = 100
target-version = "py38"
Expand Down
Loading