Skip to content

Commit 558072d

Browse files
feat: replace pdm with uv, nox (#1362)
1 parent 49f7c23 commit 558072d

File tree

16 files changed

+224
-169
lines changed

16 files changed

+224
-169
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
- [ ] If code changes were made, then they have been tested
1010
- [ ] I have updated the documentation to reflect the changes
11-
- [ ] I have formatted the code properly by running `pdm run nox -s lint`
12-
- [ ] I have type-checked the code by running `pdm run nox -s pyright`
11+
- [ ] I have formatted the code properly by running `uv run nox -s lint`
12+
- [ ] I have type-checked the code by running `uv run nox -s pyright`
1313
- [ ] This PR fixes an issue
1414
- [ ] This PR adds something new (e.g. new method or parameters)
1515
- [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)

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

Lines changed: 0 additions & 42 deletions
This file was deleted.

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

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@ description: .
55
inputs:
66
python-version:
77
description: The python version to install
8-
required: true
8+
required: false
9+
default: '3.8'
10+
use-cached-uv-lock:
11+
description: Whether to download the uv lock cache.
12+
required: false
13+
default: 'true'
14+
update-uv-lock:
15+
description: Whether to update the uv lock file. Allows the cache to fail.
16+
required: false
17+
default: 'false'
18+
uv-resolution-strategy:
19+
description: The uv resolution strategy to use. See https://docs.astral.sh/uv/reference/environment/#uv_resolution for details.
20+
required: false
21+
default: 'highest'
922
outputs:
1023
python-version:
1124
description: The python version that was installed.
@@ -14,33 +27,52 @@ outputs:
1427
runs:
1528
using: composite
1629
steps:
17-
- name: Set up pdm with python ${{ inputs.python-version }}
30+
- name: Download uv lock
31+
uses: actions/cache/restore@v4
32+
if: ${{ inputs.use-cached-uv-lock != 'false' }}
33+
id: restore-uv-lock
34+
with:
35+
key: uv-lock-resolved-${{ inputs.uv-resolution-strategy }}
36+
path: uv.lock
37+
restore-keys: |
38+
uv-lock-resolved-${{ inputs.uv-resolution-strategy }}
39+
enableCrossOsArchive: true
40+
fail-on-cache-miss: ${{ inputs.update-uv-lock != 'true' }}
41+
42+
- name: Set up uv with python ${{ inputs.python-version }}
1843
id: setup-python
19-
uses: pdm-project/setup-pdm@v4
44+
uses: astral-sh/setup-uv@v6
2045
with:
21-
allow-python-prereleases: true
46+
version: '0.8.14'
47+
enable-cache: true
48+
# this doesn't install python but pins the uv version; its the same as providing UV_PYTHON
2249
python-version: ${{ inputs.python-version }}
23-
version: "2.20.1" # last version to support python 3.8
24-
cache: false
2550

26-
- name: Disable PDM version check
51+
- name: Install python ${{ inputs.python-version }}
2752
shell: bash
53+
env:
54+
UV_PYTHON_DOWNLOADS: automatic
2855
run: |
29-
pdm config check_update false
56+
uv python install ${{ inputs.python-version }}
3057
31-
- name: Ignore saved pythons
58+
- name: Install nox
3259
shell: bash
3360
run: |
34-
echo "PDM_IGNORE_SAVED_PYTHON=1" >> $GITHUB_ENV
61+
uv tool install nox
3562
36-
- name: Install nox
63+
- name: Lock dependencies
64+
id: lock-uv-deps
65+
if: ${{ inputs.update-uv-lock }}
3766
shell: bash
38-
run: pip install nox
67+
env:
68+
UV_LOCKED: 0
69+
run: uv lock --refresh
3970

4071
- name: Set python version
4172
id: python-version
4273
shell: bash
43-
run: echo "python-version=$(python -c 'import sys; print(".".join(map(str,sys.version_info[:2])))')" >> $GITHUB_OUTPUT
44-
45-
- name: Configure cache
46-
uses: ./.github/actions/cache-pdm
74+
env:
75+
UV_VENV_CLEAR: 1
76+
run: |
77+
uv venv .venv
78+
echo "python-version=$(uv run python -c 'import sys; print(".".join(map(str,sys.version_info[:2])))')" >> $GITHUB_OUTPUT

.github/workflows/changelog.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ jobs:
2828
fetch-depth: '0'
2929

3030
- name: Set up environment
31+
id: setup-env
3132
uses: ./.github/actions/setup-env
3233
with:
33-
python-version: '3.9'
34+
update-uv-lock: true
3435

3536
- name: Install dependencies
36-
run: pdm install -dG changelog
37+
run: uv sync --only-group changelog
3738

3839
- name: Check for presence of a Change Log fragment (only pull requests)
3940
# NOTE: The pull request' base branch needs to be fetched so towncrier
4041
# is able to compare the current branch with the base branch.
4142
run: |
42-
if ! pdm run towncrier check --compare-with origin/${BASE_BRANCH}; then
43+
if ! uv run towncrier check --compare-with origin/${BASE_BRANCH}; then
4344
echo "::error::Please see https://github.com/DisnakeDev/disnake/blob/master/changelog/README.rst for details on how to create a changelog entry." >&2
4445
exit 1
4546
fi

.github/workflows/create-release-pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
python-version: 3.8
4949

5050
- name: Install dependencies
51-
run: pdm install -dG changelog
51+
run: uv sync --no-default-groups --group changelog
5252

5353
- name: Update version
5454
run: |
@@ -57,7 +57,7 @@ jobs:
5757
5858
- name: Build changelog
5959
run: |
60-
pdm run towncrier build --yes --version "$VERSION_INPUT"
60+
uv run towncrier build --yes --version "$VERSION_INPUT"
6161
git commit -a -m "docs: build changelog"
6262
6363
- name: Create pull request

.github/workflows/lint-test.yml

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ defaults:
2525
shell: bash
2626

2727
env:
28+
# https://docs.astral.sh/uv/reference/environment/
29+
UV_LOCKED: 1
30+
UV_NO_SYNC: 1
31+
UV_PYTHON_DOWNLOADS: never
2832
GITHUB_STEP_SUMMARY_HEADER: "<details><summary>#name#</summary>\n<pre>"
2933
GITHUB_STEP_SUMMARY_FOOTER: "</pre></details>\n"
3034

@@ -36,15 +40,48 @@ jobs:
3640
# while still not needing to commit a lockfile to the repo, which is discouraged for libraries as per
3741
# https://pdm-project.org/en/latest/usage/lockfile/
3842
runs-on: ubuntu-latest
43+
env:
44+
UV_RESOLUTION: highest
3945
steps:
4046
- uses: actions/checkout@v4
4147

42-
# Instead of setup-env, we call the cache-pdm action here directly.
43-
# This avoids having to install PDM, only to find out the cache is already up to date sometimes.
44-
- name: Configure cache
45-
uses: ./.github/actions/cache-pdm
48+
- name: Set up environment
49+
id: setup-env
50+
uses: ./.github/actions/setup-env
51+
with:
52+
use-cached-uv-lock: 'false' # we don't need the lock here, we will automatically download it below
53+
54+
- name: Restore uv lock
55+
uses: actions/cache/restore@v4
56+
id: cache-uv-lock
4657
with:
47-
env-already-initialized: false
58+
key: uv-lock-resolved-${{ env.UV_RESOLUTION }}
59+
restore-keys: |
60+
uv-lock-resolved-${{ env.UV_RESOLUTION }}
61+
path: uv.lock
62+
enableCrossOsArchive: true
63+
64+
- name: Check if uv.lock changed
65+
id: uv-lock-changed
66+
continue-on-error: true
67+
if: steps.cache-uv-lock.outputs.cache-hit == 'true' || steps.cache-uv-lock.outputs.cache-hit == 'false'
68+
run: |
69+
uv lock --check
70+
71+
- name: Lock dependencies
72+
if: steps.uv-lock-changed.outcome == 'failure' || steps.cache-uv-lock.outputs.cache-hit != 'true' && steps.cache-uv-lock.outputs.cache-hit != 'false'
73+
id: lock-uv-deps
74+
env:
75+
UV_LOCKED: 0
76+
run: uv lock --refresh
77+
78+
- uses: actions/cache/save@v4
79+
if: steps.lock-uv-deps.outcome == 'success'
80+
name: upload-uv-lock
81+
with:
82+
key: uv-lock-resolved-${{ env.UV_RESOLUTION }}-${{ hashFiles('uv.lock') }}
83+
path: uv.lock
84+
enableCrossOsArchive: true
4885

4986
# Used to determine which python versions to test against.
5087
# noxfile.py is the source of truth, which in turn draws from
@@ -62,7 +99,7 @@ jobs:
6299
- name: Set up environment
63100
uses: ./.github/actions/setup-env
64101
with:
65-
python-version: 3.8
102+
use-cached-uv-lock: 'false' # we don't need the lock here
66103

67104
- name: Determine Python versions to test and lint against
68105
id: set-matrix
@@ -120,7 +157,6 @@ jobs:
120157
- lint
121158
strategy:
122159
matrix:
123-
# TODO: add 3.14 once we switch to uv
124160
session: ${{ fromJson(needs.python-versions.outputs.pyright-sessions) }}
125161
fail-fast: false
126162
continue-on-error: ${{ matrix.session.experimental }}
@@ -136,9 +172,9 @@ jobs:
136172
- name: Add .venv/bin to PATH
137173
id: venv-bin
138174
run: |
139-
pdm venv create
140-
dirname "$(pdm info --python)" >> $GITHUB_PATH
141-
echo python="$(pdm info --python)" >> $GITHUB_OUTPUT
175+
uv venv .venv
176+
dirname "$(uv python find)" >> $GITHUB_PATH
177+
echo python="$(uv python find)" >> $GITHUB_OUTPUT
142178
143179
- name: Install dependencies
144180
# `--no-venv` to install in the main pdm venv instead of nox's pyright-specific one
@@ -196,21 +232,15 @@ jobs:
196232
run: |
197233
nox -s slotscheck
198234
199-
- name: Run check-manifest
200-
if: (success() || failure()) && steps.setup.outcome == 'success'
201-
run: nox -s check-manifest
202-
203-
# This only runs if the previous steps were successful, no point in running it otherwise
204235
- name: Try building package
236+
if: (success() || failure()) && steps.setup.outcome == 'success'
205237
run: |
206-
pdm install -dG build
207-
208-
pdm run python -m build
238+
nox -s build
209239
ls -la dist/
210240
211241
- name: Check README.md renders properly on PyPI
212242
run: |
213-
pdm run twine check --strict dist/*
243+
uvx twine~=6.1 check --strict dist/*
214244
215245
codemod:
216246
runs-on: ubuntu-latest
@@ -237,7 +267,7 @@ jobs:
237267
if [ -n "$(git status --porcelain)" ]; then
238268
echo "::error::Please run 'nox -s codemod -- run-all' locally and commit the changes." >&2;
239269
echo "$GITHUB_STEP_SUMMARY_HEADER" | sed "s/#name#/LibCST Codemod/" >> $GITHUB_STEP_SUMMARY
240-
echo "The libcst codemod made changes to the codebase. Please run 'nox -s codemod -- run-all' locally and commit the changes." >> $GITHUB_STEP_SUMMARY
270+
echo "The libcst codemod made changes to the codebase. Please run 'uv run nox -s codemod -- run-all' locally and commit the changes." >> $GITHUB_STEP_SUMMARY
241271
echo "::group::git diff"
242272
git diff |& tee -a $GITHUB_STEP_SUMMARY
243273
echo "::endgroup::"
@@ -256,7 +286,6 @@ jobs:
256286
strategy:
257287
matrix:
258288
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
259-
# TODO: add 3.14 once we switch to uv
260289
session: ${{ fromJson(needs.python-versions.outputs.test-sessions) }}
261290
fail-fast: true
262291
continue-on-error: ${{ matrix.session.experimental }}
@@ -288,6 +317,7 @@ jobs:
288317
- name: Print Coverage Output
289318
if: always() && (steps.run_tests.outcome == 'success' || steps.run_tests.outcome == 'failure')
290319
env:
320+
UV_NO_SYNC: 0
291321
NOXSESSION: coverage
292322
run: |
293323
echo "$GITHUB_STEP_SUMMARY_HEADER" | sed "s/#name#/Coverage Summary/" >> $GITHUB_STEP_SUMMARY

.github/workflows/release.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ jobs:
2525
with:
2626
python-version: 3.8
2727

28-
- name: Install dependencies
29-
run: pdm install -dG build
30-
3128
- name: Build package
3229
run: |
33-
pdm run python -m build
30+
uvx --from=build~=1.3 pyproject-build
3431
ls -la dist/
3532
3633
- name: Twine check
37-
run: pdm run twine check --strict dist/*
34+
run: uvx twine~=6.1 check --strict dist/*
3835

3936
- name: Show metadata
4037
run: |

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ venvs/
3131
.coverage*
3232
coverage.xml
3333
__pypackages__/
34-
.pdm.toml
35-
.pdm-python
36-
pdm.lock
34+
.python-version
35+
uv.lock

.readthedocs.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ build:
77
os: ubuntu-24.04
88
tools:
99
python: "3.8"
10+
jobs:
11+
create_environment:
12+
- asdf plugin add uv
13+
- asdf install uv latest
14+
- asdf global uv latest
15+
- UV_PROJECT_ENVIRONMENT=$READTHEDOCS_VIRTUALENV_PATH uv sync --no-default-groups --extra docs
16+
install:
17+
- "true"
18+
1019
sphinx:
1120
configuration: docs/conf.py
1221
fail_on_warning: false
1322
builder: html
14-
python:
15-
install:
16-
- method: pip
17-
path: .
18-
extra_requirements:
19-
- docs

0 commit comments

Comments
 (0)