diff --git a/.github/workflows/python-quality.yml b/.github/workflows/python-quality.yml index 3d400487f3..97be22d052 100644 --- a/.github/workflows/python-quality.yml +++ b/.github/workflows/python-quality.yml @@ -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 diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 618a5a934e..d04939e273 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -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 @@ -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 @@ -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