py-topdir.mk: Add file
Add a file to be included from every toplevel Makefile of every repo that owns Python code. It defines the following targets:
py-check: py-check-syntax py-check-format py-check-syntax: py-check-format: py-format:
Currently, only mypy is run from py-check-syntax, but the targets are meant as entry point for further linter jobs in the future.
There's also
py-format-assignments:
which is meant to add spaces around "=" in multi-line assignment blocks, but, pending future experiments, I thing that target is going to be removed again. Left in for now.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
2961ced779
commit
22b09dd9aa
1 changed files with 31 additions and 0 deletions
31
make/py-topdir.mk
Normal file
31
make/py-topdir.mk
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
TD_COPY_FILES +=
|
||||||
|
|
||||||
|
PY_CHECK_EXCLUDE ?=
|
||||||
|
PY_SRC_ROOT += $(wildcard $(TOPDIR)/src $(TOPDIR)/tools)
|
||||||
|
|
||||||
|
all:
|
||||||
|
|
||||||
|
format: py-format
|
||||||
|
check-syntax: py-check-syntax
|
||||||
|
check-format: py-check-format
|
||||||
|
|
||||||
|
py-check: py-check-syntax py-check-format
|
||||||
|
py-check-syntax:
|
||||||
|
mypy $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT)
|
||||||
|
|
||||||
|
py-check-format:
|
||||||
|
|
||||||
|
py-format:
|
||||||
|
find . -type f -name '*.py' -print0 | \
|
||||||
|
xargs -0 sed -i -E '1{/^# -\*- coding: utf-8 -\*-$$/{:a;N;/\n[[:space:]]*$$/ba;s/^# -\*- coding: utf-8 -\*-\n([[:space:]]*\n)*/ /;s/^ //}}'
|
||||||
|
|
||||||
|
py-format-assignments:
|
||||||
|
find . \
|
||||||
|
-path './.git' -prune -o \
|
||||||
|
-type f -name '*.py' \
|
||||||
|
-execdir /usr/bin/sed -i 's/^\(\s\+[a-zA-Z0-9_]\+\)=\([^,[:space:]]\+\)\([,(]\)*\s*$$/\1 = \2\3/g' {} '+'
|
||||||
|
git diff --exit-code
|
||||||
|
|
||||||
|
clean.topdir: clean.py-check
|
||||||
|
clean.py-check:
|
||||||
|
rm -rf .mypy_cache
|
||||||
Loading…
Add table
Add a link
Reference in a new issue