Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: Add makefile and update readme #1173

Merged
merged 10 commits into from
Jun 22, 2023
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
AntonLydike marked this conversation as resolved.
Show resolved Hide resolved
lit -vv docs/Toy/examples

# run pytest tests
pytest:
AntonLydike marked this conversation as resolved.
Show resolved Hide resolved
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}
Comment on lines +51 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also runs black on files that are not Python files. This is not an issue in the pyright case above, since pyright realises that and still works, but black complains.

Not sure we really care, just another minor inconvenience

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not cared so far, maybe we can fix that in an upcoming PR?


# 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]"
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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/).