Files
awx/pre-commit.sh
Dirk JulichandClaude Opus 4.6 4b73e1264b AAP-85334: Replace Black + Flake8 with Ruff
Migrate Python linting and formatting toolchain from Black (formatter)
and Flake8 (linter) to Ruff, which provides both in a single tool.

- pyproject.toml: remove [tool.black], add [tool.ruff] config sections
- tox.ini: replace black+flake8 deps/commands with ruff in linters env
- awxkit/tox.ini: replace flake8 with ruff in lint env
- Makefile: replace `black` target with `format` + `lint`, keep `black`
  as legacy alias, update `check` and `api-lint`
- pre-commit.sh: use `ruff format --check`, honor AWX_IGNORE_RUFF
- requirements_dev.txt: swap black/flake8 for ruff
- Dockerfile.j2: install ruff instead of black
- CONTRIBUTING.md: update tool references
- Fix noqa comments to use # separator instead of ; (ruff requirement)
- Add noqa: F841 for false positive in awxkit/cli/__init__.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-08-20 18:35:23 +02:00

33 lines
946 B
Bash
Executable File

#!/usr/bin/env bash
if [ -z "$AWX_IGNORE_BLACK" ] && [ -z "$AWX_IGNORE_RUFF" ] ; then
python_files_changed=$(git diff --cached --name-only --diff-filter=AM awx/ awxkit/ tools/ | grep -E '\.py$')
if [ "x$python_files_changed" != "x" ] ; then
ruff format --check $python_files_changed || \
if [ $? != 0 ] ; then
echo 'To fix this, run `make format` to auto-format your code prior to commit, or set AWX_IGNORE_RUFF=1'
exit 1
fi
fi
fi
if [ -z $AWX_IGNORE_USER ] ; then
FAIL=0
export CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM)
if [ -d ./pre-commit-user ] ; then
for SCRIPT in `find ./pre-commit-user -type f` ; do
if [ -x $SCRIPT ] ; then
echo "Running user pre-commit hook $SCRIPT"
$SCRIPT
if [ $? != 0 ] ; then
echo "User test $SCRIPT failed"
FAIL=1
fi
fi
done
fi
if [ $FAIL == 1 ] ; then
echo "One or more user tests failed, see messages above"
exit 1
fi
fi