Add py-check.mk and use it from py-topdir.mk and py-rules.mk. This
removes redundant check definitions, making sure that that checks run
from a repo's subdirectory match the checks run from its toplevel
directory.
Signed-off-by: Jan Lindemann <jan@janware.com>
.mypy_cache, .ruff_cache and .pytest_cache are not consistently
cleaned in all subdirectories. Fix that.
Signed-off-by: Jan Lindemann <jan@janware.com>
py-topdir.mk has this:
ifndef PY_CHECK_ROOTS
PY_CHECK_ROOTS += ...
endif
That is too involved: Either PY_CHECK_ROOTS is defined, then nothing
is appended, or it's undefined, then a simple "=" would be just fine.
Use that instead.
Signed-off-by: Jan Lindemann <jan@janware.com>
Make use of the newly introduced --prefix option to the pythonpath
command, and generate what's subseqently used to fill in mypy_path in
pyproject.toml.
By decoupling it from PYTHONPATH, this commit makes the creation of
mypy_path less involved and easier to understand. It also obviates
the need replace the relatively heavy ldlibpath.mk by the relatively
lightweight projects.mk, thereby enhancing performance.
Signed-off-by: Jan Lindemann <jan@janware.com>
pyproject.toml is currently copied unchanged from conf/topdir to the
toplevel directory. Set up machinery in py-topdir.mk to render it
from a template in conf/templates instead, replacing {mypypath} in
the process.
Signed-off-by: Jan Lindemann <jan@janware.com>
ruff tries to recursivley use every config file it finds and stumbles
over a template:
/usr/bin/ruff check --select TC,FA --fix --unsafe-fixes .
ruff failed
Cause: Failed to parse /home/jan/local/src/jw.dev/proj/jw-pkg/conf/templates/pyproject.toml
Cause: TOML parse error at line 3, column 3
|
3 | {mypypath}
| ^
invalid key-value pair, expected key
Limiting it to the toplevel pyproject.toml by explicitly specifying
--config fixes the behaviour, so that's what this commit does.
Signed-off-by: Jan Lindemann <jan@janware.com>
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>
Be prepared to not have working pyright. This is necessary, because
the next commit will remove it for Debian.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add two new targets, basically
py-check-annotation-imports:
ruff check --select TC,FA --fix --unsafe-fixes .
py-format-annotation-imports:
ruff format --select TC,FA --fix --unsafe-fixes .
They basically import statements merely used for annotation
only during type checking runs:
if TYPE_CHECKING:
import AirFrobnicator from frobnication
Signed-off-by: Jan Lindemann <jan@janware.com>
"make check" fails on Kali Linux, because the machinery lacks pieces:
- Add mypy, yapf3, python3-pyright to project.conf for Debian. The
pyright package is not in upstream Kali, but is now supplied by
the jw-foss repo.
- ifdef ruff out from "make check" in py-topdir.mk, because it's
too much work to get that to work from packages on Kali Linux for
now.
project.conf, py-topdir.mk: Make Kali work
Signed-off-by: Jan Lindemann <jan@janware.com>
make topdir doesn't reliably regenerate pyrightconfig.json because of
.SECONDEXPANSION. Adding a second dollar symbol $$(TD_GENERATE_FILES)
solves the problem.
Signed-off-by: Jan Lindemann <jan@janware.com>
py-topdir.mk: Use ruff and yapf
- Use pyright for the target py-check-syntax
- Generate a $(TOPDIR)/pyrightconfig.json for that
- Add pyrightconfig-base.json because it's used by
pyrightconfig.json
- Add python3-pyright to pkg.requires.release, anticipating the use
of the py-syntax-check target by CI
Signed-off-by: Jan Lindemann <jan@janware.com>
- Use ruff and yapf for the targets py-check-syntax, py-format and
py-check-format.
- Add a pyproject.toml for those. It also includes configuration
for isort, albeit not being directly used in the linter targets.
- Make .gitignore igore that in newly created projects.
- Add ruff, yapf and isort to pkg.requires.release, anticipating
their use by CI.
Signed-off-by: Jan Lindemann <jan@janware.com>
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>