Meta: Lint python files with black

It's the industry standard nowadays. This also lets us add a flag to the
lint-python.sh script to overwrite our python files in place.
This commit is contained in:
Timothy Flynn
2025-05-22 07:24:42 -04:00
committed by Jelle Raaijmakers
parent fe99c1fa7c
commit 9e8336c04f
3 changed files with 15 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ jobs:
run: |
set -e
brew install curl flake8 llvm@20 ninja optipng shellcheck swift-format unzip
brew install black curl llvm@20 ninja optipng shellcheck swift-format unzip
# Note: gn isn't available in homebrew :(
# Corresponds to https://gn.googlesource.com/gn/+/225e90c5025bf74f41dbee60d9cde4512c846fe7

View File

@@ -5,6 +5,15 @@ set -e
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "${script_path}/.." || exit 1
check_argument="--check"
if [ "$#" -gt "0" ]; then
if [ "--overwrite-inplace" = "$1" ] ; then
check_argument=""
shift
fi
fi
if [ "$#" -eq "0" ]; then
files=()
while IFS= read -r file; do
@@ -22,12 +31,12 @@ else
fi
if (( ${#files[@]} )); then
if ! command -v flake8 >/dev/null 2>&1 ; then
echo "flake8 is not available, but python files need linting! Either skip this script, or install flake8."
if ! command -v black >/dev/null 2>&1 ; then
echo "black is not available, but python files need linting! Either skip this script, or install black."
exit 1
fi
flake8 "${files[@]}" --max-line-length=120
black ${check_argument} "${files[@]}"
else
echo "No py files to check."
fi

2
pyproject.toml Normal file
View File

@@ -0,0 +1,2 @@
[tool.black]
line-length = 120