Code Formatting
Black Code Formatter
To ensure consistent code formatting in Kaapana, we utilize Black
as a precommit hook. By integrating Black into our workflow, we
maintain a standardized coding style across the project, enhancing readability and maintainability. To write custom Operators, and
extensions or contribute directly to Kaapana, it is suggested to use the Black
Code formatter to format your code.
To get an overview on how the Black code formatter works, you can visit to their Github repository
Installation
Black can be installed by using pip
. It requires Python 3.8+ to run. Run the following command to install via pip
pip install black
Usage
After the installation any python file can be formatted just by running the file path name preceded by the black command.
black /path/to/python/file
To know more about black code style you can visit to their Documentation
Pre-commit hook
Important
Before commiting to the codebase, it is important to install pre-commit hook. This hook check if your files follow black formatting and formats them accordingly if not. To install hook run this in the root of the repository:
pip install pre-commit && pre-commit
Pre-commit script can be found in kaapana/utils/pre-commit
. This script uses the black formatter to detect files that do not follow
the formatting standard while making git commits and prevent the unformatted changes from committing.