diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4dc70c1ffd..e4e85651f6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,9 +12,27 @@ repos: verbose: false language: script types: [c++] - - id: remove-exec-bit - name: Remove executable bit from non-executable files - entry: script/remove_exec_bit.sh - language: script - types_or: [c++, text] - verbose: true + - id: remove-exec-bit + name: Remove executable bit from non-executable files + entry: script/remove_exec_bit.sh + language: script + types_or: [c++, text] + verbose: true + - id: ruff-check + name: Ruff Linter + entry: ruff check --fix + language: python + types: [python] + additional_dependencies: [ruff] + - id: ruff-format + name: Ruff Formatter + entry: ruff format + language: python + types: [python] + additional_dependencies: [ruff] + - id: run-remod-if-ck-tile-changed + name: Run remod.py if ck_tile files changed + entry: script/remod_for_ck_tile.sh + language: script + always_run: true + pass_filenames: false diff --git a/script/install_precommit.sh b/script/install_precommit.sh index 296280bb03..83e526035c 100755 --- a/script/install_precommit.sh +++ b/script/install_precommit.sh @@ -1,5 +1,4 @@ #!/bin/bash - run_and_check() { "$@" status=$? @@ -13,8 +12,12 @@ run_and_check() { echo "I: Installing tools required for pre-commit checks..." run_and_check apt install clang-format-12 -echo "I: Installing pre-commit itself..." -run_and_check pip3 install pre-commit +echo "I: Creating and activating virtual environment for pre-commit..." +python3 -m venv "$(dirname "$0")/../.venv" +source "$(dirname "$0")/../.venv/bin/activate" + +echo "I: Installing pre-commit in virtual environment..." +run_and_check pip install pre-commit run_and_check pre-commit install echo "I: Installation successful." diff --git a/script/remod_for_ck_tile.sh b/script/remod_for_ck_tile.sh new file mode 100755 index 0000000000..5c7a78d0cc --- /dev/null +++ b/script/remod_for_ck_tile.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Get list of staged files +STAGED_FILES=$(git diff --cached --name-only) + +# Check if any staged file is under include/ck_tile/ or example/ck_tile/ +if echo "$STAGED_FILES" | grep -qE '^(include/ck_tile/|example/ck_tile/)'; then + echo "Detected changes in ck_tile-related files. Running remod.py..." + + # Run remod.py in both required locations + (cd include/ck_tile/ && python3 remod.py) + (cd example/ck_tile/ && python3 remod.py) + + echo "remod.py completed." +else + echo "No changes in ck_tile-related files. Skipping remod.py." +fi