Skip to content

Commit cb49540

Browse files
committed
refactor(template): switch project automation from mise tasks to nox sessions
Add a generated noxfile and update test and benchmark workflows to discover and run nox sessions through uv, so template projects use one consistent automation entrypoint locally and in CI. Remove redundant test and bench shell tasks and inline pyright config, while updating ignores and install locking to support the new environment layout more reliably.
1 parent d4cefd1 commit cb49540

15 files changed

Lines changed: 109 additions & 142 deletions

File tree

.config/cspell.config.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ cache:
77
caseSensitive: false
88
enableGlobDot: true
99
ignorePaths:
10-
- .cspell.*
1110
- .git/
12-
- "*-lock.*"
13-
- "*.lock"
1411
- cspell.*
15-
- go.sum
1612
ignoreRandomStrings: true
13+
maxFileSize: 500KB
1714
useGitignore: true
1815
words:
1916
- arithmatex
@@ -27,11 +24,13 @@ words:
2724
- getattr
2825
- hynek
2926
- inlinehilite
27+
- kwargs
3028
- libc
3129
- liblaf
3230
- mathjax
3331
- mkdocs
3432
- mkdocstrings
33+
- noxfile
3534
- numprocesses
3635
- numpy
3736
- pycache
@@ -45,13 +44,11 @@ words:
4544
- pyproject
4645
- pyrightconfig
4746
- pytest
48-
- pyvenv
4947
- pyvista
5048
- sdist
5149
- strftime
5250
- tombi
5351
- trimesh
54-
- unshallow
5552
- uuidgen
5653
- venv
5754
- virtualenv

copier.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ _skip_if_exists:
4545
- docs/.nav.yml
4646
- docs/README.md
4747
- mkdocs.yaml
48+
- noxfile.py
4849
- pyproject.toml
4950
- README.md
5051
- src/

template/.config/copier/mise-tasks/bench.sh

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

template/.config/copier/mise-tasks/install.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ function has() {
99
type "$@" &> /dev/null
1010
}
1111

12+
function lock() {
13+
local -r id="$(basename -- "$PWD")"
14+
mkdir --parents --verbose '/tmp/mise-flock'
15+
flock --nonblock "/tmp/mise-flock/$id.lock" "$@"
16+
}
17+
1218
if [[ -f 'pixi.lock' ]]; then
1319
pixi='pixi'
1420
if has pixi-wrapper.sh; then pixi='pixi-wrapper.sh'; fi
15-
"$pixi" install "$@"
21+
lock "$pixi" install "$@"
1622
fi
1723

1824
if [[ -f 'uv.lock' ]]; then
1925
uv_sync=(uv sync)
2026
if has uv-sync.sh; then uv_sync=(uv-sync.sh); fi
21-
"${uv_sync[@]}" "$@"
27+
lock "${uv_sync[@]}" "$@"
2228
fi

template/.config/copier/mise-tasks/test.sh

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

template/.config/copier/mise-tasks/upgrade.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ function has() {
1010
type "$@" &> /dev/null
1111
}
1212

13+
function lock() {
14+
local -r name="$(basename -- "$PWD")"
15+
mkdir --parents --verbose '/tmp/mise-flock'
16+
flock --nonblock "/tmp/mise-flock/$name.lock" "$@"
17+
}
18+
1319
if [[ -f 'pixi.lock' ]]; then
1420
pixi='pixi'
1521
if has pixi-wrapper.sh; then pixi='pixi-wrapper.sh'; fi
16-
"$pixi" upgrade "$@"
22+
lock "$pixi" upgrade "$@"
1723
fi
1824

1925
if [[ -f 'uv.lock' ]]; then
2026
uv_sync=(uv sync)
2127
if has uv-sync.sh; then uv_sync=(uv-sync.sh); fi
22-
"${uv_sync[@]}" --upgrade "$@"
28+
lock "${uv_sync[@]}" --upgrade "$@"
2329
fi

template/.config/linters/pyrightconfig.json

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

