Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruff rules #32

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ reportUnknownArgumentType = "warning"

[tool.ruff]
output-format="concise"
line-length = 90
exclude = ["node_modules", "__pycache__"]
lint.select = [
"F", # Pyflakes
Expand All @@ -19,11 +18,19 @@ lint.select = [
"R", # Ruff-specific
"N", # Naming
"I", # Import conventions
"SIM", # flake8-simplify
"UP", # pyupgrade
"RUF", # ruff-specific rules
"ARG", # flake8-unused-arguments
"TRY", # tryceratops
"PLR0402", # import a.b as b -> from a import b
]

lint.ignore = [
"E501", # Example: Ignore line length warnings
"D", # Ignore all docstring-related warnings
"ARG002",# Ignore unused-argument in method > problematic eg when required by parent class / interface
"TRY003",# Allow to write exception messages in place instead of subclassing
]

[tool.ruff.format]
Expand Down
Empty file modified tests/ci/check_def_changed.sh
100644 → 100755
Empty file.
41 changes: 29 additions & 12 deletions tests/ci/lint.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
#!/bin/bash
#===============================================================================
# Description: Runs ruff either on all Python files or only on changed files
# compared to master branch using a specified Singularity container
# compared to master branch using a specified Singularity container
#
# Arguments:
# $1 - Path to Singularity (.sif) container
# $2 - Optional: "--all" to run on all files, otherwise runs only on changed files
# $1 - Path to Singularity (.sif) container
# $2 - Optional: "--all" to run on all files, otherwise runs only on changed files
# $3+ - Optional: Additional arguments passed directly to ruff
#
# Usage:
# tests/ci/lint.sh container.sif # Lint only changed Python files
# tests/ci/lint.sh container.sif --all # Lint all Python files
# (run from top level directory!)
# tests/ci/lint.sh container.sif # Lint only changed Python files
# tests/ci/lint.sh container.sif --all # Lint all Python files
# tests/ci/lint.sh container.sif --all --select E501,F401 # Lint all files with specific rules
# tests/ci/lint.sh container.sif "" --fix # Fix changed files
# (run from top level directory!)
#
# Dependencies:
# - Singularity/Apptainer + container
# - Container must have ruff installed
# - Singularity/Apptainer + container
# - Container must have ruff installed
#===============================================================================

if [ "$2" = "--all" ]; then
apptainer exec "$1" ruff check .
# Store the container path
CONTAINER="$1"
shift

# Check if --all flag is present
if [ "$1" = "--all" ]; then
# Remove --all from arguments
shift
# Run ruff on all files with any remaining arguments
apptainer exec "$CONTAINER" ruff check . "$@"
else
# If first arg isn't --all, put it back in the argument list
if [ -n "$1" ]; then
set -- "$1" "$@"
fi

# Get changed Python files
changed_files=$(git diff --name-only origin/master...HEAD -- '*.py')
if [ -n "$changed_files" ]; then
apptainer exec "$1" ruff check $(git diff --name-only origin/master...HEAD -- '*.py')
# Run ruff on changed files with any remaining arguments
apptainer exec "$CONTAINER" ruff check $(git diff --name-only origin/master...HEAD -- '*.py') "$@"
else
echo "No .py files changed"
fi
Expand Down