From 37aa578390fdbfaf220d2376ad0b48cd3a218fd8 Mon Sep 17 00:00:00 2001 From: Jakub Kasperski Date: Fri, 20 Jun 2025 06:44:25 +0200 Subject: [PATCH 1/3] Added requirements.txt and pre commit configuration files --- .clang-format | 5 +++++ .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 .clang-format create mode 100644 .pre-commit-config.yaml create mode 100644 requirements.txt diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..18319fda --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BasedOnStyle: Google +ColumnLimit: 120 +DerivePointerAlignment: false +PointerAlignment: Left +AllowShortFunctionsOnASingleLine: Inline diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..f070bd2d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + + - repo: https://github.com/psf/black + rev: 25.1.0 + hooks: + - id: black + args: [--line-length=120] + + - repo: https://github.com/PyCQA/isort + rev: 6.0.1 + hooks: + - id: isort + args: ["--profile", "black"] + + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v20.1.5 + hooks: + - id: clang-format + args: [-style=file] + files: '\.(cpp|hpp|c|h|cc|hh)$' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..6031a1ef --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pre-commit==4.2.0 +clang-format==20.1.5 From 42dfbdca570bd034f3050b3733522fe176e5f186 Mon Sep 17 00:00:00 2001 From: Jakub Kasperski Date: Fri, 20 Jun 2025 18:44:12 +0200 Subject: [PATCH 2/3] Removed python from precommit (does not work with python2) --- .pre-commit-config.yaml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f070bd2d..6f035b3f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,19 +6,6 @@ repos: - id: end-of-file-fixer - id: check-added-large-files - - repo: https://github.com/psf/black - rev: 25.1.0 - hooks: - - id: black - args: [--line-length=120] - - - repo: https://github.com/PyCQA/isort - rev: 6.0.1 - hooks: - - id: isort - args: ["--profile", "black"] - - - repo: https://github.com/pre-commit/mirrors-clang-format rev: v20.1.5 hooks: From 03e68899d0e801392db1de1fb592ebe6e51a44e2 Mon Sep 17 00:00:00 2001 From: Jakub Kasperski Date: Fri, 20 Jun 2025 18:52:18 +0200 Subject: [PATCH 3/3] Added pre commit setup instructions --- docs/manual/PreCommitSetup.md | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 docs/manual/PreCommitSetup.md diff --git a/docs/manual/PreCommitSetup.md b/docs/manual/PreCommitSetup.md new file mode 100644 index 00000000..297829d4 --- /dev/null +++ b/docs/manual/PreCommitSetup.md @@ -0,0 +1,45 @@ +### Code Formatting and Pre-commit Hooks + +This project uses [pre-commit](https://pre-commit.com) to ensure code quality and consistent formatting. + +To set it up: + +1. **Create a Virtual Environment**: + Create and activate a Python virtual environment: + ```bash + python3 -m venv venv + source venv/bin/activate + ``` + +2. **Install Development Dependencies**: + Install the required dependencies for building the project: + ```bash + pip install -r requirements.txt + ``` + +3. **Install the Git hooks**: + + ```bash + pre-commit install + ``` + +To update the hooks to their latest versions later: + +```bash +pre-commit autoupdate +``` + +**DO NOT** run. It is not recomended on legacy repositories: + + ```bash + pre-commit run --all-files + ``` + +The following hooks are used: + +* `clang-format` for C/C++ formatting +* `trailing-whitespace` to remove trailing spaces +* `end-of-file-fixer` to ensure files end with a single newline +* `check-added-large-files` to avoid accidentally committing large binaries + +All configuration is in `.pre-commit-config.yaml`. The hooks will run automatically every time you commit.