-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruff.sh
More file actions
executable file
·42 lines (35 loc) · 2.24 KB
/
Copy pathruff.sh
File metadata and controls
executable file
·42 lines (35 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash -
# This is our internal ruff execution script.
# It prints the ruff command and the results of ruff.
# It always exits with an exit code 0, even if ruff fails.
# Argument $1: the folder to run it in
# Argument $2: the file(s) to scan
# We enforce strict error handling, i.e., fail on any unexpected error.
set -o pipefail # trace errors through pipes
set -o errtrace # trace errors through commands and functions
set -o nounset # exit if encountering an uninitialized variable
set -o errexit # exit if any statement returns a non-0 return value
# Check if ruff is installed. If yes, get its version. If no, install.
infos="$(python3 -m pip show ruff 2>/dev/null || true)"
if [ -z "$infos" ]; then
# ruff is not installed, so we install it now.
# We do this silently, without printing any information...
python3 -m pip install --require-virtualenv ruff 1>/dev/null 2>&1
infos="$(python3 -m pip show ruff 2>/dev/null)"
fi
# We now extract the version of ruff from the information string.
version="$(grep Version: <<< "$infos")"
version="$(sed -n 's/.*Version:\s*\([.0-9]*\)/\1/p' <<< "$version")"
# Construct the ruff command.
command="ruff check --target-version py312 --select=A,AIR,ANN,ASYNC,B,BLE,C,C4,COM,D,DJ,DTZ,E,ERA,EXE,F,FA,FIX,FLY,FURB,G,I,ICN,INP,ISC,INT,LOG,N,NPY,PERF,PIE,PLC,PLE,PLR,PLW,PT,PYI,Q,RET,RSE,RUF,S,SIM,T,T10,TD,TID,TRY,UP,W,YTT --ignore=A005,ANN001,ANN002,ANN003,ANN204,ANN401,B008,B009,B010,C901,D203,D208,D212,D401,D407,D413,INP001,N801,PLC2801,PLR0904,PLR0911,PLR0912,PLR0913,PLR0914,PLR0915,PLR0916,PLR0917,PLR1702,PLR2004,PLR6301,PT011,PT012,PT013,PYI041,RUF100,S,T201,TRY003,UP035,W --line-length 79 $2"
echo "\$ $command" # We print the command line which will be executed.
cd "$1" # We enter the folder inside of which we should execute ruff.
# Switch of "exit-on-error", run ruff, and afterwards switch it back on.
set +o errexit # Turn off exit-on-error.
$command 2>&1 # Run ruff.
exitCode="$?" # Store exit code of program in variable exitCode.
set -o errexit # Turn exit-on-error back on.
# Convert exit code to success or failure string.
[ "$exitCode" -eq 0 ] && exitCodeStr="succeeded" || exitCodeStr="failed"
# Finally, we print the result string.
echo "# ruff $version $exitCodeStr with exit code $exitCode."