Skip to content

Commit 05cf589

Browse files
authored
Refactor CI jobs. (#699)
* Refactor CI jobs. * Parallel and verbose tests. * Cancel in-progress jobs when new commit is pushed. * Detect coverage better.
1 parent 128dd5a commit 05cf589

File tree

7 files changed

+47
-92
lines changed

7 files changed

+47
-92
lines changed

.codecov.yml

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
comment:
2-
layout: "header, diff, changes, uncovered"
3-
1+
comment: false
42
coverage:
53
status:
64
project:
75
default:
8-
# Total project must not drop by more than 3%
9-
target: auto
10-
threshold: "3%"
6+
# Total project must be 95%
7+
target: '100%'
8+
threshold: '5%'
119

1210
patch:
1311
default:
1412
# Patch coverage must be 92%
15-
target: auto
16-
threshold: "92%"
13+
target: '100%'
14+
threshold: '8%'
1715

1816
precision: 2
1917
round: down
20-
range: 70...98
21-
22-
ignore:
23-
- sparse/tests/
24-
- sparse/_version.py
25-
- ^(?!sparse\/)
26-
27-
codecov:
28-
token: 8de77158-fc37-47be-930c-f98739f9e5bf
18+
range: 80...98

.github/workflows/ci.yml

+26-63
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
defaults:
2+
run:
3+
shell: bash -leo pipefail {0}
4+
5+
concurrency:
6+
group: ${{ github.head_ref }}
7+
cancel-in-progress: true
8+
19
jobs:
210
test:
3-
defaults:
4-
run:
5-
shell: bash -el {0}
611
strategy:
712
matrix:
813
os: [ubuntu-latest]
@@ -18,6 +23,7 @@ jobs:
1823
python: '3.10'
1924
numba_boundscheck: 1
2025
- os: ubuntu-latest
26+
python: '3.10'
2127
pip_opts: "--pre -U"
2228
fail-fast: false
2329
runs-on: ${{ matrix.os }}
@@ -27,65 +33,33 @@ jobs:
2733
steps:
2834
- name: Checkout Repo
2935
uses: actions/checkout@v4
30-
- name: Cache conda
31-
uses: actions/cache@v4
32-
env:
33-
# Increase this value to reset cache if ci/environment.yml has not changed
34-
CACHE_NUMBER: 0
35-
with:
36-
path: ~/conda_pkgs_dir
37-
key:
38-
test-${{ matrix.os }}-conda-py${{ matrix.python }}-${{ env.CACHE_NUMBER }}-${{
39-
hashFiles('ci/environment.yml') }}
40-
- uses: julia-actions/setup-julia@v1
41-
with:
42-
version: '1.10.0'
43-
- uses: conda-incubator/setup-miniconda@v3
36+
- name: Set up Python
37+
uses: actions/setup-python@v5
4438
with:
45-
activate-environment: sparse-dev
46-
allow-softlinks: true
47-
environment-file: ci/environment.yml
4839
python-version: ${{ matrix.python }}
49-
miniforge-version: latest
40+
cache: 'pip'
5041
- name: Install package
5142
run: |
5243
pip install -e .[tests]
5344
pip install ${{ matrix.pip_opts }} numpy numba
5445
- name: Run tests
5546
run: |
56-
SPARSE_BACKEND=Numba pytest --pyargs sparse
57-
SPARSE_BACKEND=Finch pytest --pyargs sparse/tests
47+
SPARSE_BACKEND=Numba pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n 4 -vvv
48+
SPARSE_BACKEND=Finch pytest --pyargs sparse/tests --cov-report=xml:coverage_Finch.xml -n 4 -vvv
5849
- uses: codecov/codecov-action@v4
5950
if: always()
60-
- name: Publish Test Results
61-
uses: EnricoMi/publish-unit-test-result-action/composite@v2
62-
if: always()
6351
with:
64-
files: "**/test-*.xml"
52+
files: ./**/coverage*.xml
6553
docs:
66-
defaults:
67-
run:
68-
shell: bash -el {0}
6954
runs-on: ubuntu-latest
7055
steps:
7156
- name: Checkout Repo
7257
uses: actions/checkout@v4
73-
- name: Cache conda
74-
uses: actions/cache@v4
75-
env:
76-
# Increase this value to reset cache if ci/environment.yml has not changed
77-
CACHE_NUMBER: 0
78-
with:
79-
path: ~/conda_pkgs_dir
80-
key:
81-
docs-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment.yml') }}
82-
- uses: conda-incubator/setup-miniconda@v3
58+
- name: Set up Python
59+
uses: actions/setup-python@v5
8360
with:
84-
activate-environment: sparse-dev
85-
allow-softlinks: true
86-
environment-file: ci/environment.yml
8761
python-version: '3.10'
88-
miniforge-version: latest
62+
cache: 'pip'
8963
- name: Install package
9064
run: |
9165
pip install -e .[docs]
@@ -97,29 +71,15 @@ jobs:
9771
name: Documentation
9872
path: _build/html
9973
benchmarks:
100-
defaults:
101-
run:
102-
shell: bash -el {0}
10374
runs-on: ubuntu-latest
10475
steps:
10576
- name: Checkout Repo
10677
uses: actions/checkout@v4
107-
- name: Cache conda
108-
uses: actions/cache@v4
109-
env:
110-
# Increase this value to reset cache if ci/environment.yml has not changed
111-
CACHE_NUMBER: 0
112-
with:
113-
path: ~/conda_pkgs_dir
114-
key:
115-
benchmarks-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment.yml') }}
116-
- uses: conda-incubator/setup-miniconda@v3
78+
- name: Set up Python
79+
uses: actions/setup-python@v5
11780
with:
118-
activate-environment: sparse-dev
119-
allow-softlinks: true
120-
environment-file: ci/environment.yml
12181
python-version: '3.10'
122-
miniforge-version: latest
82+
cache: 'pip'
12383
- name: Install asv
12484
run: |
12585
pip install asv
@@ -133,11 +93,13 @@ jobs:
13393
- name: Checkout Repo
13494
uses: actions/checkout@v4
13595
- name: Set up Python
136-
uses: actions/setup-python@v5.1.0
96+
uses: actions/setup-python@v5
13797
with:
13898
python-version: '3.11'
99+
cache: 'pip'
139100
- name: Build and install Sparse
140101
run: |
102+
pip install -U setuptools wheel
141103
python -m pip install '.[finch]' scipy
142104
- name: Run examples
143105
run: |
@@ -159,9 +121,10 @@ jobs:
159121
submodules: 'true'
160122
path: 'array-api-tests'
161123
- name: Set up Python
162-
uses: actions/setup-python@v5.1.0
124+
uses: actions/setup-python@v5
163125
with:
164126
python-version: '3.11'
127+
cache: 'pip'
165128
- name: Install build and test dependencies from PyPI
166129
run: |
167130
python -m pip install pytest-xdist -r array-api-tests/requirements.txt

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ sandbox.py
8080

8181
# Version file
8282
sparse/_version.py
83+
84+
# Benchmark Results
85+
results/

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tests = [
3232
"dask[array]",
3333
"pytest>=3.5",
3434
"pytest-cov",
35+
"pytest-xdist",
3536
"pre-commit",
3637
"scipy",
3738
"sparse[finch]",

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
addopts = --cov-report term-missing --cov-report html --cov-report=xml --cov-report=term --cov sparse --cov-config .coveragerc --junitxml=junit/test-results.xml
2+
addopts = --cov-report term-missing --cov-report html --cov-report=term:skip-covered --cov sparse --cov-config .coveragerc --junitxml=junit/test-results.xml
33
filterwarnings =
44
ignore::PendingDeprecationWarning
55
testpaths =

sparse/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ class BackendType(Enum):
1616

1717
if _ENV_VAR_NAME in os.environ:
1818
warnings.warn("Selectable backends feature in `sparse` might change in the future.", FutureWarning, stacklevel=1)
19-
backend_name = os.environ[_ENV_VAR_NAME]
19+
_backend_name = os.environ[_ENV_VAR_NAME]
2020
else:
21-
backend_name = BackendType.Numba.value
21+
_backend_name = BackendType.Numba.value
2222

23-
if backend_name not in {BackendType.Numba.value, BackendType.Finch.value}:
24-
warnings.warn(f"Invalid backend identifier: {backend_name}. Selecting Numba backend.", UserWarning, stacklevel=1)
25-
backend = BackendType.Numba
23+
if _backend_name not in {BackendType.Numba.value, BackendType.Finch.value}:
24+
warnings.warn(f"Invalid backend identifier: {_backend_name}. Selecting Numba backend.", UserWarning, stacklevel=1)
25+
BACKEND = BackendType.Numba
2626
else:
27-
backend = BackendType[backend_name]
27+
BACKEND = BackendType[_backend_name]
2828

29-
del backend_name
29+
del _backend_name
3030

31-
if backend == BackendType.Finch:
31+
if BackendType.Finch == BACKEND:
3232
from sparse.finch_backend import * # noqa: F403
3333
from sparse.finch_backend import __all__
3434
else:

sparse/tests/conftest.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
import sparse
42

53
import pytest
@@ -9,7 +7,7 @@
97

108
@pytest.fixture(scope="session")
119
def backend():
12-
yield sparse.BackendType[os.environ[sparse._ENV_VAR_NAME]]
10+
yield sparse.BACKEND
1311

1412

1513
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)