|
| 1 | +# ABACUS Precommit |
| 2 | + |
| 3 | +This is a CP2K-style precommit system adapted for ABACUS. The local driver is |
| 4 | +`tools/precommit/precommit.py`; the formatting tools are provided by a small |
| 5 | +Flask/gunicorn precommit server. |
| 6 | + |
| 7 | +The design intentionally follows CP2K's usage model: |
| 8 | + |
| 9 | +- one local driver script; |
| 10 | +- `obj/precommit/cache.json` mtime cache; |
| 11 | +- file-level processing; |
| 12 | +- local backup before each tool modifies a file; |
| 13 | +- default check-only mode; |
| 14 | +- `--allow-modifications` to keep formatter changes; |
| 15 | +- remote or local Docker server for external tools. |
| 16 | + |
| 17 | +## Install Git hook |
| 18 | + |
| 19 | +From the ABACUS repository root: |
| 20 | + |
| 21 | +```bash |
| 22 | +ln -fs ../../tools/precommit/precommit.py .git/hooks/pre-commit |
| 23 | +``` |
| 24 | + |
| 25 | +## Run checks |
| 26 | + |
| 27 | +```bash |
| 28 | +./tools/precommit/precommit.py |
| 29 | +``` |
| 30 | + |
| 31 | +The default mode does not modify source files. If a formatter would change a |
| 32 | +file, the driver restores the original content and prints a unified diff. |
| 33 | + |
| 34 | +## Apply modifications |
| 35 | + |
| 36 | +```bash |
| 37 | +./tools/precommit/precommit.py --allow-modifications |
| 38 | +``` |
| 39 | + |
| 40 | +Short option: |
| 41 | + |
| 42 | +```bash |
| 43 | +./tools/precommit/precommit.py -m |
| 44 | +``` |
| 45 | + |
| 46 | +## Ignore cache |
| 47 | + |
| 48 | +```bash |
| 49 | +./tools/precommit/precommit.py --no-cache |
| 50 | +``` |
| 51 | + |
| 52 | +Short option: |
| 53 | + |
| 54 | +```bash |
| 55 | +./tools/precommit/precommit.py -a |
| 56 | +``` |
| 57 | + |
| 58 | +## Process selected files |
| 59 | + |
| 60 | +```bash |
| 61 | +./tools/precommit/precommit.py source/module/foo.cpp source/module/foo.h |
| 62 | +``` |
| 63 | + |
| 64 | +## Local server |
| 65 | + |
| 66 | +Until an ABACUS precommit server is deployed, run the server locally with Docker: |
| 67 | + |
| 68 | +```bash |
| 69 | +cd tools/precommit |
| 70 | +./start_local_server.sh |
| 71 | +``` |
| 72 | + |
| 73 | +Then, in another terminal from the repository root: |
| 74 | + |
| 75 | +```bash |
| 76 | +export ABACUS_PRECOMMIT_SERVER="http://127.0.0.1:8080" |
| 77 | +./tools/precommit/precommit.py |
| 78 | +``` |
| 79 | + |
| 80 | +## Tools |
| 81 | + |
| 82 | +The first ABACUS version keeps CP2K's lightweight file-level model and maps it to |
| 83 | +ABACUS' C++-first source tree: |
| 84 | + |
| 85 | +- C/C++/CUDA/HIP/OpenCL: `clang-format` |
| 86 | +- Python: `ast.parse` + `black` |
| 87 | +- Shell: `shfmt` + `shellcheck` |
| 88 | +- Markdown: `mdformat --wrap=100` |
| 89 | +- CMake: `cmake-format -i` |
| 90 | +- Makefile: local `format_makefile.py` |
| 91 | +- all files: local `check_file_properties.py` |
| 92 | + |
| 93 | +`clang-tidy` and `compile_commands.json` are intentionally not part of this |
| 94 | +CP2K-style first version. They are build-level static-analysis concerns, while |
| 95 | +this precommit driver is a lightweight file-level formatting and convention gate. |
| 96 | + |
| 97 | +## Notes for ABACUS maintainers |
| 98 | + |
| 99 | +The only non-CP2K structural change is that C++ is first-class. CP2K rejects |
| 100 | +most C++ files; this ABACUS version formats `.c`, `.cc`, `.cpp`, `.cxx`, `.h`, |
| 101 | +`.hh`, `.hpp`, `.hxx`, `.cu`, `.cuh`, `.hip`, and `.cl` files. |
| 102 | + |
| 103 | +`check_file_properties.py` contains the ABACUS-specific convention checks. The |
| 104 | +banner/license policy should be tightened once the exact ABACUS source header is |
| 105 | +agreed upon. |
0 commit comments