|
1 | 1 | # Contributing to Devito |
2 | | - |
3 | 2 | We welcome third-party contributions, and we would love you to become an active contributor! |
4 | 3 |
|
5 | | -Software contributions are made via GitHub pull requests to https://github.com/devitocodes/devito. If you are planning a large contribution, we encourage you to engage with us frequently to ensure that your effort is well-directed. See below for more details. |
| 4 | +Software contributions are made via GitHub pull requests to https://github.com/devitocodes/devito. |
| 5 | +If you are planning a large contribution, we encourage you to engage with us frequently to ensure that your effort is well-directed. |
| 6 | +See below for more details. |
6 | 7 |
|
7 | | -Devito is distributed under the MIT License, https://github.com/devitocodes/devito/blob/main/LICENSE.md. The act of submitting a pull request or patch (with or without an explicit Signed-off-by tag) will be understood as an affirmation of the following: |
| 8 | +Devito is distributed under the MIT License, https://github.com/devitocodes/devito/blob/main/LICENSE.md. |
| 9 | +The act of submitting a pull request or patch (with or without an explicit Signed-off-by tag) will be understood as an affirmation of the following: |
8 | 10 |
|
9 | 11 | Developer's Certificate of Origin 1.1 |
10 | 12 |
|
@@ -33,47 +35,105 @@ Devito is distributed under the MIT License, https://github.com/devitocodes/devi |
33 | 35 | this project or the open source license(s) involved. |
34 | 36 |
|
35 | 37 | ### Reporting issues |
36 | | - |
37 | 38 | There are several options: |
38 | 39 | * Talk to us. You can join our Slack team via this [link](https://join.slack.com/t/devitocodes/shared_invite/zt-2hgp6891e-jQDcepOWPQwxL5JJegYKSA). Should you have installation issues, or should you bump into something that appears to be a Devito-related bug, do not hesitate to get in touch. We are always keen to help out. |
39 | 40 | * File an issue on [our GitHub page](https://github.com/devitocodes/devito/issues). |
40 | 41 |
|
41 | 42 | ### Making changes |
42 | | - |
43 | 43 | First of all, read of [code of conduct](https://github.com/devitocodes/devito/blob/main/CODE_OF_CONDUCT.md) and make sure you agree with it. |
44 | 44 |
|
45 | 45 | The protocol to propose a patch is: |
46 | 46 | * [Recommended, but not compulsory] Talk to us on Slack about what you're trying to do. There is a great chance we can support you. |
47 | 47 | * As soon as you know what you need to do, [fork](https://help.github.com/articles/fork-a-repo/) Devito. |
48 | 48 | * Create a branch with a suitable name. |
49 | 49 | * Write code following the guidelines below. Commit your changes as small logical units. |
50 | | -* Commit messages must adhere to the format specified [here](https://github.com/devitocodes/devito/wiki/Tags-for-commit-messages-and-PR-titles). We may ask you to rebase the commit history if it looks too messy. |
51 | | -* Write tests to convince us and yourself that what you've done works as expected. Commit them. |
| 50 | +* Commit messages must adhere to the format specified below. We may ask you to rebase the commit history if it looks too messy. |
| 51 | +* Write tests to convince us and yourself that what you have done works as expected and commit them. |
52 | 52 | * Run **the entire test suite**, including the new tests, to make sure that you haven't accidentally broken anything else. |
53 | 53 | * Push everything to your Devito fork. |
54 | 54 | * Submit a Pull Request on our repository. |
55 | 55 | * Wait for us to provide feedback. This may require a few iterations. |
56 | 56 |
|
57 | 57 | Tip, especially for newcomers: prefer short, self-contained Pull Requests over lengthy, impenetrable, and thus difficult to review, ones. |
58 | 58 |
|
59 | | -### Coding guidelines |
| 59 | +#### Commit messages and pull request titles |
| 60 | + |
| 61 | +Your commit message should follow the following format: `tag: Message` |
| 62 | + |
| 63 | +Where `tag` should be one of the following: |
| 64 | +* `arch`: JIT and architecture (basically anything in `devito/arch`) |
| 65 | +* `bench`: Anything related to benchmarking and profiling |
| 66 | +* `ci`: Continuous Integration (CI) |
| 67 | +* `ckp`: Checkpointing related |
| 68 | +* `compiler`: Compilation (`operator`, `ir`, `passes`, `symbolics`, ...) |
| 69 | +* `docs`: Updates or changes to docstrings or the documentation |
| 70 | +* `dsl`: A change related to Devito's Domain Specific Language _Note: `fd`, `differentiable`, etc -- all belong to dsl_ |
| 71 | +* `examples`: Updates or changes to the examples or tutorials |
| 72 | +* `install`: Related to installation (`docker`, `conda`, `pip`, ...) |
| 73 | +* `reqs`: Package dependence updates |
| 74 | +* `sympy`: Changes related to `sympy` |
| 75 | +* `tests`: Updates or changes to the test suite |
| 76 | +* `misc`: tools, docstring/comment updates, linting fixes, etc |
| 77 | + |
| 78 | +`Message` should: |
| 79 | +* Start with an upper case letter |
| 80 | +* Start with a verb in first person |
| 81 | +* Be as short as possible |
| 82 | + |
| 83 | +Examples: |
| 84 | +* `compiler: Fix MPI optimization pass` |
| 85 | +* `install: Update Dockerfiles to new NVidia SDK` |
| 86 | + |
| 87 | +Your Pull Request (PR) should follow a similar format: `tag: Title` |
| 88 | +Additionally, you should add labels to the PR so that it can be categorised and the new changes can be correctly auto-summarised in the changelog. |
| 89 | +Optionally, you may wish to select a reviewer, especially if you have discussed the PR with a member of the Devito team already. |
60 | 90 |
|
61 | | -Some coding rules are "enforced" (and automatically checked by our Continuous Integration systems), some are "strongly recommended", others are "optional" but welcome. |
| 91 | +### Coding guidelines |
62 | 92 |
|
63 | | -* We _enforce_ [PEP8](https://www.python.org/dev/peps/pep-0008/), with a few exceptions, listed [here](https://github.com/devitocodes/devito/blob/main/setup.cfg#L3) |
| 93 | +To ease the process of contributing we use [pre-commit](https://pre-commit.com/), which runs a small set of formatting and linting tests before you create a new commit. |
| 94 | +To use `pre-commit` with Devito simply run: |
| 95 | +```bash |
| 96 | +pip install pre-commit |
| 97 | +pre-commit install |
| 98 | +``` |
| 99 | +Now when you make a commit, a set of pre-defined steps will run to check your contributed code. |
| 100 | + |
| 101 | +These checks will: |
| 102 | +* Trim any trailing whitespace |
| 103 | +* Fix ends of files |
| 104 | +* Check YAML formatting |
| 105 | +* Check for accidentally added large files |
| 106 | +* Sort imports using `isort` * |
| 107 | +* Lint the codebase using `ruff` * |
| 108 | +* Lint the codebase again using `flake8` * |
| 109 | +* Check the code and documentation for typos using `typos` * |
| 110 | +* Lint GitHub Actions workflow files using actionlint * |
| 111 | +* Lint Dockerfiles using hadolint * |
| 112 | + |
| 113 | +(* these checks will not change the edited files, you must manually fix the files or run an automated tool eg: `ruff check --fix`) |
| 114 | + |
| 115 | +If you absolutely must push "dirty" code, `pre-commit` can be circumvented using: |
| 116 | +```bash |
| 117 | +git commit --no-verify -m "misc: WIP very dirty code" |
| 118 | +``` |
| 119 | +However, this will cause CI to fail almost immediately! |
| 120 | + |
| 121 | +Some coding rules are "enforced" (and automatically checked by CI), some are "strongly recommended", others are "optional" but welcome. |
| 122 | + |
| 123 | +* We _enforce_ [PEP8](https://www.python.org/dev/peps/pep-0008/) using `ruff` and `flake8` with [a few exceptions](https://github.com/devitocodes/devito/blob/main/pyproject.toml). |
64 | 124 | * We _enforce_ a maximum line length of 90 characters. |
65 | 125 | * We _enforce_ indentation via 4 spaces. |
66 | | -* We _suggest_ to use ``flake8`` to check the above points locally, before filing a Pull Request. |
67 | | -* We _strongly recommend_ to document any new module, class, routine, ... with [NumPy-like docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html#example-numpy) ("numpydoc"). |
68 | | -* We _strongly recommend_ imports to be at the top of a module, logically grouped and, within each group, to be alphabetically ordered. As an example, condider our [__init__.py](https://github.com/devitocodes/devito/blob/main/devito/__init__.py): the first group is imports from the standard library; then imports from third-party dependencies; finally, imports from devito modules. |
| 126 | +* We _enforce_ imports to be at the top of a module and logically grouped using `isort`. |
| 127 | +* We _strongly recommend_ to document any new module, class, routine, with [numpy docstrings](https://numpydoc.readthedocs.io/en/latest/format.html). |
69 | 128 | * We _strongly recommend_ to follow standard Python coding guidelines: |
70 | 129 | - Use camel caps for class names, e.g. ``class FooBar``. |
71 | | - - Method names must start with a small letter; use underscores to separate words, e.g. ``def _my_meth_...``. |
72 | | - - Private class attributes and methods must start with an underscore. |
73 | | - - Variable names should be explicative (Devito prefers "long and clear" over "short but unclear"). |
| 130 | + - Method names must start with a small letter; use underscores to separate words, eg: `def my_method(...)`. |
| 131 | + - Private class attributes and methods must start with an underscore, eg: `def _my_private_method(...)`. |
| 132 | + - Variable names should be explicative (Devito prefers "long and clear" over "short and FORTRAN like"). |
74 | 133 | - Comment your code, and do not be afraid of being verbose. The first letter must be capitalized. Do not use punctuation (unless the comment consists of multiple sentences). |
75 | 134 | * We _like_ that blank lines are used to logically split blocks of code implementing different (possibly sequential) tasks. |
76 | 135 |
|
77 | 136 | ### Adding tutorials or examples |
78 | 137 |
|
79 | | -We always look forward to extending our [suite of tutorials and examples](https://www.devitoproject.org/devito/tutorials.html) with new Jupyter Notebooks. Even something completely new, such as a new series of tutorials showing your work with Devito, would be a great addition. |
| 138 | +We always look forward to extending our [suite of tutorials and examples](https://www.devitoproject.org/devito/tutorials.html) with new Jupyter Notebooks. |
| 139 | +Even something completely new, such as a new series of tutorials showing your work with Devito, would be a great addition. |
0 commit comments