Skip to content

Commit b205efc

Browse files
committed
Fix uv resolving for the whole range of python versions.
* uv somehow decides to constrain libraries to be compatible with the whole range of python versions supported by torchjd (3.10-3.13) when resolving, so it does not install libraries that require python 3.11+ for example, even when using python 3.13. This leads to outdated library versions installed in the CI and locally, especially documentation-related libraries. * Adding --python-version=... forces uv to resolve libraries compatible with the specified python version only, fixing the issue * When using `uv run ...`, uv automatically re-syncs. There's no way to specify the python-version for which to resolve when this happens, so the idea is to prevent this resyncing by either using --no-sync everytime we call uv run, or by using the UV_NO_SYNC=1 environment variable. This is done in both ci files that have a uv run, and it's now recommended in CONTRIBUTING.md
1 parent d6fb95a commit b205efc

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
tags:
77
- 'v[0-9]*.[0-9]*.[0-9]*'
88

9+
env:
10+
UV_NO_SYNC: 1
11+
912
jobs:
1013
build-deploy-doc:
1114
name: Build & deploy doc
@@ -23,7 +26,7 @@ jobs:
2326
python-version: '3.13'
2427

2528
- name: Install dependencies (default with full options & doc)
26-
run: uv pip install '.[full]' --group doc
29+
run: uv pip install --python-version=${{ inputs.python-version }} '.[full]' --group doc
2730

2831
- name: Determine deployment folder
2932
id: deploy_folder

.github/workflows/tests.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
schedule:
77
- cron: '41 16 * * *' # Every day at 16:41 UTC (to avoid high load at exact hour values).
88

9+
env:
10+
UV_NO_SYNC: 1
11+
912
jobs:
1013
tests-full-install:
1114
name: Run tests with full install
@@ -23,7 +26,7 @@ jobs:
2326
with:
2427
python-version: ${{ matrix.python-version }}
2528
- name: Install default (with full options) and test dependencies
26-
run: uv pip install '.[full]' --group test
29+
run: uv pip install --python-version=${{ inputs.python-version }} '.[full]' --group test
2730
- name: Run unit and doc tests with coverage report
2831
run: uv run pytest -W error tests/unit tests/doc --cov=src --cov-report=xml
2932
- name: Upload results to Codecov
@@ -41,7 +44,7 @@ jobs:
4144
with:
4245
python-version: '3.13'
4346
- name: Install default (without any option) and test dependencies
44-
run: uv pip install . --group test
47+
run: uv pip install --python-version=${{ inputs.python-version }} . --group test
4548
- name: Run unit and doc tests with coverage report
4649
run: |
4750
uv run pytest -W error tests/unit tests/doc \
@@ -67,7 +70,7 @@ jobs:
6770
python-version: '3.13'
6871

6972
- name: Install dependencies (default with full options & doc)
70-
run: uv pip install '.[full]' --group doc
73+
run: uv pip install --python-version=${{ inputs.python-version }} '.[full]' --group doc
7174

7275
- name: Build Documentation
7376
working-directory: docs
@@ -86,7 +89,7 @@ jobs:
8689
python-version: '3.13'
8790

8891
- name: Install dependencies (default with full options & check)
89-
run: uv pip install '.[full]' --group check
92+
run: uv pip install --python-version=${{ inputs.python-version }} '.[full]' --group check
9093

9194
- name: Run mypy
9295
run: uv run mypy src/torchjd

CONTRIBUTING.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ mandatory, we only provide installation steps with this tool. You can install it
1919
2) Create a virtual environment and install the project in it. From the root of `torchjd`, run:
2020
```bash
2121
uv venv
22-
CC=gcc uv pip install -e '.[full]' --group check --group doc --group test --group plot
22+
CC=gcc uv pip install --python-version=3.13.3 -e '.[full]' --group check --group doc --group test --group plot
23+
```
24+
We also advise using `UV_NO_SYNC=1` to prevent `uv` from syncing all the time. This is because by
25+
default, it tries to resolve libraries compatible with the whole range of Python versions
26+
supported by TorchJD, but in reality, we just need an installation compatible with the currently
27+
used Python version. That's also why we specify `--python-version=3.14` when running
28+
`uv pip install`. To follow that recommendation, add the following line to your `.bashrc`:
29+
```bash
30+
export UV_NO_SYNC=1
31+
```
32+
and start a new terminal. The alternative is to use the `--no-sync` flag whenever you run a pip
33+
command that would normally sync (like `uv run`).
34+
35+
3) Install pre-commit:
36+
```bash
2337
uv run pre-commit install
2438
```
2539

@@ -46,7 +60,7 @@ from the root of `torchjd`:
4660
rm -rf .venv
4761
rm uv.lock
4862
uv venv
49-
CC=gcc uv pip install -e '.[full]' --group check --group doc --group test --group plot
63+
CC=gcc uv pip install --python-version=3.13.3 -e '.[full]' --group check --group doc --group test --group plot
5064
uv run pre-commit install
5165
```
5266

0 commit comments

Comments
 (0)