1+ variables :
2+ UV_INSTALL_DIR : " ${CI_PROJECT_DIR}/.local/bin"
3+ UV_CACHE_DIR : " ${CI_PROJECT_DIR}/.uv-cache"
4+ UV_LINK_MODE : copy
5+
16stages :
7+ - setup
28 - build
39 - static-analysis
410 - test
511 - doc
612
713.default-before-script : &default-before-script
8- - python --version
14+ - export PATH="${UV_INSTALL_DIR}:$PATH"
15+ - source "${UV_INSTALL_DIR}/env"
16+ - uv run --no-sync python --version
917
1018.check-torch-cuda : &check-torch-cuda
1119 - |
12- TORCH_VERSION="$TORCH_VERSION" python <<EOF
20+ TORCH_VERSION="$TORCH_VERSION" uv run --no-sync python <<EOF
1321 import os, torch
1422 from packaging import version
1523 print(f"{torch.__version__=}\n{torch.version.cuda=}\n{torch.cuda.is_available()=}")
@@ -21,14 +29,27 @@ stages:
2129 # assert torch.cuda.is_available(), "CUDA is not available"
2230 EOF
2331
32+ uv-install :
33+ image : python:3.10-buster
34+ stage : setup
35+ script :
36+ - curl -LsSf https://astral.sh/uv/install.sh | sh
37+ - *default-before-script
38+ artifacts :
39+ paths :
40+ - " .local/"
41+ expire_in : 1 day
42+ tags :
43+ - docker
44+
2445wheel :
2546 image : python:$PYTHON_VERSION-buster
2647 stage : build
2748 before_script :
49+ # - export UV_PYTHON="$PYTHON_VERSION"
2850 - *default-before-script
29- - python -m pip install build
3051 script :
31- - python -m build --wheel .
52+ - uv build --wheel
3253 artifacts :
3354 paths :
3455 - dist/
4465 stage : build
4566 before_script :
4667 - *default-before-script
47- - python -m pip install build
4868 script :
49- - python -m build --sdist .
69+ - uv build --sdist
5070 tags :
5171 - docker
5272
@@ -55,9 +75,9 @@ flake8:
5575 image : pytorch/pytorch:2.2.0-cuda11.8-cudnn8-devel
5676 before_script :
5777 - *default-before-script
58- - python -m pip install flake8 flake8-bugbear flake8-comprehensions
78+ - uv sync --only-group=dev
5979 script :
60- - make check-flake8
80+ - uv run --no-sync make check-flake8
6181 tags :
6282 - docker
6383
@@ -66,11 +86,9 @@ ruff-format:
6686 image : python:3.10-buster
6787 before_script :
6888 - *default-before-script
69- - python -m pip install tomli
70- - RUFF_VERSION=$(python -c 'import tomli; config = tomli.load(open("uv.lock", "rb")); ruff_config = next(x for x in config["package"] if x["name"] == "ruff"); print(ruff_config["version"])')
71- - python -m pip install "ruff==$RUFF_VERSION"
89+ - uv sync --only-group=dev
7290 script :
73- - make check-ruff-format
91+ - uv run --no-sync make check-ruff-format
7492 tags :
7593 - docker
7694
@@ -79,11 +97,9 @@ ruff-organize-imports:
7997 image : python:3.10-buster
8098 before_script :
8199 - *default-before-script
82- - python -m pip install tomli
83- - RUFF_VERSION=$(python -c 'import tomli; config = tomli.load(open("uv.lock", "rb")); ruff_config = next(x for x in config["package"] if x["name"] == "ruff"); print(ruff_config["version"])')
84- - python -m pip install "ruff==$RUFF_VERSION"
100+ - uv sync --only-group=dev
85101 script :
86- - make check-ruff-organize-imports
102+ - uv run --no-sync make check-ruff-organize-imports
87103 tags :
88104 - docker
89105
@@ -102,17 +118,39 @@ test:
102118 TORCH_VERSION=2.2.0+cu118
103119 TORCHVISION_VERSION=0.17.0+cu118
104120 fi
105- - python -m pip install -U pip
106- - python -m pip install -e .
107- - python -m pip install pytest pytest-cov plotly
121+ - |
122+ if grep -q "tool.uv" pyproject.toml; then
123+ echo "[tool.uv] already exists in pyproject.toml"
124+ exit 1
125+ fi
126+ - |
127+ cat <<EOF >> pyproject.toml
128+
129+ [tool.uv]
130+ override-dependencies = [
131+ "torch==$TORCH_VERSION",
132+ "torchvision==$TORCHVISION_VERSION",
133+ ]
134+
135+ [tool.uv.sources]
136+ torch = { index = "pytorch-$CUDA_VERSION_NAME" }
137+ torchvision = { index = "pytorch-$CUDA_VERSION_NAME" }
138+
139+ [[tool.uv.index]]
140+ name = "pytorch-$CUDA_VERSION_NAME"
141+ url = "https://download.pytorch.org/whl/$CUDA_VERSION_NAME"
142+ explicit = true
143+
144+ EOF
145+ - uv sync --group=test
108146 - *check-torch-cuda
109147 - |
110148 PYTEST_ARGS=(--cov=compressai --capture=no tests)
111149 if [ "$CI_COMMIT_BRANCH" != "master" ]; then
112150 PYTEST_ARGS+=(-m "not pretrained")
113151 fi
114152 script :
115- - pytest "${PYTEST_ARGS[@]}"
153+ - uv run --no-sync pytest "${PYTEST_ARGS[@]}"
116154 parallel :
117155 matrix :
118156 - PYTORCH_IMAGE :
@@ -126,10 +164,9 @@ doc:
126164 image : pytorch/pytorch:2.2.0-cuda11.8-cudnn8-devel
127165 before_script :
128166 - *default-before-script
129- - python -m pip install -e .
167+ - uv sync --group=doc
130168 - cd docs
131- - python -m pip install -r requirements.txt
132169 script :
133- - make html
170+ - uv run --no-sync make html
134171 tags :
135172 - docker
0 commit comments