Skip to content

Commit 73c955f

Browse files
ci: Add doctests to CI again. (#767)
Co-authored-by: Willow Ahrens <[email protected]>
1 parent b4ba7c6 commit 73c955f

File tree

20 files changed

+6309
-83
lines changed

20 files changed

+6309
-83
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ jobs:
5050
pip install -e '.[tests]'
5151
- name: Run tests
5252
run: |
53-
SPARSE_BACKEND=Numba pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n auto -vvv
53+
if [ $(python -c 'import numpy as np; print(np.lib.NumpyVersion(np.__version__) >= "2.0.0a1")') = 'True' ]; then
54+
pytest --pyargs sparse --doctest-modules --cov-report=xml:coverage_Numba.xml -n auto -vvv
55+
else
56+
pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n auto -vvv
57+
fi
58+
python -c 'import finch'
5459
SPARSE_BACKEND=Finch pytest --pyargs sparse/tests --cov-report=xml:coverage_Finch.xml -n auto -vvv
5560
SPARSE_BACKEND=MLIR pytest --pyargs sparse/mlir_backend --cov-report=xml:coverage_MLIR.xml -n auto -vvv
5661
- uses: codecov/codecov-action@v5
@@ -126,6 +131,9 @@ jobs:
126131
SPARSE_BACKEND: ${{ matrix.backend }}
127132
run: |
128133
cd ${GITHUB_WORKSPACE}/array-api-tests
134+
if [ "${SPARSE_BACKEND}" = "Finch" ]; then
135+
python -c 'import finch'
136+
fi
129137
pytest array_api_tests -v -c pytest.ini -n auto --max-examples=2 --derandomize --disable-deadline -o xfail_strict=True --xfails-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-xfails.txt --skips-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-skips.txt
130138
131139
on:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ coverage.xml
4949
test_results/
5050
junit/
5151
.hypothesis/
52+
coverage_*.xml
5253

5354
# Translations
5455
*.mo
@@ -85,4 +86,3 @@ docs/examples_ipynb/
8586

8687
# Pixi envs
8788
.pixi/
88-
pixi.lock

ci/environment.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ channels:
55
dependencies:
66
- python
77
- pip
8-
- numpy
9-
- numba
10-
- scipy
11-
- dask
12-
- pytest
13-
- pytest-cov
14-
- pytest-xdist
158
- pip:
169
- finch-tensor>=0.2.2
1710
- finch-mlir>=0.0.2
1811
- pytest-codspeed
12+
- numpy
13+
- numba
14+
- scipy
15+
- dask
16+
- pytest
17+
- pytest-cov
18+
- pytest-xdist

conftest.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import pathlib
2+
3+
import sparse
4+
15
import pytest
26

37

@@ -7,8 +11,18 @@ def add_doctest_modules(doctest_namespace):
711

812
import numpy as np
913

10-
if sparse._BackendType.Numba != sparse._BACKEND:
11-
pass # TODO: pytest.skip() skips Finch and MLIR tests
12-
1314
doctest_namespace["np"] = np
1415
doctest_namespace["sparse"] = sparse
16+
17+
18+
def pytest_ignore_collect(collection_path: pathlib.Path, config: pytest.Config) -> bool | None:
19+
if "numba_backend" in collection_path.parts and sparse._BackendType.Numba != sparse._BACKEND:
20+
return True
21+
22+
if "mlir_backend" in collection_path.parts and sparse._BackendType.MLIR != sparse._BACKEND:
23+
return True
24+
25+
if "finch_backend" in collection_path.parts and sparse._BackendType.Finch != sparse._BACKEND:
26+
return True
27+
28+
return None

pixi.lock

Lines changed: 6199 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,28 @@ numpy = ">=1.17"
1212
[dependencies]
1313
python = ">=3.10,<3.13"
1414

15-
[feature.extras.pypi-dependencies]
15+
[feature.extra.pypi-dependencies]
1616
dask = { version = ">=2024", extras = ["array"] }
1717
scipy = ">=0.19"
1818
scikit-learn = "*"
1919

20-
[feature.docs.pypi-dependencies]
20+
[feature.doc.pypi-dependencies]
2121
mkdocs-material = "*"
2222
mkdocstrings = { version = "*", extras = ["python"] }
2323
mkdocs-gen-files = "*"
2424
mkdocs-literate-nav = "*"
2525
mkdocs-section-index = "*"
2626
mkdocs-jupyter = "*"
2727

28-
[feature.tests.tasks]
29-
test = "pytest --pyargs sparse -n auto"
30-
test-mlir = { cmd = "pytest --pyargs sparse.mlir_backend -v" }
28+
[feature.test.tasks]
29+
test = "pytest -n auto --doctest-modules"
30+
test-mlir = "pytest --pyargs sparse.mlir_backend -v"
3131
test-finch = { cmd = "pytest --pyargs sparse/tests -n auto -v", depends-on = ["precompile"] }
3232

33-
[feature.tests.dependencies]
33+
[feature.test.pypi-dependencies]
3434
pytest = ">=3.5"
3535
pytest-cov = "*"
3636
pytest-xdist = "*"
37-
pre-commit = "*"
3837
pytest-codspeed = "*"
3938

4039
[feature.notebooks.pypi-dependencies]
@@ -51,6 +50,7 @@ matrepr = "*"
5150
precompile = "python -c 'import finch'"
5251

5352
[feature.finch.dependencies]
53+
python = ">=3.10"
5454
juliaup = ">=1.17.10"
5555

5656
[feature.finch.pypi-dependencies]
@@ -63,16 +63,20 @@ SPARSE_BACKEND = "Finch"
6363
[feature.finch.target.osx-arm64.activation.env]
6464
PYTHONFAULTHANDLER = "${HOME}/faulthandler.log"
6565

66+
[feature.mlir.dependencies]
67+
python = ">=3.10"
68+
6669
[feature.mlir.pypi-dependencies]
6770
scipy = ">=0.19"
6871
finch-mlir = ">=0.0.2"
72+
"PyYAML" = "*"
6973

7074
[feature.mlir.activation.env]
7175
SPARSE_BACKEND = "MLIR"
7276

7377
[environments]
74-
tests = ["tests", "extras"]
75-
docs = ["docs", "extras"]
76-
mlir-dev = {features = ["tests", "mlir"], no-default-feature = true}
77-
finch-dev = {features = ["tests", "finch"], no-default-feature = true}
78-
notebooks = ["extras", "mlir", "finch", "notebooks"]
78+
test = ["test", "extra"]
79+
doc = ["doc", "extra"]
80+
mlir-dev = {features = ["test", "mlir"], no-default-feature = true}
81+
finch-dev = {features = ["test", "finch"], no-default-feature = true}
82+
notebooks = ["extra", "mlir", "finch", "notebooks"]

pytest.ini

Lines changed: 1 addition & 1 deletion
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=term:skip-covered --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
33
filterwarnings =
44
ignore::PendingDeprecationWarning
55
testpaths =

sparse/mlir_backend/tests/__init__.py

Whitespace-only changes.

sparse/mlir_backend/tests/test_simple.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import numpy as np
1010
import scipy.sparse as sps
1111

12-
if sparse._BACKEND != sparse._BackendType.MLIR:
13-
pytest.skip("skipping MLIR tests", allow_module_level=True)
14-
1512
parametrize_dtypes = pytest.mark.parametrize(
1613
"dtype",
1714
[

sparse/numba_backend/_common.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,13 +1176,13 @@ def _parse_einsum_input(operands):
11761176
Examples
11771177
--------
11781178
The operand list is simplified to reduce printing:
1179-
>>> np.random.seed(123)
1180-
>>> a = np.random.rand(4, 4)
1181-
>>> b = np.random.rand(4, 4, 4)
1182-
>>> _parse_einsum_input(("...a,...a->...", a, b))
1183-
('za,xza', 'xz', [a, b]) # may vary
1184-
>>> _parse_einsum_input((a, [Ellipsis, 0], b, [Ellipsis, 0]))
1185-
('za,xza', 'xz', [a, b]) # may vary
1179+
>>> rng = np.random.default_rng(42)
1180+
>>> a = rng.random((4, 4))
1181+
>>> b = rng.random((4, 4, 4))
1182+
>>> _parse_einsum_input(("...a,...a->...", a, b)) # doctest: +SKIP
1183+
('za,xza', 'xz', [a, b])
1184+
>>> _parse_einsum_input((a, [Ellipsis, 0], b, [Ellipsis, 0])) # doctest: +SKIP
1185+
('za,xza', 'xz', [a, b])
11861186
"""
11871187

11881188
if len(operands) == 0:
@@ -2061,7 +2061,7 @@ def asarray(obj, /, *, dtype=None, format="coo", copy=False, device=None):
20612061
Examples
20622062
--------
20632063
>>> x = np.eye(8, dtype="i8")
2064-
>>> sparse.asarray(x, format="COO")
2064+
>>> sparse.asarray(x, format="coo")
20652065
<COO: shape=(8, 8), dtype=int64, nnz=8, fill_value=0>
20662066
"""
20672067

0 commit comments

Comments
 (0)