- Clone this repo into a Python
3.9
virtual environment. pip install -e ".[dev]"
pre-commit install
- If using PyCharm, set the test runner as
pytest
and marksrc
as a sources root.
Optionally setup PyCharm linting shortcut:
- Preferences -> Tools -> External Tools > + (add new entry)
Name: lint
Description: Format the current file
Program: $PyInterpreterDirectory$/pre-commit
Arguments: run --files=$FilePath$Working
Working Directory: $ProjectFileDir$
- Preferences -> Keymap -> External Tools -> lint,
Assign the keyboard shortcut
Option-cmd-l
- The pre-commit hook should catch linting errors
- run
mypy src
to check for type errors - run
pytest tests/unit
to run unit tests
Note: while there is a mypy
hook for pre-commit,
I found it too buggy to be worthwhile, so I just run mypy manually.
- When a pull request is created a set of automated tests are run. If any of those fail they will need to be fixed before any of the maintainers can review the PR. The checks here include:
- Unit tests
- Linting
- Type checks
- PR title correctness
- If all automated tests have succeeded, the change is reviewed by one of the maintainers, assesing the need for the change and adding suggestions.
- Maintainer kicks off integration tests. Those can only be submitted by the maintainers in order to avoid an abuse of resources.
- If the integration tests pass and the change looks good to the maintainer they approve it.
- Merge into the main branch. Only the maintainers have the ability to merge a PR. They will do so at the earliest convenience, with regards to the impact of the change as well as the release planning.
Use the Google format for docstrings. Do not include types or an indication of "optional" in docstrings. Those should be captured in the function signature as type annotations; no need to repeat them in the docstring.
Public methods and functions should have docstrings. One-liners are fine for simple methods and functions.
For PyCharm Users:
- Tools > Python Integrated Tools > Docstring Format: "Google"
- Editor > General > Smart Keys > Check "Insert documentation comment stub"
- Editor > General > Smart Keys > Python > Uncheck "Insert type placeholders..."
In general, prefer from typing import Optional, ...
, and not import typing
.
In general, organize class internals in this order:
- class attributes
__init__()
- classmethods (
@classmethod
)- alternative constructors first
- other classmethods next
- properties (
@property
) - remaining methods
- put more important / broadly applicable functions first
- group related functions together to minimize scrolling
Read more about this philosophy here.
If classes start to approach 1k lines, consider breaking them into parts, possibly like this.
Consider adopting: