IMAS-Python follows The Black Code Style. All Python
files should be formatted with the black
command line tool (this is checked in
:ref:`CI <ci configuration>`).
We use the black autoformatter, so the code style is uniform across all Python files, regardless of the developer that created the code 🙂.
This improves efficiency of developers working on the project:
- Uniform code style makes it easier to read, review and understand other's code.
- Autoformatting code means that developers can save time and mental energy for the important matters.
More reasons for using black can be found on their website.
The easiest way to work with Black is by using an integration with your editor. See https://black.readthedocs.io/en/stable/integrations/editors.html.
You can also pip install black
and run it every time before committing (manually or
with pre-commit hooks):
$ black imas
All done! ✨ 🍰 ✨
66 files left unchanged.
IMAS-Python uses flake8 for linting (static code
analysis). Flake8 should not report any violations when running it on the imas
code base. Again, this is checked in CI.
In some exceptions we can ignore a violation. For example, if a violation cannot be avoided, or fixing it would result in less readable code. This should be avoided as much as possible though.
Because it results in more readable code and can prevent some types of bugs!
Again, the easiest way to work with the flake8
linter is by using an integration
with your editor.
You can also pip install flake8
and run it every time before comitting to check if
your code introduces any violations:
$ flake8 imas