Improve Python config file template substitution #8

Merged
Jan Lindemann merged 10 commits from jan/feature/20260609-pyproject-toml-add-mypypath into master 2026-06-09 08:13:09 +02:00 AGit
Showing only changes of commit 0b558635a8 - Show all commits

py-topdir.mk: Introduce $(PY_CHECK_ROOTS)

Replace variable PY_SRC_ROOT by PY_CHECK_ROOTS. The name PY_SRC_ROOT was a bad choice, given that it isn't immediately obvious that it a) can contain multiple root locations to be checked, and that it b) specifically concerns static type checking.

As of this commit, it's possible to limit the type checking scope with PY_CHECK_ROOTS as in

PY_CHECK_ROOTS="src/python/jw/pkg/CmdBase.py src/python/jw/lib" \ make check
Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann 2026-06-05 14:36:22 +02:00
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -1,7 +1,9 @@
TD_COPY_FILES += pyproject.toml TD_COPY_FILES += pyproject.toml
PY_CHECK_EXCLUDE ?= PY_CHECK_EXCLUDE ?=
PY_SRC_ROOT += $(wildcard $(TOPDIR)/src $(TOPDIR)/tools) ifndef PY_CHECK_ROOTS
PY_CHECK_ROOTS += $(wildcard $(TOPDIR)/src $(TOPDIR)/tools)
endif
ifndef PY_CHECK_RUFF ifndef PY_CHECK_RUFF
PY_CHECK_RUFF := $(shell which ruff 2>/dev/null) PY_CHECK_RUFF := $(shell which ruff 2>/dev/null)
@ -25,27 +27,27 @@ check-format: py-check-format
py-check: py-check-syntax py-check-format py-check: py-check-syntax py-check-format
py-check-syntax: py-check-syntax:
ifneq ($(PY_CHECK_RUFF),) ifneq ($(PY_CHECK_RUFF),)
$(PY_CHECK_RUFF) check $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT) $(PY_CHECK_RUFF) check $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_CHECK_ROOTS)
endif endif
mypy $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT) mypy $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_CHECK_ROOTS)
ifneq ($(PY_CHECK_PYRIGHT),) ifneq ($(PY_CHECK_PYRIGHT),)
pyright pyright $(PY_CHECK_ROOTS)
endif endif
py-check-format: py-check-format:
ifneq ($(PY_CHECK_YAPF),) ifneq ($(PY_CHECK_YAPF),)
$(PY_CHECK_YAPF) --diff --recursive . $(PY_CHECK_YAPF) --diff --recursive $(PY_CHECK_ROOTS)
endif endif
py-format: py-format:
find . -type f -name '*.py' -print0 | \ 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/^ //}}' xargs -0 sed -i -E '1{/^# -\*- coding: utf-8 -\*-$$/{:a;N;/\n[[:space:]]*$$/ba;s/^# -\*- coding: utf-8 -\*-\n([[:space:]]*\n)*/ /;s/^ //}}'
ifneq ($(PY_CHECK_YAPF),) ifneq ($(PY_CHECK_YAPF),)
$(PY_CHECK_YAPF) --in-place --recursive . $(PY_CHECK_YAPF) --in-place --recursive $(PY_CHECK_ROOTS)
endif endif
py-format-assignments: py-format-assignments:
find . \ find $(PY_CHECK_ROOTS) \
-path './.git' -prune -o \ -path './.git' -prune -o \
-type f -name '*.py' \ -type f -name '*.py' \
-execdir /usr/bin/sed -i 's/^\(\s\+[a-zA-Z0-9_]\+\)=\([^,[:space:]]\+\)\([,(]\)*\s*$$/\1 = \2\3/g' {} '+' -execdir /usr/bin/sed -i 's/^\(\s\+[a-zA-Z0-9_]\+\)=\([^,[:space:]]\+\)\([,(]\)*\s*$$/\1 = \2\3/g' {} '+'
@ -53,12 +55,12 @@ py-format-assignments:
py-check-annotation-imports: py-check-annotation-imports:
ifneq ($(PY_CHECK_RUFF),) ifneq ($(PY_CHECK_RUFF),)
$(PY_CHECK_RUFF) check --select TC,FA --diff --unsafe-fixes . $(PY_CHECK_RUFF) check --select TC,FA --diff --unsafe-fixes $(PY_CHECK_ROOTS)
endif endif
py-format-annotation-imports: py-format-annotation-imports:
ifneq ($(PY_CHECK_RUFF),) ifneq ($(PY_CHECK_RUFF),)
$(PY_CHECK_RUFF) check --select TC,FA --fix --unsafe-fixes . $(PY_CHECK_RUFF) check --select TC,FA --fix --unsafe-fixes $(PY_CHECK_ROOTS)
endif endif
clean.topdir: clean.py-check clean.topdir: clean.py-check