Repository navigation
210 lines (201 loc) · 7.12 KB
/
Copy pathrun_tests.yml
File metadata and controls
210 lines (201 loc) · 7.12 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
name: tests
on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- master
paths:
- "shap/**"
- "tests/**"
- "data/**"
- "javascript/**" # Include JS changes that affect bundle.js
- ".github/workflows/run_tests.yml"
- "pyproject.toml"
- "CMakeLists.txt"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Cancel only PR intermediate builds
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
# we need this test since we run into 403 errors on MacOS, see GH #4179
prepare_data:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies for dataset download
run: |
uv pip install --system . --group download-datasets
- name: Pre-download datasets
run: python -P tests/datasets_to_cache.py
- name: Create unified cache directory
run: |
mkdir -p /tmp/test_data_cache
cp -r ~/scikit_learn_data /tmp/test_data_cache/ || true
cp -r shap/cached_data /tmp/test_data_cache/ || true
ls -la /tmp/test_data_cache/
- name: Upload cached datasets
uses: actions/upload-artifact@v4
with:
name: test-data-cache
path: /tmp/test_data_cache
retention-days: 1
run_tests:
needs: prepare_data
strategy:
matrix:
os: ["ubuntu-latest"]
# The total number of matrix jobs should match codecov.yml `after_n_builds`.
python-version: ["3.12",
"3.13",
"3.14"
]
extras: ["test"]
include:
# Test on windows/mac, just one job each
- os: windows-latest
python-version: "3.13"
extras: "test"
- os: macos-latest
python-version: "3.13"
extras: "test"
# Run tests with only the core dependencies, to ensure we
# cover the latest version of numpy/pandas. See GH dsgibbons#46
- os: ubuntu-latest
python-version: "3.13"
extras: "test-core"
fail-fast: false
runs-on: ${{ matrix.os }}
timeout-minutes: 40
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
js:
- 'javascript/**'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Build JavaScript bundle if JS files have changed
- name: Set up Node.js
if: steps.filter.outputs.js == 'true'
uses: actions/setup-node@v3
with:
node-version: lts/Hydrogen
- name: Build JavaScript bundle conditionally
if: steps.filter.outputs.js == 'true'
shell: bash
run: |
cd javascript
npm ci
npm run build
cp build/bundle.js ../shap/plots/resources/bundle.js
- name: Install libomp (macOS)
if: runner.os == 'macOS'
run: |
brew install libomp
# Set DYLD_LIBRARY_PATH to avoid OpenMP conflicts, see https://github.com/unit8co/darts/pull/3050
_libomp_path=$(brew --prefix libomp 2>/dev/null)/lib
echo "DYLD_LIBRARY_PATH=$_libomp_path:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
unset _libomp_path
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
# Do regular install NOT editable install: see GH #3020
run: |
uv pip install --system . --group ${{matrix.extras}} --group plots
- name: Download pre-cached datasets
uses: actions/download-artifact@v4
with:
name: test-data-cache
path: /tmp/test_data_cache
- name: Restore datasets to correct locations
shell: bash
run: |
# Restore sklearn data
if [ "$RUNNER_OS" == "Windows" ]; then
cp -r /d/tmp/test_data_cache/scikit_learn_data ~/scikit_learn_data || true
else
cp -r /tmp/test_data_cache/scikit_learn_data ~/scikit_learn_data || true
fi
# Restore shap cached data to the installed package location
SHAP_CACHE_DIR=$(python -P -c "import shap, os; print(os.path.join(os.path.dirname(shap.__file__), 'cached_data'))")
mkdir -p "$SHAP_CACHE_DIR"
if [ "$RUNNER_OS" == "Windows" ]; then
cp -r /d/tmp/test_data_cache/cached_data/* "$SHAP_CACHE_DIR/" 2>/dev/null || true
else
cp -r /tmp/test_data_cache/cached_data/* "$SHAP_CACHE_DIR/" 2>/dev/null || true
fi
echo "Sklearn data:"
ls -la ~/scikit_learn_data/ 2>/dev/null || echo "No sklearn data"
echo "Shap cache data:"
ls -la "$SHAP_CACHE_DIR" 2>/dev/null || echo "No shap data"
- name: Test with pytest
# Ensure we avoid adding current working directory to sys.path:
# - Use "pytest" over "python -m pytest"
# - Use "append" import mode rather than default "prepend"
run: >
pytest --durations=20
--cov --cov-report=xml
--mpl-generate-summary=html --mpl-results-path=./mpl-results
--import-mode=append
- name: Upload mpl test report
if: failure()
uses: actions/upload-artifact@v4
with:
name: mpl-results-${{ matrix.python-version }}-${{ runner.os }}-${{ matrix.extras }}
path: mpl-results/
if-no-files-found: ignore
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
test_oldest_supported_numpy:
# Package is built with numpy 2.X
# This job is recommended by https://numpy.org/doc/stable/dev/depending_on_numpy.html#numpy-2-0-specific-advice
# The "oldest supported numpy" is determined by SPEC 0:
# https://scientific-python.org/specs/spec-0000/
name: run tests (oldest supported numpy)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv pip install --system numpy==2.0 . --group test-core --group plots
- name: Test with pytest
run: pytest --durations=20 --import-mode=append
run_mypy:
# Run mypy on the latest Python version
name: run mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv pip install --system . --group test-core
- name: Run mypy
run: mypy shap tests