Enhancements in precommit_install.sh for Python and CK Tile code (#2400)

* fix(precommit_install): script now installs packages in virtual env

* fix(precommit_install): installs packages in virtual env

* feat(precommit): added ruff for python linting and formatting

* feat(precommit): added ruff for python linting and formatting

* feat(precommit): run ruff when py files are commited

* feat(precommit): remod.py is run when ck_tile modified

* add empty line at the end

* style(precommit.yaml): remove empty line

---------

Co-authored-by: Max Podkorytov <4273004+tenpercent@users.noreply.github.com>

[ROCm/composable_kernel commit: e9036a8fc2]
This commit is contained in:
Aviral Goel
2025-07-01 04:11:10 -04:00
committed by GitHub
parent ae7f6accfc
commit 26fd170c5b
3 changed files with 47 additions and 9 deletions

View File

@@ -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

View File

@@ -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."

17
script/remod_for_ck_tile.sh Executable file
View File

@@ -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