|
1 | | -# Contributing to aieng-template |
| 1 | +# Contributing to MIDST Toolkit |
2 | 2 |
|
3 | | -Thanks for your interest in contributing to the aieng-template! |
| 3 | +Thanks for your interest in contributing to the MIDST Toolkit! |
4 | 4 |
|
5 | 5 | To submit PRs, please fill out the PR template along with the PR. If the PR |
6 | 6 | fixes an issue, don't forget to link the PR to the issue! |
7 | 7 |
|
8 | 8 | ## Pre-commit hooks |
9 | 9 |
|
10 | | -Once the python virtual environment is setup, you can run pre-commit hooks using: |
| 10 | +```bash |
| 11 | +pre-commit install |
| 12 | +``` |
11 | 13 |
|
| 14 | +To run the checks, some of which will automatically re-format your code to fit the standards, you can run |
12 | 15 | ```bash |
13 | 16 | pre-commit run --all-files |
14 | 17 | ``` |
| 18 | +It can also be run on a subset of files by omitting the `--all-files` option and pointing to specific files or folders. |
| 19 | + |
| 20 | +If you're using VS Code for development, pre-commit should setup git hooks that execute the pre-commit checks each |
| 21 | +time you check code into your branch through the integrated source-control as well. This will ensure that each of your |
| 22 | +commits conform to the desired format before they are run remotely and without needing to remember to run the checks |
| 23 | +before pushing to a remote. If this isn't done automatically, you can find instructions for setting up these hooks |
| 24 | +manually online. |
15 | 25 |
|
16 | 26 | ## Coding guidelines |
17 | 27 |
|
18 | 28 | For code style, we recommend the [PEP 8 style guide](https://peps.python.org/pep-0008/). |
19 | 29 |
|
20 | | -For docstrings we use [numpy format](https://numpydoc.readthedocs.io/en/latest/format.html). |
| 30 | +For code documentation, we try to adhere to the Google docstring style |
| 31 | +(See [here](https://google.github.io/styleguide/pyguide.html), Section: Comments and Doc-strings). The implementation |
| 32 | +of an extensive set of comments for the code in this repository is a work-in-progress. However, we are continuing to |
| 33 | +work towards a better commented state for the code. For development, as stated in the style guide, |
| 34 | +__any non-trivial or non-obvious methods added to the library should have a doc string__. For our library this |
| 35 | +applies only to code added to the main library in `midst_toolkit`. Examples, research code, and tests need not |
| 36 | +incorporate the strict rules of documentation, though clarifying and helpful comments in that code is also |
| 37 | +__strongly encouraged__. |
| 38 | + |
| 39 | +> [!NOTE] |
| 40 | +> As a matter of convention choice, classes are documented through their `__init__` functions rather than at the |
| 41 | +> "class" level. |
| 42 | +
|
| 43 | +If you are using VS Code a very helpful integration is available to facilitate the creation of properly formatted |
| 44 | +doc-strings called autoDocstring [VS Code Page](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring) |
| 45 | +and [Documentation](https://github.com/NilsJPWerner/autoDocstring). This tool will automatically generate a docstring |
| 46 | +template when starting a docstring with triple quotation marks (`"""`). To get the correct format, the following |
| 47 | +settings should be prescribed in your VS Code settings JSON: |
| 48 | + |
| 49 | +```json |
| 50 | +{ |
| 51 | + "autoDocstring.customTemplatePath": "", |
| 52 | + "autoDocstring.docstringFormat": "google", |
| 53 | + "autoDocstring.generateDocstringOnEnter": true, |
| 54 | + "autoDocstring.guessTypes": true, |
| 55 | + "autoDocstring.includeExtendedSummary": false, |
| 56 | + "autoDocstring.includeName": false, |
| 57 | + "autoDocstring.logLevel": "Info", |
| 58 | + "autoDocstring.quoteStyle": "\"\"\"", |
| 59 | + "autoDocstring.startOnNewLine": true |
| 60 | +} |
| 61 | +``` |
21 | 62 |
|
22 | 63 | We use [ruff](https://docs.astral.sh/ruff/) for code formatting and static code |
23 | | -analysis. Ruff checks various rules including [flake8](https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-flake8). The pre-commit hooks show errors which you need to fix before submitting a PR. |
| 64 | +analysis. Ruff checks various rules including |
| 65 | +[flake8](https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-flake8). The pre-commit hooks show errors which |
| 66 | +you need to fix before submitting a PR. |
24 | 67 |
|
25 | 68 | Last but not the least, we use type hints in our code which is then checked using |
26 | 69 | [mypy](https://mypy.readthedocs.io/en/stable/). |
| 70 | + |
| 71 | +**Note**: We use the modern mypy types introduced in Python 3.10 and above. See some of the |
| 72 | +[documentation here](https://mypy.readthedocs.io/en/stable/builtin_types.html) |
| 73 | + |
| 74 | +For example, this means that we're using `list[str], tuple[int, int], tuple[int, ...], dict[str, int], type[C]` as |
| 75 | +built-in types and `Iterable[int], Sequence[bool], Mapping[str, int], Callable[[...], ...]` from collections.abc |
| 76 | +(as now recommended by mypy). |
| 77 | + |
| 78 | +We also use the new Optional and Union specification style: |
| 79 | +```python |
| 80 | +Optional[typing_stuff] -> typing_stuff | None |
| 81 | +Union[typing1, typing2] -> typing1 | typing2 |
| 82 | +Optional[Union[typing1, typing2]] -> typing1 | typing2 | None |
| 83 | +``` |
| 84 | + |
| 85 | +There is a custom script that enforces this style. It is not infallible. So if there is an issue with it please fix or |
| 86 | +report it to us. |
0 commit comments