|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Please see [Installation](install.md) for instructions on how to set up your |
| 4 | +development environment. |
| 5 | + |
| 6 | +## Pre-commit hooks |
| 7 | + |
| 8 | +We use `pre-commit` to run the linter checks before you commit your changes. The |
| 9 | +pre-commit hooks are installed as part of the development dependencies. You can |
| 10 | +setup `pre-commit` using the following command: |
| 11 | + |
| 12 | +```bash |
| 13 | +pre-commit install |
| 14 | +``` |
| 15 | + |
| 16 | +This will run the linter checks before you commit your changes. If the checks fail, |
| 17 | +the commit will be rejected. Most of the following sections can be checked by the |
| 18 | +pre-commit hooks. |
| 19 | + |
| 20 | +## Running the tests |
| 21 | + |
| 22 | +We use `pytest` for testing. To run the tests, simply run: |
| 23 | + |
| 24 | +```bash |
| 25 | +pytest |
| 26 | +``` |
| 27 | + |
| 28 | +or for a specific test file with the `-s` flag to show the output of the program: |
| 29 | + |
| 30 | +```bash |
| 31 | +pytest -s tests/test_program.py |
| 32 | +``` |
| 33 | + |
| 34 | +lots of tests contains pretty printing of the IR themselves, so it's useful to see the |
| 35 | +output. |
| 36 | + |
| 37 | +## Code style |
| 38 | + |
| 39 | +We use `black` for code formatting. Besides the linter requirements, we also require |
| 40 | +the following |
| 41 | +good-to-have practices: |
| 42 | + |
| 43 | +### Naming |
| 44 | + |
| 45 | +- try not to use abbreviation as names, unless it's a common abbreviation like `idx` |
| 46 | +for `index` |
| 47 | +- try not create a lot of duplicated name prefix unless the extra information is |
| 48 | +necessary when accessing the class object. |
| 49 | +- try to use `snake_case` for naming variables and functions, and `CamelCase` |
| 50 | +for classes. |
| 51 | + |
| 52 | +### Comments |
| 53 | + |
| 54 | +- try not to write comments, unless it's really necessary. The code should be |
| 55 | +self-explanatory. |
| 56 | +- if you have to write comments, try to use `NOTE:`, `TODO:` `FIXME:` tags to make it |
| 57 | +easier to search for them. |
| 58 | + |
| 59 | +## Documentation |
| 60 | + |
| 61 | +We use `just` for mangaging command line tools and scripts. It should be installed when |
| 62 | +you run `uv sync`. To build the documentation, simply run: |
| 63 | + |
| 64 | +```bash |
| 65 | +just doc |
| 66 | +``` |
| 67 | + |
| 68 | +This will launch a local server to preview the documentation. You can also run |
| 69 | +`just doc-build` to build the documentation without launching the server. |
0 commit comments