Use package directory to namespace modules

merge-requests/12/head
Luke Murphy 2021-02-03 11:50:26 +01:00
parent 98e98ab6cc
commit 05705ded65
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 28 additions and 0 deletions

0
__init__.py 100644
View File

View File

@ -0,0 +1,5 @@
# Epicyon Pypi package
This is a wrapper package for the purpose of gathering all modules under the
`epicyon` namespace when doing Python module imports. With this wrapper
package, you can get `from epicyon import httpsig` instead of `import httpsig`.

View File

@ -0,0 +1,23 @@
"""Pypi package module namespce wrapper.
We do this automation based importing to take all Epicyon modules in under this
package namespace in one go. This way we do not have to maintain a module list
here just for the Pypi packaging effort and package builds will automatically
pick up new modules as we go forward.
"""
from pathlib import Path
from pkgutil import walk_packages
__all__ = []
package_root = str(Path(".").parent.absolute())
for loader, module_name, is_pkg in walk_packages([package_root]):
__all__.append(module_name)
if module_name == "epicyon":
continue
_module = loader.find_module(module_name).load_module(module_name)
globals()[module_name] = _module