lib.init.detect_modules(): Add function

Not all __init__.py modules are generated by python-tools.sh, some are needed early to make jw-pkg useful without generation, notably in jw.pkg.cmds.

Add detect_modules() to unify that detection, and place it into a minimal module lib.init to not increase startup time cost.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-05-30 12:44:55 +02:00
commit 13ec34cc57
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
5 changed files with 68 additions and 42 deletions

View file

@ -1,13 +1,9 @@
import importlib, pkgutil
from ..lib.init import detect_modules
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
if not module_name.startswith("Cmd"):
continue
if module_name == "Cmd":
continue
module = importlib.import_module(f".{module_name}", __name__)
cls = getattr(module, module_name)
globals()[module_name] = cls
__all__.append(module_name)
__all__ = detect_modules(
package_name = __name__,
package_path = __path__,
namespace = globals(),
prefix = "Cmd",
skip = {"Cmd"},
) # pyright: ignore[reportUnsupportedDunderAll]

View file

@ -1,11 +1,9 @@
import importlib, pkgutil
from ...lib.init import detect_modules
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
if not module_name.startswith("Cmd"):
continue
module = importlib.import_module(f".{module_name}", __name__)
cls = getattr(module, module_name)
globals()[module_name] = cls
__all__.append(module_name)
__all__ = detect_modules(
package_name = __name__,
package_path = __path__,
namespace = globals(),
prefix = "Cmd",
skip = {"Cmd"},
) # pyright: ignore[reportUnsupportedDunderAll]

View file

@ -1,11 +1,9 @@
import importlib, pkgutil
from ...lib.init import detect_modules
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
if not module_name.startswith("Cmd"):
continue
module = importlib.import_module(f".{module_name}", __name__)
cls = getattr(module, module_name)
globals()[module_name] = cls
__all__.append(module_name)
__all__ = detect_modules(
package_name = __name__,
package_path = __path__,
namespace = globals(),
prefix = "Cmd",
skip = {"Cmd"},
) # pyright: ignore[reportUnsupportedDunderAll]

View file

@ -1,11 +1,9 @@
import importlib, pkgutil
from ...lib.init import detect_modules
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
if not module_name.startswith("Cmd"):
continue
module = importlib.import_module(f".{module_name}", __name__)
cls = getattr(module, module_name)
globals()[module_name] = cls
__all__.append(module_name)
__all__ = detect_modules(
package_name = __name__,
package_path = __path__,
namespace = globals(),
prefix = "Cmd",
skip = {"Cmd"},
) # pyright: ignore[reportUnsupportedDunderAll]