-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_ruff.sh
executable file
·41 lines (35 loc) · 1.08 KB
/
run_ruff.sh
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
#!/bin/bash
set -e
RUFF_LINT="${RUFF_LINT:-true}"
REQUIRED_RUFF_VERSION="0.3.3"
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-"python3"}
ensure_ruff_installed() {
if ! "${PYTHON_EXECUTABLE}" -m ruff --version &>/dev/null; then
echo "Installing ruff ${REQUIRED_RUFF_VERSION}"
"${PYTHON_EXECUTABLE}" -m pip install ruff==${REQUIRED_RUFF_VERSION}
fi
RUFF_VERSION=$("${PYTHON_EXECUTABLE}" -m ruff --version)
if [[ $RUFF_VERSION != "ruff $REQUIRED_RUFF_VERSION" ]]; then
echo "Incorrect ruff version ${RUFF_VERSION}; Updating ruff version."
"${PYTHON_EXECUTABLE}" -m pip install ruff==${REQUIRED_RUFF_VERSION}
fi
}
run_ruff() {
ruff_cmd="ruff check"
if [[ "$2" != "" ]]; then
ruff_cmd="$ruff_cmd $2 $1 --config ruff.toml"
else
ruff_cmd="$ruff_cmd $1 --config ruff.toml"
fi
# shellcheck disable=SC2086
"${PYTHON_EXECUTABLE}" -m $ruff_cmd
}
if [[ "$1" == "--fix" ]]; then
RUFF_ARGS="--fix --show-fixes"
else
RUFF_ARGS=""
fi
if [[ $RUFF_LINT = true ]]; then
ensure_ruff_installed
run_ruff . "$RUFF_ARGS"
fi