diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..6adee4f --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,9 @@ +# Codecov's statuses report coverage on PRs but never fail them. +coverage: + status: + project: + default: + informational: true + patch: + default: + informational: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d8b457..4f70c9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,30 +102,14 @@ jobs: - name: Build run: | pip install -e . --no-deps - - name: Configure coverage - run: | - # Cython's coverage plugin (see [tool.coverage.run] in pyproject.toml) - # needs coverage's C tracer. Where conda-forge has no compiled build of - # coverage for a Python (3.15t, for now), it installs a pure-Python build - # that lacks the tracer. There, loading the plugin raises ImportError and - # every `coverage run` dies before it runs anything, so run the tests - # directly instead. - if python -c "import Cython.Coverage" 2>/dev/null; then - coverage erase - echo "COV=coverage run -a --branch" >> "$GITHUB_ENV" - else - echo "Cython coverage plugin unusable here; running without coverage" - python -VV - echo "COV=python" >> "$GITHUB_ENV" - fi - name: Test env: - CYTHON_COVERAGE: true PYVER: ${{ matrix.python-version }} run: | pytest -s -k test_print_jit_config - $COV -m pytest - $COV suitesparse_graphblas/tests/test_initialize.py + # Coverage of the Python code; see [tool.coverage.run] in pyproject.toml. + coverage run -a -m pytest + coverage run -a suitesparse_graphblas/tests/test_initialize.py if [[ $PYVER == *t ]]; then # Without a GIL, threads run Python code in parallel, so also run each test in 4 # threads at once, 10 times each, to find races (in psg, GraphBLAS, or a test). @@ -136,5 +120,22 @@ jobs: - name: create_headers.py check if: (! contains(matrix.os, 'windows')) run: | - $COV suitesparse_graphblas/create_headers.py + coverage run -a suitesparse_graphblas/create_headers.py git diff --exit-code # error if anything changed + - name: Coverage report + run: | + coverage report --show-missing + coverage xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + files: coverage.xml + disable_search: true + # The "Coverage report" step wrote coverage.xml, so skip the uploader's own search for + # gcov, Xcode, Swift and coverage.py data (it only logs a warning for each). + plugins: noop + name: ${{ matrix.os }} ${{ matrix.python-version }} + # PRs from forks upload without a token. Pushes to main need the repository + # secret CODECOV_TOKEN. An upload that fails doesn't fail the job. + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false diff --git a/AGENTS.md b/AGENTS.md index cad7326..5609936 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -92,8 +92,9 @@ only be called once per process, so `test_initialize.py` is run as a separate pr docker run --rm -w /tmp psg-test python3 -m suitesparse_graphblas.tests.test_initialize ``` -Coverage runs in CI use `CYTHON_COVERAGE=true` so the Cython `utils.pyx` extension is -recompiled with line tracing. +CI measures coverage of the Python code only, prints it in the "Coverage report" step, and +uploads it to Codecov. It doesn't trace `utils.pyx` (see `[tool.coverage.run]` in +`pyproject.toml`). ## Architecture: how the binding is generated and assembled diff --git a/pyproject.toml b/pyproject.toml index 501d5f3..d53954c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,10 +120,13 @@ line_length = 100 skip_glob = ["*.pxd", "*.pyx"] [tool.coverage.run] +# Python code only. Cython's plugin for `utils.pyx` needs a build with line tracing, and on +# Python 3.14+ coverage's default core (sys.monitoring) can't run it. branch = true source = ["suitesparse_graphblas"] omit = [] -plugins = ["Cython.Coverage"] +# Paths relative to the checkout, so reports from every CI job line up. +relative_files = true [tool.coverage.report] ignore_errors = false