make, scripts: Add support for static Python typechecking

This commit adds support for static typechecking with mypy.

Notable additions:

  - A new target "check" which does the type checking

  - Py-mods.mk, meant to be included from a directory containing python modules
    in subdirectories, but not being a python module itself. It makes the all
    target depend on check only if PY_RUN_CHECK_AFTER_BUILD is defined and
    true.  That's because pypy is under heavy development, and the Ubuntu 18.04
    version is too old to work for lots of the code.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2020-04-10 12:13:12 +00:00
commit a404be15b9
4 changed files with 25 additions and 3 deletions

View file

@ -21,6 +21,8 @@ ifndef PY_PREREQ_BUILD_DIRS
PY_PREREQ_BUILD_DIRS := $(shell $(proj_query_cmd) proj-dir $(PY_PREREQ_BUILD))
endif
PY_MYPY ?= mypy --ignore-missing-imports
PY_SRC_PY ?= $(wildcard *.py)
PY_ALL_PY = $(PY_SRC_PY)
@ -66,7 +68,8 @@ PY_INSTALLED_REG = $(PY_INSTALLED_PY) $(PY_INSTALLED_PYC)
PYTHONPATH ?= $(call proj_query, pythonpath $(PROJECT) $(PY_PREREQ_RUN))
#PYTHONPATH = $(subst $(space),,$(ENV_PYTHONPATH)$(foreach d,$(PY_MODULE_DIRS),:$(d)))
export PYTHONPATH
MYPYPATH = $(PYTHONPATH)
export PYTHONPATH MYPYPATH
# not used anywhere
#PY_PROJ_MODULE_DIRS ?= $(wildcard $(foreach subdir,/tools/python /src/python,$(addsuffix $(subdir),$(TOPDIR) $(PY_PREREQ_BUILD_DIRS))))
@ -84,6 +87,7 @@ echo-py:
@echo "PY_SITE_PACKAGES_PATH = $(PY_SITE_PACKAGES_PATH)"
@echo "PY_MODULES = $(PY_MODULES)"
@echo "PYTHONPATH = $(PYTHONPATH)"
@echo "MYPYPATH = $(MYPYPATH)"
@echo "PY_INSTALL_MOD = $(PY_INSTALL_MOD)"
@echo "PY_INSTALL_SUB_MOD = $(PY_INSTALL_SUB_MOD)"
# not used anywhere"