Skip to content

Commit

Permalink
misc (Makefile): Update coverage handling in Makefile (#3617)
Browse files Browse the repository at this point in the history
This PR:

- Moves coverage options from the `Makefile` to `.coveragerc` and adds
the
[`ignore_errors`](https://coverage.readthedocs.io/en/latest/config.html#report-ignore-errors)
option
- Adds a `coverage-clean` target and lets the coverage module to erase
the produced files from a coverage run
- Removes the `TESTS_COVERAGE_FILE` env variable as this is only used in
a target to avoid name collision of coverage files; for all purposes
using the common prefix as enforced by `COVERAGE_FILE` is enough to make
things work uniformly across targets

I would have loved to
[move](https://coverage.readthedocs.io/en/latest/config.html#sample-file)
the `.coveragerc` configuration to `pyproject.toml`, but it seems that
`pytest-cov` does not support it yet.
  • Loading branch information
compor authored Dec 11, 2024
1 parent 6dba951 commit e719c7f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ source =
tests/
docs/



[report]
# Regexes for lines to exclude from consideration
exclude_lines =
Expand All @@ -23,3 +21,5 @@ exclude_lines =
raise ValueError
raise TypeError
raise RuntimeError
format = markdown
ignore_errors = True
50 changes: 33 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ VENV_DIR ?= venv
# use a default prefix for coverage data files
COVERAGE_FILE ?= .coverage

# use different coverage data file per coverage run, otherwise combine complains
TESTS_COVERAGE_FILE = ${COVERAGE_FILE}.tests

# default lit options
LIT_OPTIONS ?= -v --order=smart

# make tasks run all commands in a single shell
.ONESHELL:

# these targets don't produce files:
.PHONY: ${VENV_DIR}/ venv clean clean-caches filecheck pytest pytest-nb tests-toy tests
.PHONY: rerun-notebooks precommit-install precommit pyright tests-marimo
.PHONY: coverage coverage-tests coverage-filecheck-tests
.PHONY: coverage-report-html coverage-report-md

# set up the venv with all dependencies for development
.PHONY: ${VENV_DIR}/
${VENV_DIR}/: requirements.txt
python3 -m venv ${VENV_DIR}
. ${VENV_DIR}/bin/activate
Expand All @@ -32,33 +24,39 @@ ${VENV_DIR}/: requirements.txt
venv: ${VENV_DIR}/

# remove all caches
clean-caches:
rm -rf .pytest_cache *.egg-info .coverage.*
find . -type f -name "*.cover" -delete
.PHONY: clean-caches
clean-caches: coverage-clean
rm -rf .pytest_cache *.egg-info

# remove all caches and the venv
.PHONY: clean
clean: clean-caches
rm -rf ${VENV_DIR}

# run filecheck tests
.PHONY: filecheck
filecheck:
lit $(LIT_OPTIONS) tests/filecheck

# run pytest tests
.PHONY: pytest
pytest:
pytest tests -W error -vv

# run pytest on notebooks
.PHONY: pytest-nb
pytest-nb:
pytest -W error --nbval -vv docs \
--ignore=docs/mlir_interoperation.ipynb \
--ignore=docs/Toy \
--nbval-current-env

# run tests for Toy tutorial
.PHONY: filecheck-toy
filecheck-toy:
lit $(LIT_OPTIONS) docs/Toy/examples

.PHONY: pytest-toy
pytest-toy:
pytest docs/Toy/toy/tests

Expand All @@ -70,8 +68,10 @@ pytest-toy-nb:
echo "riscemu is not installed, skipping tests."; \
fi

.PHONY: tests-toy
tests-toy: filecheck-toy pytest-toy pytest-toy-nb

.PHONY: tests-marimo
tests-marimo:
@for file in docs/marimo/*.py; do \
echo "Running $$file"; \
Expand Down Expand Up @@ -105,14 +105,17 @@ tests-marimo-onnx:
fi

# run all tests
.PHONY: tests-functional
tests-functional: pytest tests-toy filecheck pytest-nb tests-marimo tests-marimo-onnx
@echo All functional tests done.

# run all tests
.PHONY: tests
tests: tests-functional pyright
@echo All tests done.

# re-generate the output from all jupyter notebooks in the docs directory
.PHONY: rerun-notebooks
rerun-notebooks:
jupyter nbconvert \
--ClearMetadataPreprocessor.enabled=True \
Expand All @@ -121,35 +124,48 @@ rerun-notebooks:
--execute docs/*.ipynb docs/Toy/*.ipynb

# set up all precommit hooks
.PHONY: precommit-install
precommit-install:
pre-commit install

# run all precommit hooks and apply them
.PHONY: precommit
precommit:
pre-commit run --all

# run pyright on all files in the current git commit
# make sure to generate the python typing stubs before running pyright
.PHONY: pyright
pyright:
# We make sure to generate the python typing stubs before running pyright
xdsl-stubgen
pyright $(shell git diff --staged --name-only -- '*.py')

# run coverage over all tests and combine data files
.PHONY: coverage
coverage: coverage-tests coverage-filecheck-tests
coverage combine --append

# run coverage over tests
# use different coverage data file per coverage run, otherwise combine complains
.PHONY: coverage-tests
coverage-tests:
COVERAGE_FILE=${TESTS_COVERAGE_FILE} pytest -W error --cov --cov-config=.coveragerc
COVERAGE_FILE="${COVERAGE_FILE}.$@" pytest -W error --cov --cov-config=.coveragerc

# run coverage over filecheck tests
.PHONY: coverage-filecheck-tests
coverage-filecheck-tests:
lit $(LIT_OPTIONS) tests/filecheck/ -DCOVERAGE

# generate html coverage report
.PHONY: coverage-report-html
coverage-report-html:
coverage html

# generate markdown coverage report
coverage-report-md:
coverage report --format=markdown
# generate coverage report
.PHONY: coverage-report
coverage-report:
coverage report

.PHONY: coverage-clean
coverage-clean:
coverage erase

0 comments on commit e719c7f

Please sign in to comment.