-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathMakefile
175 lines (140 loc) · 4.41 KB
/
Makefile
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
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
# use a default prefix for coverage data files
COVERAGE_FILE ?= .coverage
# allow overriding the name of the venv directory
VENV_DIR ?= .venv
# use activated venv if any
export UV_PROJECT_ENVIRONMENT=$(if $(VIRTUAL_ENV),$(VIRTUAL_ENV),$(VENV_DIR))
# allow overriding which extras are installed
VENV_EXTRAS ?= --extra gui --extra dev --extra jax --extra riscv --extra docs
# default lit options
LIT_OPTIONS ?= -v --order=smart
# make tasks run all commands in a single shell
.ONESHELL:
.PHONY: uv-installed
uv-installed:
@command -v uv &> /dev/null ||\
(echo "UV doesn't seem to be installed, try the following instructions:" &&\
echo "https://docs.astral.sh/uv/getting-started/installation/" && false)
# set up the venv with all dependencies for development
.PHONY: ${VENV_DIR}/
${VENV_DIR}/: uv-installed
uv sync ${VENV_EXTRAS}
@if [ ! -z "$(XDSL_MLIR_OPT_PATH)" ]; then \
ln -sf $(XDSL_MLIR_OPT_PATH) ${VENV_DIR}/bin/mlir-opt; \
fi
# make sure `make venv` also works correctly
.PHONY: venv
venv: ${VENV_DIR}/
# remove all caches
.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: uv-installed
uv run lit $(LIT_OPTIONS) tests/filecheck
# run pytest tests
.PHONY: pytest
pytest: uv-installed
uv run pytest tests -W error -vv
# run pytest on notebooks
.PHONY: pytest-nb
pytest-nb: uv-installed
uv run pytest -W error --nbval -vv docs \
--ignore=docs/mlir_interoperation.ipynb \
--ignore=docs/Toy \
--ignore-glob=**/__marimo__/*.ipynb \
--nbval-current-env
# run tests for Toy tutorial
.PHONY: filecheck-toy
filecheck-toy: uv-installed
uv run lit $(LIT_OPTIONS) docs/Toy/examples
.PHONY: pytest-toy
pytest-toy: uv-installed
uv run pytest docs/Toy/toy/tests
.PHONY: pytest-toy-nb
pytest-toy-nb:
@if uv run python -c "import riscemu" > /dev/null 2>&1; then \
uv run pytest -W error --nbval -vv docs/Toy --nbval-current-env; \
else \
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: uv-installed
@for file in docs/marimo/*.py; do \
echo "Running $$file"; \
error_message=$$(uv run python3 "$$file" 2>&1) || { \
echo "Error running $$file"; \
echo "$$error_message"; \
exit 1; \
}; \
done
@echo "All marimo tests passed successfully."
# run all tests
.PHONY: tests-functional
tests-functional: pytest tests-toy filecheck pytest-nb tests-marimo
@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: uv-installed
uv run jupyter nbconvert \
--ClearMetadataPreprocessor.enabled=True \
--inplace \
--to notebook \
--execute docs/*.ipynb docs/Toy/*.ipynb
# set up all precommit hooks
.PHONY: precommit-install
precommit-install: uv-installed
uv run pre-commit install
# run all precommit hooks and apply them
.PHONY: precommit
precommit: uv-installed
uv run 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: uv-installed
uv run xdsl-stubgen
uv run 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
uv run coverage combine --append
# use different coverage data file per coverage run, otherwise combine complains
.PHONY: coverage-tests
coverage-tests: uv-installed
COVERAGE_FILE="${COVERAGE_FILE}.$@" uv run pytest -W error --cov --cov-config=.coveragerc
# run coverage over filecheck tests
.PHONY: coverage-filecheck-tests
coverage-filecheck-tests: uv-installed
uv run lit $(LIT_OPTIONS) tests/filecheck/ -DCOVERAGE
# generate html coverage report
.PHONY: coverage-report-html
coverage-report-html: uv-installed
uv run coverage html
# generate coverage report
.PHONY: coverage-report
coverage-report: uv-installed
uv run coverage report
.PHONY: coverage-clean
coverage-clean: uv-installed
uv run coverage erase
# docs
.PHONY: docs-serve
docs-serve: uv-installed
uv run mkdocs serve
.PHONY: docs-build
docs-build: uv-installed
uv run mkdocs build