From 3e88cace1a50861d0eb5259187a5338bc74369e4 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 30 Oct 2024 11:33:03 +0100 Subject: [PATCH] feat: add formatting check & shortcut usage --- tests/ci/changed_py_files.sh | 3 +++ tests/ci/lint.sh | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 tests/ci/changed_py_files.sh diff --git a/tests/ci/changed_py_files.sh b/tests/ci/changed_py_files.sh new file mode 100755 index 00000000..c155ab2c --- /dev/null +++ b/tests/ci/changed_py_files.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo $(git diff --name-only origin/master...HEAD -- '*.py') \ No newline at end of file diff --git a/tests/ci/lint.sh b/tests/ci/lint.sh index cfa1c70d..6fc19a20 100755 --- a/tests/ci/lint.sh +++ b/tests/ci/lint.sh @@ -27,6 +27,16 @@ shift if [ "$1" = "--all" ]; then # Remove --all from arguments shift + + # Check or fix + check="--check" + if [[ "$@" == *"--fix"* ]]; then + check="" + fi + + # Format + apptainer exec "$CONTAINER" ruff format "$check" . + # Run ruff on all files with any remaining arguments apptainer exec "$CONTAINER" ruff check . "$@" else @@ -36,10 +46,13 @@ else fi # Get changed Python files - changed_files=$(git diff --name-only origin/master...HEAD -- '*.py') + changed_files=$(tests/ci/changed_py_files.sh) if [ -n "$changed_files" ]; then + # Format + apptainer exec "$CONTAINER" ruff format "$check" $changed_files + # Run ruff on changed files with any remaining arguments - apptainer exec "$CONTAINER" ruff check $(git diff --name-only origin/master...HEAD -- '*.py') "$@" + apptainer exec "$CONTAINER" ruff check $changed_files "$@" else echo "No .py files changed" fi