Skip to content

Commit 4de55ab

Browse files
ValerianReyclaude
andauthored
ci: Revamp CI (#503)
* Remove redundant specification of python-version. The python-version argument used when setting up uv is sufficient. * Remove the now unnecessary PYTHON_VERSION environment variable from the env of workflows. * Create composite action to install dependencies, with options and groups as inputs. * Add name to the checkout step * Add anchor upload-codecov in tests.yml * Add pytest.skip in test_nash_mtl.py and test_cagrad.py so that we don't have to use ignore flags when running pytest with default install (i.e. without nashmtl and cagrad dependencies installed). * Factorize all steps running tests to a single step that has default values for all params + a list of overrides. --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 61e6c05 commit 4de55ab

File tree

6 files changed

+107
-75
lines changed

6 files changed

+107
-75
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Install Dependencies
2+
description: Install package dependencies using uv
3+
4+
inputs:
5+
options:
6+
# We can't directly provide the empty string for no options because it would be mapped to the
7+
# default value thanks to github's weird logic (https://github.com/actions/toolkit/issues/940)
8+
description: 'Package options to install (space-separated, e.g., "full"). Use "none" for no options.'
9+
required: false
10+
default: 'full'
11+
groups:
12+
description: 'Dependency groups to install (space-separated, e.g., "test doc")'
13+
required: false
14+
default: ''
15+
16+
runs:
17+
using: composite
18+
steps:
19+
- name: Install dependencies (options=[${{ inputs.options }}], groups=[${{ inputs.groups }}])
20+
shell: bash
21+
run: |
22+
# Map "none" to the empty string
23+
options_input="${{ inputs.options }}"
24+
if [ "$options_input" = "none" ]; then
25+
options_input=""
26+
fi
27+
28+
# Build the install command
29+
cmd="uv pip install -e"
30+
31+
# Convert space-separated options to comma-separated for brackets
32+
# E.g. "abc def" => '.[abc,def]'
33+
options=$(echo "$options_input" | tr ' ' ',')
34+
cmd="$cmd '.[$options]'"
35+
36+
# Add groups
37+
for group in ${{ inputs.groups }}; do
38+
cmd="$cmd --group $group"
39+
done
40+
41+
# Print and execute the command
42+
echo $cmd
43+
eval $cmd

.github/workflows/build-deploy-docs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
env:
1010
UV_NO_SYNC: 1
11-
PYTHON_VERSION: '3.14'
1211

1312
jobs:
1413
build-deploy-doc:
@@ -24,10 +23,11 @@ jobs:
2423
- name: Set up uv
2524
uses: astral-sh/setup-uv@v5
2625
with:
27-
python-version: ${{ env.PYTHON_VERSION }}
26+
python-version: '3.14'
2827

29-
- name: Install dependencies (default with full options & doc)
30-
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group doc
28+
- uses: ./.github/actions/install-deps
29+
with:
30+
groups: doc
3131

3232
- name: Determine deployment folder
3333
id: deploy_folder

.github/workflows/release.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
release:
55
types: [published]
66

7-
env:
8-
PYTHON_VERSION: 3.14
9-
107
jobs:
118
pypi-publish:
129
name: Publish to PyPI
@@ -22,7 +19,7 @@ jobs:
2219
- name: Set up uv
2320
uses: astral-sh/setup-uv@v5
2421
with:
25-
python-version: ${{ env.PYTHON_VERSION }}
22+
python-version: '3.14'
2623

2724
- name: Build
2825
run: uv build

.github/workflows/tests.yml

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,52 @@ on:
88

99
env:
1010
UV_NO_SYNC: 1
11-
PYTHON_VERSION: 3.14
1211

1312
jobs:
14-
tests-full-install:
15-
name: Run tests with full install
16-
runs-on: ${{ matrix.os }}
13+
tests:
14+
# Default config: py3.14, ubuntu-latest, float32, full options.
15+
# The idea is to make each of those params vary one by one, to limit the number of tests to run.
16+
name: Run tests (py${{ matrix.python-version || '3.14' }}, ${{ matrix.os || 'ubuntu-latest' }}, ${{ matrix.dtype || 'float32' }}, ${{ matrix.options || 'full' }})
17+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
1718
strategy:
18-
fail-fast: false # Ensure matrix jobs keep running even if one fails
19+
fail-fast: false
1920
matrix:
20-
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
21-
os: [ubuntu-latest, macOS-latest, windows-latest]
21+
include:
22+
# Python version variations
23+
- python-version: '3.10'
24+
- python-version: '3.11'
25+
- python-version: '3.12'
26+
- python-version: '3.13'
27+
- python-version: '3.14' # To actually run the default config
28+
# OS variations
29+
- os: macOS-latest
30+
- os: windows-latest
31+
# dtype variations
32+
- dtype: float64
33+
# Installation options variations
34+
- options: 'none'
2235

2336
steps:
24-
- uses: actions/checkout@v4
25-
- name: Set up uv
26-
uses: astral-sh/setup-uv@v5
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
- name: Install default (with full options) and test dependencies
30-
run: uv pip install --python-version=${{ matrix.python-version }} -e '.[full]' --group test
31-
- name: Run unit and doc tests with coverage report
32-
run: uv run pytest -W error tests/unit tests/doc --cov=src --cov-report=xml
33-
- name: Upload results to Codecov
34-
uses: codecov/codecov-action@v4
35-
with:
36-
token: ${{ secrets.CODECOV_TOKEN }}
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
3739

38-
tests-default-install:
39-
name: Run (most) tests with default install
40-
runs-on: ubuntu-latest
41-
steps:
42-
- uses: actions/checkout@v4
4340
- name: Set up uv
4441
uses: astral-sh/setup-uv@v5
4542
with:
46-
python-version: ${{ env.PYTHON_VERSION }}
47-
- name: Install default (without any option) and test dependencies
48-
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e . --group test
49-
- name: Run unit and doc tests with coverage report
50-
run: |
51-
uv run pytest -W error tests/unit tests/doc \
52-
--ignore tests/unit/aggregation/test_cagrad.py \
53-
--ignore tests/unit/aggregation/test_nash_mtl.py \
54-
--ignore tests/doc/test_aggregation.py \
55-
--cov=src --cov-report=xml
56-
- name: Upload results to Codecov
57-
uses: codecov/codecov-action@v4
58-
with:
59-
token: ${{ secrets.CODECOV_TOKEN }}
43+
python-version: ${{ matrix.python-version || '3.14' }}
6044

61-
tests-float64:
62-
name: Run tests on float64 dtype
63-
runs-on: ubuntu-latest
64-
steps:
65-
- uses: actions/checkout@v4
66-
- name: Set up uv
67-
uses: astral-sh/setup-uv@v5
45+
- uses: ./.github/actions/install-deps
6846
with:
69-
python-version: ${{ env.PYTHON_VERSION }}
70-
- name: Install default (with full options) and test dependencies
71-
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group test
72-
- name: Run unit and doc tests with coverage report
47+
options: ${{ matrix.options || 'full' }}
48+
groups: test
49+
50+
- name: Run tests
7351
run: uv run pytest -W error tests/unit tests/doc --cov=src --cov-report=xml
7452
env:
75-
PYTEST_TORCH_DTYPE: float64
76-
- name: Upload results to Codecov
53+
PYTEST_TORCH_DTYPE: ${{ matrix.dtype || 'float32' }}
54+
55+
- &upload-codecov
56+
name: Upload results to Codecov
7757
uses: codecov/codecov-action@v4
7858
with:
7959
token: ${{ secrets.CODECOV_TOKEN }}
@@ -88,10 +68,11 @@ jobs:
8868
- name: Set up uv
8969
uses: astral-sh/setup-uv@v5
9070
with:
91-
python-version: ${{ env.PYTHON_VERSION }}
71+
python-version: '3.14'
9272

93-
- name: Install dependencies (default with full options & doc)
94-
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group doc
73+
- uses: ./.github/actions/install-deps
74+
with:
75+
groups: doc
9576

9677
- name: Build Documentation
9778
working-directory: docs
@@ -101,16 +82,17 @@ jobs:
10182
name: Run mypy
10283
runs-on: ubuntu-latest
10384
steps:
104-
- name: Checkout repository
105-
uses: actions/checkout@v4
85+
- name: Checkout repository
86+
uses: actions/checkout@v4
10687

107-
- name: Set up uv
108-
uses: astral-sh/setup-uv@v5
109-
with:
110-
python-version: ${{ env.PYTHON_VERSION }}
88+
- name: Set up uv
89+
uses: astral-sh/setup-uv@v5
90+
with:
91+
python-version: '3.14'
11192

112-
- name: Install dependencies (default with full options & check)
113-
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group check
93+
- uses: ./.github/actions/install-deps
94+
with:
95+
groups: check
11496

115-
- name: Run mypy
116-
run: uv run mypy src/torchjd
97+
- name: Run mypy
98+
run: uv run mypy src/torchjd

tests/unit/aggregation/test_cagrad.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from utils.contexts import ExceptionContext
66
from utils.tensors import ones_
77

8-
from torchjd.aggregation import CAGrad
8+
try:
9+
from torchjd.aggregation import CAGrad
10+
except ImportError:
11+
import pytest
12+
13+
pytest.skip("CAGrad dependencies not installed", allow_module_level=True)
914

1015
from ._asserts import assert_expected_structure, assert_non_conflicting, assert_non_differentiable
1116
from ._inputs import scaled_matrices, typical_matrices

tests/unit/aggregation/test_nash_mtl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
from torch.testing import assert_close
44
from utils.tensors import ones_, randn_
55

6-
from torchjd.aggregation import NashMTL
6+
try:
7+
from torchjd.aggregation import NashMTL
8+
except ImportError:
9+
import pytest
10+
11+
pytest.skip("NashMTL dependencies not installed", allow_module_level=True)
712

813
from ._asserts import assert_expected_structure, assert_non_differentiable
914
from ._inputs import nash_mtl_matrices

0 commit comments

Comments
 (0)