2021-01-22 13:44:05 -03:00
|
|
|
#!/usr/bin/env bash
|
2021-01-03 23:08:26 -03:00
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
|
|
|
|
cd "${script_path}/.." || exit 1
|
|
|
|
|
|
2025-06-09 10:32:47 -03:00
|
|
|
overwrite=0
|
2025-05-22 08:24:42 -03:00
|
|
|
|
|
|
|
|
if [ "$#" -gt "0" ]; then
|
|
|
|
|
if [ "--overwrite-inplace" = "$1" ] ; then
|
2025-06-09 10:32:47 -03:00
|
|
|
overwrite=1
|
2025-05-22 08:24:42 -03:00
|
|
|
shift
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2021-01-03 23:08:26 -03:00
|
|
|
if [ "$#" -eq "0" ]; then
|
2024-07-16 08:41:50 -03:00
|
|
|
files=()
|
|
|
|
|
while IFS= read -r file; do
|
|
|
|
|
files+=("$file")
|
|
|
|
|
done < <(
|
2021-01-03 23:08:26 -03:00
|
|
|
git ls-files '*.py'
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
files=()
|
|
|
|
|
for file in "$@"; do
|
|
|
|
|
if [[ "${file}" == *".py" ]]; then
|
|
|
|
|
files+=("${file}")
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if (( ${#files[@]} )); then
|
2025-06-09 10:32:47 -03:00
|
|
|
if ! command -v ruff >/dev/null 2>&1 ; then
|
|
|
|
|
echo "Please install ruff: pip3 install ruff"
|
2021-01-10 04:20:21 -03:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-06-09 10:32:47 -03:00
|
|
|
if [[ ${overwrite} -eq 0 ]] ; then
|
|
|
|
|
ruff check "${files[@]}"
|
|
|
|
|
ruff format --check "${files[@]}"
|
|
|
|
|
else
|
|
|
|
|
ruff check --fix "${files[@]}"
|
|
|
|
|
ruff format "${files[@]}"
|
|
|
|
|
fi
|
2021-01-03 23:08:26 -03:00
|
|
|
else
|
|
|
|
|
echo "No py files to check."
|
|
|
|
|
fi
|