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>
30 lines
1.2 KiB
Makefile
30 lines
1.2 KiB
Makefile
include $(JWBDIR)/make/defs.mk
|
|
include $(JWBDIR)/make/py-defs.mk
|
|
include $(JWBDIR)/make/dirs.mk
|
|
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))
|
|
|
|
all: $(PY_PYC)
|
|
install: install-dirs.done install-reg.done
|
|
clean: py.clean
|
|
distclean:
|
|
|
|
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; $(PY_GENERATE_INIT_PY) \
|
|
$(filter-out __init__.py,$(PY_ALL_PY)) $(SUBDIRS_TO_ITERATE) | $(PY_INIT_FILTER) | tee -a $@.tmp
|
|
mv $@.tmp $@
|
|
endif
|