py-mod.mk: Support PY_INIT_SUBMODULES
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m3s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m12s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m2s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m21s
CI / Packaging test (push) Successful in 0s

Add support for PY_INIT_SUBMODULES to py-mod.mk. If it is defined in a Makefile including py-mod.mk, the listed submodules will be added to __init__.py and thus included in the list of things that can be imported from a module.

This commit also adds support for --submodules to python-tools.sh for that to happen.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-16 12:51:45 +02:00
commit d42040cb7b
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 18 additions and 1 deletions

View file

@ -14,6 +14,11 @@ ifneq ($(PY_SYMBOL_FILTER),)
PY_GENERATE_INIT_PY += --symbol-filter "$(PY_SYMBOL_FILTER)"
endif
PY_INIT_SUBMODULES ?=
ifneq ($(PY_INIT_SUBMODULES),)
PY_GENERATE_INIT_PY += --submodules "$(PY_INIT_SUBMODULES)"
endif
#leftparen := (
#PY_EXPORT ?= $(shell sed '/\(class\|def\) ..*\# *export/ !d; s/\(class\|def\) *//; s/[$(leftparen):].*//' $(PY_SRC_PY))

View file

@ -68,6 +68,13 @@ cmd_create_init()
done
done
fi
local submodule
for submodule in $submodules; do
echo "from . import $submodule as $submodule"
__add_seen $submodule
done
if [ "$import_submodules" = 1 ]; then
for f in $files; do
[ -f $f/__init__.py ] || continue
@ -90,7 +97,8 @@ cmd_create_init()
myname=`basename $0`
eval set -- `getopt -l 'symbol-filter:,extract-filter:,module:' -o 'he:m:' "$@"`
submodules=""
eval set -- `getopt -l 'symbol-filter:,extract-filter:,module:,submodules:' -o 'he:m:' "$@"`
while [ "$1" != -- ]; do
case $1 in
-e|--extract-filter)
@ -105,6 +113,10 @@ case $1 in
module=$2
shift
;;
-m|--submodules)
submodules="$submodules $2"
shift
;;
-h|--help)
usage 0
;;