python-tools.sh, py-mod.mk: Use --symbol-filter
Some checks failed
CI / Packaging - Kali Linux (pull_request) Failing after 2m8s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Failing after 2m34s
CI / Packaging test (pull_request) Failing after 0s

Letting python-tools.sh rewrite symbols is more robust than rewriting an entire __init__.py with PY_INIT_FILTER in the including Makefile. The latter can break in non-obvious ways if python-tools.sh changes __init__.py's format.

Make python-tools.sh support --symbol-filter to remedy that. The option takes an sed script which should expect a string of two non-whitespace tokens: The module from which the symbol is imported, and the name of the symbol in that module. It's output will then be used as the symbol to be exported from __init__.py.

Also, support the PY_SYMBOL_FILTER variable in py-mod.mk. If it's defined, it is used for --symbol-filter.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-12 06:57:23 +02:00
commit 80248dec88
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 36 additions and 10 deletions

View file

@ -6,6 +6,10 @@ include $(JWBDIR)/make/dev-utils.mk
PY_INIT_TMPL = $(wildcard __init__.py.tmpl)
PY_SED_EXTRACT_EXPORT ?= /\(\(class\|def\)\s\+[a-zA-Z_].*\|^ *\S\+\s*=.*\)\# *export/ !d; /^\s*\#/ d; s/\(async\)* *\(class\|def\) *//; s/[(:=].*//
PY_INIT_FILTER ?= cat
PY_GENERATE_INIT_PY ?= /bin/bash $(JWB_SCRIPT_DIR)/python-tools.sh create-init -m . -e "$(PY_SED_EXTRACT_EXPORT)"
ifneq ($(PY_SYMBOL_FILTER),)
PY_GENERATE_INIT_PY += --symbol-filter "$(PY_SYMBOL_FILTER)"
endif
#leftparen := (
#PY_EXPORT ?= $(shell sed '/\(class\|def\) ..*\# *export/ !d; s/\(class\|def\) *//; s/[$(leftparen):].*//' $(PY_SRC_PY))
@ -20,7 +24,7 @@ include $(JWBDIR)/make/py-rules.mk
ifeq ($(PY_UPDATE_INIT_PY),true)
__init__.py: $(PY_INIT_TMPL) $(filter-out __init__.py,$(PY_SRC_PY))
if [ "$(PY_INIT_TMPL)" ]; then cat "$(PY_INIT_TMPL)" > $@.tmp; else > $@.tmp; fi
set -e -o pipefail; /bin/bash $(JWB_SCRIPT_DIR)/python-tools.sh create-init -m . -e "$(PY_SED_EXTRACT_EXPORT)" \
set -e -o pipefail; $(PY_GENERATE_INIT_PY) \
$(filter-out __init__.py,$(PY_ALL_PY)) $(SUBDIRS_TO_ITERATE) | $(PY_INIT_FILTER) | tee -a $@.tmp
mv $@.tmp $@
endif