Code style and formatting

We aim for a consistent and readable coding style. You do not need to worry about styling if you use the right tools we present in the following.

C++

Use clang-format. It can be added to be automatically run on save in your editor / IDE:

The current style is defined in .clang-format.

A pre-commit hook for git checking the code formatting can be found here.

Python

Use black. It can be added to be automatically run on save in your editor / IDE:

black is also run by our pre-commit-hooks. To run manually:

pre-commit run black --all-files

CMake

Use cmake-format. It can be added to be automatically run on save in your editor / IDE:

The current style is defined in .cmake-format.yaml.

On installation make sure to install with the yaml option:

pip install cmakelang[YAML]

Build targets

You can run clang-format and cmake-format on the OGS code base by building the following targets:

Language Shows formatting Applies formatting
C++ clang-format fix-clang-format
CMake cmake-format fix-cmake-format

This article was written by Lars Bilke. If you are missing something or you find an error please let us know. Generated with Hugo 0.79.0. Last revision: March 4, 2021
Commit: [MPL] Registered WaterVapourDensity property 9beabd69f  | Edit this page on