Code style#
Consistency makes code more readable and easier for collaborators to jump in. SimPEG uses Black to autoformat its codebase, and flake8 and Ruff to lint its code and enforce style rules. Black can automatically format SimPEG’s codebase to ensure it complies with Black code style. flake8 and Ruff perform style checks, raise warnings on code that could lead towards bugs, performs checks on consistent documentation formatting, and identifies poor coding practices.
Hint
If you configure pre-commit, it will automatically run Black, flake8, and Ruff on every commit.
One can manually run Black, flake8, and Ruff anytime.
Run
blackon SimPEG directories that contain Python source files:black .Run
flake8on the whole project with:flake8
Run
ruffon the whole project with:ruff check
Important
Following code style rules can be challenging for new contributors. These rules are meant to ease the development process, not to generate an obstacle to contribute. Please, don’t hesistate to ask for help if your contribution raises some flake8 errors. And feel free to push code that don’t follow our code style 100% in Pull Requests. Other developers will be there to help you solve them.
Note
SimPEG is currently not PEP 8 compliant and is not following all flake8 rules, but we are working towards it and would appreciate contributions that do too!