forked from huggingface/huggingface_hub
-
Notifications
You must be signed in to change notification settings - Fork 0
234 lines (203 loc) · 8.16 KB
/
Copy pathpython-tests.yml
File metadata and controls
234 lines (203 loc) · 8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
name: Python tests
on:
push:
branches:
- main
- ci_*
paths-ignore:
- "docs/**"
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- "docs/**"
# Cancel superseded runs: a new push to a PR makes the previous run useless.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-imports:
# Catch missing dependencies: install only base requirements and verify all public imports work.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.14"
- name: Install base dependencies only
run: |
pip install --upgrade uv
uv venv
uv pip install .
- name: Check imports
run: |
source .venv/bin/activate
python utils/check_imports.py
build-ubuntu:
runs-on:
group: aws-general-8-plus
# A healthy full-suite job takes ~20min. Anything much longer means something is stuck: fail fast instead of
# burning a runner until GitHub's 6h limit.
timeout-minutes: 45
env:
UV_HTTP_TIMEOUT: 600 # max 10min to install deps
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.14"]
test_name: ["no hf_xet", "Inference only", "with hf_xet"]
include:
- python-version: "3.10" # test torch~=1.11 on python 3.10 only.
test_name: "Python 3.10, torch_1.11"
- python-version: "3.12" # test torch latest on python 3.12 only.
test_name: "torch_latest"
- python-version: "3.13" # gradio not supported on 3.14 -> test it on 3.13
test_name: "gradio"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
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
"no hf_xet" | "Inference only")
sudo apt update
sudo apt install -y libsndfile1-dev
;;
gradio)
uv pip install "huggingface_hub[gradio] @ ."
;;
torch_latest)
uv pip install "huggingface_hub[torch] @ ."
uv pip install --upgrade torch
;;
"Python 3.10, torch_1.11")
uv pip install "huggingface_hub[torch] @ ."
uv pip install torch~=1.11
;;
esac
# Xet policy (see `xet_mode` fixture in tests/conftest.py):
# - "with hf_xet" job: hf_xet installed (comes with `huggingface_hub[testing]`). Runs `-m 'not no_xet'` => `xet` tests + unmarked tests with Xet.
# - all other jobs: hf_xet uninstalled. Run `-m 'not xet'` => `no_xet` tests + unmarked tests without Xet.
# Unmarked tests therefore run both with and without Xet and must work regardless.
if [[ "${{ matrix.test_name }}" != "with hf_xet" ]]; then
uv pip uninstall hf_xet
fi
# 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 8 --reruns-delay 2 --only-rerun '(OSError|FileNotFoundError|Timeout|HTTPError.*409|HTTPError.*502|HTTPError.*504)'"
case "${{ matrix.test_name }}" in
"Inference only")
# Run inference tests concurrently
PYTEST="$PYTEST ../tests -m 'inference' -n 4"
echo $PYTEST
eval $PYTEST
;;
"no hf_xet")
PYTEST="$PYTEST ../tests -m 'not xet and not inference' -n 4"
echo $PYTEST
eval $PYTEST
;;
gradio)
eval "$PYTEST ../tests/test_webhooks_server.py"
;;
"Python 3.10, torch_1.11" | torch_latest)
eval "$PYTEST ../tests/test_hub_mixin*"
eval "$PYTEST ../tests/test_serialization.py"
;;
"with hf_xet")
# `xet` tests + unmarked tests, all with hf_xet installed.
# Inference tests are excluded: they have their own job and don't depend on Xet.
PYTEST="$PYTEST ../tests -m 'not no_xet and not inference' -n 4"
echo $PYTEST
eval $PYTEST
;;
esac
# Upload code coverage
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
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.
runs-on: windows-latest
timeout-minutes: 30
env:
DISABLE_SYMLINKS_IN_WINDOWS_TESTS: 1
UV_HTTP_TIMEOUT: 600 # max 10min to install deps
GIT_CLONE_PROTECTION_ACTIVE: false # See https://github.com/git-lfs/git-lfs/issues/5754
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.14"]
test_name: ["no hf_xet", "with hf_xet"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
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] @ ."
# Xet policy (see `xet_mode` fixture in tests/conftest.py):
# - "with hf_xet" job: hf_xet installed (comes with `huggingface_hub[testing]`). Runs `-m 'not no_xet'` => `xet` tests + unmarked tests with Xet.
# - all other jobs: hf_xet uninstalled. Run `-m 'not xet'` => `no_xet` tests + unmarked tests without Xet.
# Unmarked tests therefore run both with and without Xet and must work regardless.
if ("${{ matrix.test_name }}" -ne "with hf_xet") {
uv pip uninstall hf_xet
}
# Run tests
- name: Run tests
working-directory: ./src # For code coverage to work
run: |
..\.venv\Scripts\activate
$PYTEST_ARGS = @(
"-m", "pytest",
"-n", "4",
"--cov=./huggingface_hub",
"--cov-report=xml:../coverage.xml",
"--vcr-record=none",
"--reruns", "8",
"--reruns-delay", "2",
"--only-rerun", "(OSError|FileNotFoundError|Timeout|HTTPError.*409|HTTPError.*502|HTTPError.*504)",
"../tests"
)
switch ("${{ matrix.test_name }}") {
"with hf_xet" {
# `xet` tests + unmarked tests, all with hf_xet installed.
# Inference tests already run in "no hf_xet" and don't depend on Xet.
python $PYTEST_ARGS -m "not no_xet and not inference"
}
"no hf_xet" {
python $PYTEST_ARGS -m "not xet"
}
}
# Upload code coverage
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
files: ./coverage.xml
verbose: true