template/.github/workflows/bench.yaml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,43 @@ jobs:
1818
name: Collect
1919
runs-on: ubuntu-latest
2020
outputs:
21-
has-benches: ${{ steps.collect.outputs.has-benches }}
22-
python-versions: ${{ steps.inspect.outputs.supported_python_classifiers_json_array }}
21+
sessions: ${{ steps.collect.outputs.sessions }}
2322
steps:
2423
- name: Checkout
2524
uses: actions/checkout@v6
26-
- id: inspect
27-
name: Build and Inspect a Python Package
28-
uses: hynek/build-and-inspect-python-package@v2
29-
- name: Setup Python
30-
uses: liblaf/actions/setup-python@v1
25+
- name: Setup uv
26+
uses: astral-sh/setup-uv@v7
27+
with:
28+
activate-environment: true
29+
- name: Install Dependencies
30+
run: uv sync --active --frozen --all-packages
3131
- id: collect
3232
name: Collect
3333
run: |-
34-
if pytest -m 'benchmark' --collect-only; then
35-
echo 'has-tests=true' >> "$GITHUB_OUTPUT"
36-
else
37-
code="$?"
38-
if (("$code" == 5)); then
39-
echo 'has-tests=false' >> "$GITHUB_OUTPUT"
40-
else
41-
exit "$code"
42-
fi
43-
fi
34+
echo "sessions=$(
35+
nox --list-sessions --json --tags 'bench' |
36+
jq --compact-output '[.[].session]'
37+
)" >> "$GITHUB_OUTPUT"
4438
4539
# CodSpeedHQ does not support the same benchmark multiple times
4640
# so we don't run on multiple python versions here.
4741
bench:
4842
name: Bench
4943
needs:
5044
- collect
51-
if: needs.collect.outputs.has-benches == 'true'
45+
if: needs.collect.outputs.sessions != '[]'
5246
runs-on: ubuntu-latest
5347
steps:
5448
- name: Checkout
5549
uses: actions/checkout@v6
56-
- name: Setup Python
57-
uses: liblaf/actions/setup-python@v1
58-
- name: Install Mise
59-
uses: jdx/mise-action@v4
50+
- name: Setup uv
51+
uses: astral-sh/setup-uv@v7
52+
with:
53+
activate-environment: true
54+
- name: Install Dependencies
55+
run: uv sync --active --frozen --all-packages
6056
- name: Bench
6157
uses: CodSpeedHQ/action@v4
6258
with:
63-
run: mise run bench
59+
run: nox --tags 'bench'
6460
mode: instrumentation
65-
env:
66-
FORCE_COLOR: 1

template/.github/workflows/docs.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ jobs:
2727
uses: actions/configure-pages@v5
2828
- name: Set Environment Variables
2929
run: echo 'SITE_URL=${{ steps.config.outputs.base_url }}' >> "$GITHUB_ENV"
30-
- name: Setup Python
31-
uses: liblaf/actions/setup-python@v1
30+
- name: Setup uv
31+
uses: astral-sh/setup-uv@v7
32+
with:
33+
activate-environment: true
34+
- name: Install Dependencies
35+
run: uv sync --active --frozen --all-packages
3236
- if: hashFiles('docs/scripts/pre-build.sh') != ''
3337
name: Pre-Build
3438
run: docs/scripts/pre-build.sh

template/.github/workflows/test.yaml

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,45 @@ jobs:
2020
name: Collect
2121
runs-on: ubuntu-latest
2222
outputs:
23-
has-tests: ${{ steps.collect.outputs.has-tests }}
24-
python-versions: ${{ steps.inspect.outputs.supported_python_classifiers_json_array }}
23+
sessions: ${{ steps.collect.outputs.sessions }}
2524
steps:
2625
- name: Checkout
2726
uses: actions/checkout@v6
28-
- id: inspect
29-
name: Build and Inspect a Python Package
30-
uses: hynek/build-and-inspect-python-package@v2
31-
- name: Setup Python
32-
uses: liblaf/actions/setup-python@v1
27+
- name: Setup uv
28+
uses: astral-sh/setup-uv@v7
29+
with:
30+
activate-environment: true
31+
- name: Install Dependencies
32+
run: uv sync --active --frozen --all-packages
3333
- id: collect
3434
name: Collect
3535
run: |-
36-
if pytest --collect-only; then
37-
echo 'has-tests=true' >> "$GITHUB_OUTPUT"
38-
else
39-
code="$?"
40-
if (("$code" == 5)); then
41-
echo 'has-tests=false' >> "$GITHUB_OUTPUT"
42-
else
43-
exit "$code"
44-
fi
45-
fi
36+
echo "sessions=$(
37+
nox --list-sessions --json --tags 'test' |
38+
jq --compact-output '[.[].session]'
39+
)" >> "$GITHUB_OUTPUT"
4640
4741
test:
4842
name: Test
4943
permissions:
5044
id-token: write
5145
needs:
5246
- collect
53-
if: needs.collect.outputs.has-tests == 'true'
47+
if: needs.collect.outputs.sessions != '[]'
5448
runs-on: ubuntu-latest
55-
env:
56-
EAGER_IMPORT: true # ref: <https://github.com/scientific-python/lazy-loader?tab=readme-ov-file#early-failure>
5749
steps:
5850
- name: Checkout
5951
uses: actions/checkout@v6
6052
with:
6153
fetch-depth: 0 # I don't know why, but it is present in Codecov's documentation
62-
- name: Setup Python
63-
uses: liblaf/actions/setup-python@v1
54+
- name: Setup uv
55+
uses: astral-sh/setup-uv@v7
6456
with:
65-
python-version: ${{ matrix.python-version }}
66-
- name: Install Mise
67-
uses: jdx/mise-action@v4
57+
activate-environment: true
58+
- name: Install Dependencies
59+
run: uv sync --active --frozen --all-packages
6860
- name: Test
69-
run: mise run test
61+
run: nox --session '${{ matrix.session }}'
7062
- if: success() || failure()
7163
name: Upload Coverage
7264
uses: codecov/codecov-action@v5
@@ -81,5 +73,5 @@ jobs:
8173
use_oidc: true
8274
strategy:
8375
matrix:
84-
python-version: ${{ fromJson(needs.collect.outputs.python-versions) }}
76+
session: ${{ fromJson(needs.collect.outputs.sessions) }}
8577
fail-fast: false

0 commit comments

Comments
 (0)