cp2k/tools/precommit
2022-07-08 11:33:48 +02:00
..
check_file_properties.py Remove version number from development branch 2022-07-08 11:33:48 +02:00
cloudbuild.yaml precommit: Fix Dockerfile and cloudbuild.yaml 2020-08-25 14:53:00 +02:00
deploy.sh Toolchain: use MKL's ScaLAPACK and FFTW (#1537) 2021-05-26 16:28:21 +02:00
Dockerfile precommit: Upgrade to Ubuntu 22.04 2022-05-11 14:17:18 +02:00
format_makefile.py precommit: Add simple Makefile formatter 2022-02-07 10:02:03 +01:00
install_requirements.sh Docker: User build context for precommit test 2022-03-11 17:12:55 +01:00
package-lock.json Bump minimist from 1.2.5 to 1.2.6 in /tools/precommit 2022-03-28 10:55:23 +02:00
package.json precommit: Freeze tool versions 2020-08-28 15:29:27 +02:00
precommit.py Makefile: Use .cu extension also for HIP kernels 2022-03-20 19:41:51 +01:00
precommit_server.py precommit: Add cmake-format 2021-11-29 19:41:30 +01:00
README.md precommit: Add shfmt to format shell scripts 2021-02-18 00:33:20 +01:00
requirements.txt precommit: Upgrade to Ubuntu 22.04 2022-05-11 14:17:18 +02: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.