cp2k/tools/precommit
Matthias Krack 4180bf53f7 Add timeout flag and allow for flags using make_pretty.sh
Using "make_pretty.sh -j 1 -t 2" is often more likely to work than increasing the (hardwired) timeout value
2026-02-27 20:42:16 +01:00
..
fprettify Move prettify into precommit folder and inline fprettify submodule 2024-08-04 12:45:16 +02:00
prettify_cp2k precommit: Update Python packages and re-format 2026-02-24 17:11:52 +01:00
check_file_properties.py ELPA: introduced ELPA_ONE_STAGE and revised ELPA_QR/UNSAFE 2026-01-21 13:33:40 +01:00
clang_format_wrapper.sh Precommit: Add work-around for clang-format's excessive memory usage 2025-03-01 12:06:30 +01:00
cloudbuild.yaml precommit: Migration Docker image to artifact registry 2022-11-06 16:15:27 +01:00
deploy.sh Toolchain: use MKL's ScaLAPACK and FFTW (#1537) 2021-05-26 16:28:21 +02:00
Dockerfile precommit: Add Fortitude linter 2025-11-05 16:52:17 +01:00
format_fortran.py precommit: Update Python packages and re-format 2026-02-24 17:11:52 +01:00
format_fortran_test.py Move prettify into precommit folder and inline fprettify submodule 2024-08-04 12:45:16 +02:00
format_input_file.py Indent @-directives and set them upercase 2024-01-16 16:23:54 +01:00
format_makefile.py Reformat with black 23.3.0 2023-05-02 12:31:58 +02:00
fortitude.toml Enable Fortitude rule missing-exit-or-cycle-label 2025-11-07 16:48:14 +01:00
install_requirements.sh precommit: Update Python packages and re-format 2026-02-24 17:11:52 +01:00
precommit.py Add timeout flag and allow for flags using make_pretty.sh 2026-02-27 20:42:16 +01:00
precommit_server.py precommit: Increase timeout for shellcheck to 30s (#4887) 2026-02-27 16:14:28 +01:00
README.md DBM: introduced OpenCL support (#3321) 2024-03-15 16:41:35 +01:00
requirements.txt precommit: Update Python packages and re-format 2026-02-24 17:11:52 +01:00
start_local_server.sh precommit: Introduce new server-based framework 2020-08-21 00:18:56 +02:00

CP2K Precommit

The precommit system consists of the following tools that analyze and format the source code:

In contrast to the CP2K-CI these tools process each file individually, which makes them much more lightweight.

Install Git Hook

The precommit.py script can be readily installed as a git hook:

ln -fs ../../tools/precommit/precommit.py .git/hooks/pre-commit

Server

Many of the tools listed above require more than just Python. To avoid their tedious installation a remote server is used by default. It is hosted at https://precommit.cp2k.org via Cloud Run.

The same server can also be started locally when Docker is available:

./start_local_server.sh

The server can also be installed without Docker by following the steps in the Dockerfile.

Once the server is up and running it can be used like this:

$ export CP2K_PRECOMMIT_SERVER="http://127.0.0.1:8080"
$ ./precommit.py
Running precommit checks using 8 workers and server: http://127.0.0.1:8080
Searching for files...

Backups and Cache

Before precommit runs an external tool on a file it create a backup copy in obj/precommit. If the tool leaves the file unmodified then the backup copy is remove afterwards. If the tool modifies the file and precommit was invoked without --allow-modifications then the backup copy is used to restore the file's original content.

After a successful tool run the file's timestamp is recorded in obj/precommit/cache.json and precommit will skip it in future unless it's invoked with --no-cache.