Skip to content

Commit

Permalink
Use uv in CI to speed-up requirements install (#2072)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Wauplin authored Mar 4, 2024
1 parent 05d715f commit 0ab9391
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/python-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies

# Setup venv
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
- name: Setup venv + uv
run: |
pip install --upgrade pip
pip install .[dev]
- run: ruff check tests src contrib # linter
- run: ruff format --check tests src contrib # formatter
- run: python utils/check_contrib_list.py
- run: python utils/check_static_imports.py
- run: python utils/generate_async_inference_client.py
- run: python utils/generate_inference_types.py
pip install --upgrade uv
uv venv
- name: Install dependencies
run: uv pip install "huggingface_hub[dev] @ ."
- run: .venv/bin/ruff check tests src contrib # linter
- run: .venv/bin/ruff format --check tests src contrib # formatter
- run: .venv/bin/python utils/check_contrib_list.py
- run: .venv/bin/python utils/check_static_imports.py
- run: .venv/bin/python utils/generate_async_inference_client.py
- run: .venv/bin/python utils/generate_inference_types.py

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

# Run mypy on full package
- run: mypy src
- run: .venv/bin/mypy src
40 changes: 23 additions & 17 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

# Setup venv
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
- name: Setup venv + uv
run: |
pip install --upgrade uv
uv venv
# Install dependencies
- name: Configure and install dependencies
- name: Install dependencies
run: |
pip install --upgrade pip
pip install .[testing]
uv pip install "huggingface_hub[testing] @ ."
case "${{ matrix.test_name }}" in
Expand All @@ -63,25 +69,22 @@ jobs:
;;
fastai | torch)
pip install .[${{ matrix.test_name }}]
uv pip install "huggingface_hub[${{ matrix.test_name }}] @ ."
;;
tensorflow)
sudo apt update
sudo apt install -y graphviz
pip install .[tensorflow]
uv pip install "huggingface_hub[tensorflow] @ ."
;;
esac
# Easy debugging if CI is broken
- name: Pip freeze
run: pip freeze

# Run tests
- name: Run tests
working-directory: ./src # For code coverage to work
run: |
source ../.venv/bin/activate
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)'"
case "${{ matrix.test_name }}" in
Expand Down Expand Up @@ -148,20 +151,23 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

# Install dependencies
- name: Configure and install dependencies
# Setup venv
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
- name: Setup venv + uv
run: |
pip install --upgrade pip
pip install .[testing]
pip install --upgrade uv
uv venv
# Easy debugging if CI is broken
- name: Pip freeze
run: pip freeze
# Install dependencies
- name: Install dependencies
run: uv pip install "huggingface_hub[testing] @ ."

# Run tests
- name: Run tests
working-directory: ./src # For code coverage to work
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
run: |
..\.venv\Scripts\activate
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
# Upload code coverage
- name: Upload coverage reports to Codecov with GitHub Action
Expand Down

0 comments on commit 0ab9391

Please sign in to comment.