Compare commits

..

1 commit

Author SHA1 Message Date
9039dc7e40
python-tools.sh, py-mod.mk: Use --symbol-filter
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m8s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m22s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m9s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m14s
CI / Packaging test (push) Successful in 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>
2026-06-12 07:33:07 +02:00

View file

@ -59,6 +59,11 @@ cmd_create_init()
if [ "$sed_extract_cmd" ]; then if [ "$sed_extract_cmd" ]; then
local src_type types=$(sed "$sed_extract_cmd" $f) local src_type types=$(sed "$sed_extract_cmd" $f)
for src_type in $types; do for src_type in $types; do
if [ -z "$sed_symbol_filter_cmd" ]; then
dst_type="$src_type"
else
dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd")
fi
[ "$sed_symbol_filter_cmd" ] && dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd") [ "$sed_symbol_filter_cmd" ] && dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd")
echo "from `module_path $base` import $src_type as $dst_type" echo "from `module_path $base` import $src_type as $dst_type"
__add_seen $dst_type __add_seen $dst_type