diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..fa5694710a --- /dev/null +++ b/Makefile @@ -0,0 +1,61 @@ +MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --no-builtin-variables + +# allow overriding the name of the venv directory +VENV_DIR ?= venv + +# make tasks run all commands in a single shell +.ONESHELL: + +# these targets don't produce files: +.PHONY: clean filecheck pytest pytest-nb tests rerun-notebooks precommit-install precommit black pyright + +# remove all caches and the venv +clean: + rm -rf ${VENV_DIR} .pytest_cache *.egg-info .coverage.* + +# run filecheck tests +filecheck: + lit -vv tests/filecheck + lit -vv docs/Toy/examples + +# run pytest tests +pytest: + pytest tests -W error -vv + +# run pytest on notebooks +pytest-nb: + pytest -W error --nbval -vv docs --ignore=docs/mlir_interoperation.ipynb + +# run all tests +tests: pytest pytest-nb filecheck pyright + echo test + +# re-generate the output from all jupyter notebooks in the docs directory +rerun-notebooks: + jupyter nbconvert --ClearMetadataPreprocessor.enabled=True --inplace --to notebook --execute docs/*.ipynb + +# set up all precommit hooks +precommit-install: + pre-commit install + +# run all precommit hooks and apply them +precommit: + pre-commit run --all + +# run pyright on all files in the current git commit +pyright: + pyright $(shell git diff --staged --name-only) + +# run black on all files currently staged +black: + staged_files="$(shell git diff --staged --name-only)" + # run black on all of xdsl if no staged files exist + black $${staged_files:-xdsl} + +# set up the venv with all dependencies for development +venv: requirements-optional.txt requirements.txt + python3 -m venv ${VENV_DIR} + source ${VENV_DIR}/bin/activate + pip install -r requirements-optional.txt -r requirements.txt + pip install -e ".[extras]" diff --git a/README.md b/README.md index 44fa09729f..ec2feb1d0d 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ for users interested in that use case. - [A DSL for defining new IRs](https://xdsl.dev/xdsl/retro/notebooks/?path=irdl.ipynb) - [Connecting xDSL with MLIR](docs/mlir_interoperation.md) +We provide a Makefile containing a lot of common tasks, which might provide +an overview of common actions. + ## xDSL Developer Setup To contribute to the development of xDSL follow the subsequent steps. @@ -67,7 +70,10 @@ To contribute to the development of xDSL follow the subsequent steps. ```bash git clone https://github.com/xdslproject/xdsl.git cd xdsl -pip install --editable ".[extras]" +# set up the venv and install everything +make venv +# activate the venv +source venv/bin/activate ``` ### Testing @@ -81,9 +87,12 @@ pytest # Executes filecheck tests lit tests/filecheck + +# run all tests using makefile +make tests ``` -### Formatting +### Formatting and Typechecking All python code used in xDSL uses [black](https://github.com/psf/black) to format the code in a uniform manner. @@ -92,17 +101,18 @@ To automate the formatting, we use pre-commit hooks from the [pre-commit](https://pypi.org/project/pre-commit/) package. ```bash -# Install pre-commit version in the optional requirement files -pip install --requirement requirements-optional.txt - # Install the pre-commit on your `.git` folder -# Be sure to run this in your virtual environment -pre-commit install - -# Optionally test the hook by running it on all files -pre-commit run --all-files +make precommit-install +# to run the hooks: +make precommit +# alternatively, running black on all staged files: +make black # or simply black $(git diff --staged --name-only) ``` +Furthermore, all python code must run through [pyright](https://github.com/microsoft/pyright) +without errors. Pyright can be run on all staged files through the +makefile using `make pyright`. + ### Discussion You can also join the discussion at our [Zulip chat room](https://xdsl.zulipchat.com), kindly supported by community hosting from [Zulip](https://zulip.com/).