Skip to content

Commit 56a058e

Browse files
authored
ci: update PDM to v2.20.1, cache lockfile between runs (#1278)
1 parent a9dc9b4 commit 56a058e

File tree

9 files changed

+85
-31
lines changed

9 files changed

+85
-31
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# force LF for pyproject to make hashFiles in CI consistent (windows <3)
2+
# (see https://github.com/actions/runner/issues/498)
3+
pyproject.toml text eol=lf

.github/actions/cache-pdm/action.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
name: Configure PDM cache
4+
description: .
5+
inputs:
6+
env-already-initialized:
7+
description: Whether Python/PDM is already configured
8+
required: false
9+
default: 'true'
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Get metadata for cache
15+
id: get-cache-meta
16+
shell: bash
17+
run: |
18+
echo "date=$(date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
19+
20+
- name: Setup/Restore cache
21+
id: cache
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
pdm.lock
26+
# cache lockfile for the current day, roughly
27+
key: pdm-${{ steps.get-cache-meta.outputs.date }}-${{ hashFiles('pyproject.toml') }}
28+
# pdm lockfiles should be platform-agnostic
29+
enableCrossOsArchive: true
30+
31+
- if: ${{ steps.cache.outputs.cache-hit != 'true' && inputs.env-already-initialized != 'true' }}
32+
name: Set up PDM
33+
uses: pdm-project/setup-pdm@v4
34+
with:
35+
python-version: 3.8
36+
version: "2.20.1"
37+
38+
- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
39+
name: Lock all dependencies
40+
shell: bash
41+
run: |
42+
pdm lock -G:all # create pdm.lock

.github/actions/setup-env/action.yml

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ inputs:
66
python-version:
77
description: The python version to install
88
required: true
9-
cache-dependency-path:
10-
description: The path(s) to use for pip caching, defaults to setup + pdm
11-
required: false
12-
default: |
13-
pyproject.toml
14-
setup.py
159
outputs:
1610
python-version:
1711
description: The python version that was installed.
@@ -25,12 +19,8 @@ runs:
2519
uses: pdm-project/setup-pdm@v4
2620
with:
2721
python-version: ${{ inputs.python-version }}
28-
version: "2.4.6"
22+
version: "2.20.1" # last version to support python 3.8
2923
cache: false
30-
cache-dependency-path: ${{ inputs.cache-dependency-path }}
31-
enable-pep582: false # Disable PEP 582 package loading globally
32-
env:
33-
PDM_DEPS: 'importlib-metadata<8; python_version < "3.10"'
3424

3525
- name: Disable PDM version check
3626
shell: bash
@@ -54,3 +44,6 @@ runs:
5444
id: python-version
5545
shell: bash
5646
run: echo "python-version=$(python -c 'import sys; print(".".join(map(str,sys.version_info[:2])))')" >> $GITHUB_OUTPUT
47+
48+
- name: Configure cache
49+
uses: ./.github/actions/cache-pdm

.github/workflows/lint-test.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,25 @@ defaults:
2525
shell: bash
2626

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

38+
# Instead of setup-env, we call the cache-pdm action here directly.
39+
# This avoids having to install PDM, only to find out the cache is already up to date sometimes.
40+
- name: Configure cache
41+
uses: ./.github/actions/cache-pdm
42+
with:
43+
env-already-initialized: false
44+
45+
lint:
46+
runs-on: ubuntu-latest
3147
steps:
3248
- uses: actions/checkout@v4
3349

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

@@ -52,10 +69,10 @@ jobs:
5269

5370
pyright:
5471
runs-on: ubuntu-latest
72+
needs: lock-dependencies
5573
strategy:
5674
matrix:
57-
# FIXME: using specific patch version for 3.12 due to pdm bug
58-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.7"]
75+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
5976
experimental: [false]
6077
fail-fast: false
6178
continue-on-error: ${{ matrix.experimental }}
@@ -105,6 +122,7 @@ jobs:
105122

106123
misc:
107124
runs-on: ubuntu-latest
125+
needs: lock-dependencies
108126
steps:
109127
- uses: actions/checkout@v4
110128

@@ -148,9 +166,10 @@ jobs:
148166
149167
pytest:
150168
runs-on: ${{ matrix.os }}
169+
needs: lock-dependencies
151170
strategy:
152171
matrix:
153-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.7"]
172+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
154173
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
155174
experimental: [false]
156175
fail-fast: true

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
args: [--negate]
3636
types: [text]
3737
exclude_types: [json, pofile]
38-
exclude: 'changelog/|py.typed|disnake/bin/COPYING|.github/PULL_REQUEST_TEMPLATE.md|.github/CODEOWNERS|LICENSE|MANIFEST.in'
38+
exclude: 'changelog/|py.typed|disnake/bin/COPYING|.github/PULL_REQUEST_TEMPLATE.md|.github/CODEOWNERS|LICENSE|MANIFEST.in|.gitattributes'
3939

4040
- repo: https://github.com/charliermarsh/ruff-pre-commit
4141
rev: v0.9.3

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Specific development aspects are further explained below.
6363

6464
### Initial setup
6565

66-
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.
66+
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.
6767

6868
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.
6969
```

changelog/1278.misc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update internal package management tooling to latest versions, speed up CI by caching dependency metadata.

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
NoxSessionFunc = Callable[Concatenate[nox.Session, P], T]
1919

2020

21-
# see https://pdm.fming.dev/latest/usage/advanced/#use-nox-as-the-runner
21+
# see https://pdm-project.org/latest/usage/advanced/#use-nox-as-the-runner
2222
os.environ.update(
2323
{
2424
"PDM_IGNORE_SAVED_PYTHON": "1",

pyproject.toml

+9-13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ docs = [
6464
"sphinx-notfound-page==0.8.3",
6565
]
6666

67-
[tool.pdm.dev-dependencies]
67+
[dependency-groups]
6868
nox = [
6969
"nox==2022.11.21",
7070
]
@@ -104,25 +104,21 @@ build = [
104104
"twine~=5.1.1",
105105
]
106106

107+
108+
[tool.pdm]
109+
# Ignore `requires-python` warnings when locking, the latest versions of some
110+
# dependencies already require >=3.9
111+
# See also https://pdm-project.org/en/latest/usage/config/#ignore-package-warnings
112+
ignore_package_warnings = ["*"]
113+
107114
[tool.pdm.scripts]
108115
docs = { cmd = "nox -Rs docs --", help = "Build the documentation for development" }
109116
lint = { cmd = "nox -Rs lint --", help = "Check all files for linting errors" }
110117
pyright = { cmd = "nox -Rs pyright --", help = "Run pyright" }
111-
setup_env = { cmd = "pdm install -d -G speed -G docs -G voice", help = "Set up the local environment and all dependencies" }
118+
setup_env = { cmd = "{pdm} install -G:all", help = "Set up the local environment and all dependencies" }
112119
post_setup_env = { composite = ["python -m ensurepip --default-pip", "pre-commit install --install-hooks"] }
113120
test = { cmd = "nox -Rs test --", help = "Run pytest" }
114121

115-
# legacy tasks for those who still type `task`
116-
[tool.taskipy.tasks]
117-
docs = { cmd = "docs", help = "Build the documentation for development" }
118-
lint = { cmd = "lint", help = "Check all files for linting errors" }
119-
pyright = { cmd = "pyright", help = "Run pyright" }
120-
setup_env = { cmd = "setup_env", help = "Setup the local environment and set up all dependencies" }
121-
test = { cmd = "test", help = "Run pytest" }
122-
123-
[tool.taskipy.settings]
124-
runner = "pdm run"
125-
126122
[tool.ruff]
127123
line-length = 100
128124
target-version = "py38"

0 commit comments

Comments
 (0)