Skip to content

Commit 0ab9391

Browse files
authored
Use uv in CI to speed-up requirements install (#2072)
* Use uv in CI to speed-up requirements install * fix commands * run in venv * echo * try something else * hack * better? * remove pip freeze * fix * better * fixed * comments * windows
1 parent 05d715f commit 0ab9391

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

.github/workflows/python-quality.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@ jobs:
2323
uses: actions/setup-python@v2
2424
with:
2525
python-version: 3.9
26-
- name: Install dependencies
26+
27+
# Setup venv
28+
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
29+
- name: Setup venv + uv
2730
run: |
28-
pip install --upgrade pip
29-
pip install .[dev]
30-
- run: ruff check tests src contrib # linter
31-
- run: ruff format --check tests src contrib # formatter
32-
- run: python utils/check_contrib_list.py
33-
- run: python utils/check_static_imports.py
34-
- run: python utils/generate_async_inference_client.py
35-
- run: python utils/generate_inference_types.py
31+
pip install --upgrade uv
32+
uv venv
33+
34+
- name: Install dependencies
35+
run: uv pip install "huggingface_hub[dev] @ ."
36+
- run: .venv/bin/ruff check tests src contrib # linter
37+
- run: .venv/bin/ruff format --check tests src contrib # formatter
38+
- run: .venv/bin/python utils/check_contrib_list.py
39+
- run: .venv/bin/python utils/check_static_imports.py
40+
- run: .venv/bin/python utils/generate_async_inference_client.py
41+
- run: .venv/bin/python utils/generate_inference_types.py
3642

3743
# Run type checking at least on huggingface_hub root file to check all modules
3844
# that can be lazy-loaded actually exist.
39-
- run: mypy src/huggingface_hub/__init__.py --follow-imports=silent --show-traceback
45+
- run: .venv/bin/mypy src/huggingface_hub/__init__.py --follow-imports=silent --show-traceback
4046

4147
# Run mypy on full package
42-
- run: mypy src
48+
- run: .venv/bin/mypy src

.github/workflows/python-tests.yml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ jobs:
4444
with:
4545
python-version: ${{ matrix.python-version }}
4646

47+
# Setup venv
48+
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
49+
- name: Setup venv + uv
50+
run: |
51+
pip install --upgrade uv
52+
uv venv
53+
4754
# Install dependencies
48-
- name: Configure and install dependencies
55+
- name: Install dependencies
4956
run: |
50-
pip install --upgrade pip
51-
pip install .[testing]
57+
uv pip install "huggingface_hub[testing] @ ."
5258
5359
case "${{ matrix.test_name }}" in
5460
@@ -63,25 +69,22 @@ jobs:
6369
;;
6470
6571
fastai | torch)
66-
pip install .[${{ matrix.test_name }}]
72+
uv pip install "huggingface_hub[${{ matrix.test_name }}] @ ."
6773
;;
6874
6975
tensorflow)
7076
sudo apt update
7177
sudo apt install -y graphviz
72-
pip install .[tensorflow]
78+
uv pip install "huggingface_hub[tensorflow] @ ."
7379
;;
7480
7581
esac
7682
77-
# Easy debugging if CI is broken
78-
- name: Pip freeze
79-
run: pip freeze
80-
8183
# Run tests
8284
- name: Run tests
8385
working-directory: ./src # For code coverage to work
8486
run: |
87+
source ../.venv/bin/activate
8588
PYTEST="python -m pytest --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none --reruns 5 --reruns-delay 1 --only-rerun '(OSError|Timeout|HTTPError.*502|HTTPError.*504||not less than or equal to 0.01)'"
8689
8790
case "${{ matrix.test_name }}" in
@@ -148,20 +151,23 @@ jobs:
148151
with:
149152
python-version: ${{ matrix.python-version }}
150153

151-
# Install dependencies
152-
- name: Configure and install dependencies
154+
# Setup venv
155+
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
156+
- name: Setup venv + uv
153157
run: |
154-
pip install --upgrade pip
155-
pip install .[testing]
158+
pip install --upgrade uv
159+
uv venv
156160
157-
# Easy debugging if CI is broken
158-
- name: Pip freeze
159-
run: pip freeze
161+
# Install dependencies
162+
- name: Install dependencies
163+
run: uv pip install "huggingface_hub[testing] @ ."
160164

161165
# Run tests
162166
- name: Run tests
163167
working-directory: ./src # For code coverage to work
164-
run: python -m pytest -n 4 --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none --reruns 5 --reruns-delay 1 --only-rerun '(OSError|Timeout|HTTPError.*502|HTTPError.*504|not less than or equal to 0.01)' ../tests
168+
run: |
169+
..\.venv\Scripts\activate
170+
python -m pytest -n 4 --cov=./huggingface_hub --cov-report=xml:../coverage.xml --vcr-record=none --reruns 5 --reruns-delay 1 --only-rerun '(OSError|Timeout|HTTPError.*502|HTTPError.*504|not less than or equal to 0.01)' ../tests
165171
166172
# Upload code coverage
167173
- name: Upload coverage reports to Codecov with GitHub Action

0 commit comments

Comments
 (0)