Skip to content

Fix ModelHubMixin: save config only if doesn't exist #5617

Fix ModelHubMixin: save config only if doesn't exist

Fix ModelHubMixin: save config only if doesn't exist #5617

Workflow file for this run

name: Python tests
on:
push:
branches:
- main
- ci_*
paths-ignore:
- "docs/**"
pull_request:
types: [assigned, opened, synchronize, reopened]
paths-ignore:
- "docs/**"
jobs:
build-ubuntu:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.11"]
test_name:
[
"Repository only",
"Everything else",
"torch",
]
include:
- python-version: "3.11" # LFS not ran on 3.8
test_name: "lfs"
- python-version: "3.8"
test_name: "fastai" # fastai not supported on 3.11 -> test it on 3.10
- python-version: "3.10"
test_name: "fastai"
- python-version: "3.8"
test_name: "tensorflow" # Tensorflow not supported on 3.11 -> test it on 3.10
- python-version: "3.10"
test_name: "tensorflow"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
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: Install dependencies
run: |
uv pip install "huggingface_hub[testing] @ ."
case "${{ matrix.test_name }}" in
"Repository only" | "Everything else")
sudo apt update
sudo apt install -y libsndfile1-dev
;;
lfs)
git config --global user.email "ci@dummy.com"
git config --global user.name "ci"
;;
fastai | torch)
uv pip install "huggingface_hub[${{ matrix.test_name }}] @ ."
;;
tensorflow)
sudo apt update
sudo apt install -y graphviz
uv pip install "huggingface_hub[tensorflow] @ ."
;;
esac
# 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
"Repository only")
# Run repo tests concurrently
PYTEST="$PYTEST ../tests -k 'TestRepository' -n 4"
echo $PYTEST
eval $PYTEST
;;
"Everything else")
PYTEST="$PYTEST ../tests -k 'not TestRepository' -n 4"
echo $PYTEST
eval $PYTEST
;;
lfs)
eval "RUN_GIT_LFS_TESTS=1 $PYTEST ../tests -k 'HfLargefilesTest'"
;;
fastai)
eval "$PYTEST ../tests/test_fastai*"
;;
tensorflow)
# Cannot be on same line since '_tf*' checks if tensorflow is NOT imported by default
eval "$PYTEST ../tests/test_tf*"
eval "$PYTEST ../tests/test_keras*"
eval "$PYTEST ../tests/test_serialization.py"
;;
torch)
eval "$PYTEST ../tests/test_hub_mixin*"
eval "$PYTEST ../tests/test_serialization.py"
;;
esac
# Upload code coverage
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
verbose: true
build-windows:
# (almost) Duplicate config compared to `build-ubuntu` but running on Windows.
# Please make sure to keep it updated as well.
# Lighter version of the tests with only 1 test suite running on Python3.8.
runs-on: windows-latest
env:
DISABLE_SYMLINKS_IN_WINDOWS_TESTS: 1
strategy:
fail-fast: false
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
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: Install dependencies
run: uv pip install "huggingface_hub[testing] @ ."
# Run tests
- name: Run tests
working-directory: ./src # For code coverage to work
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
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
verbose: true