* dev: remove len for empty comparison * dev: using in instead of multiple ors * dev: assign expression to empty variables * dev: use f-string * dev: remove list comprehension and use generators * dev: remove assert from paginator * dev: use is for identity comparison with singleton * dev: remove unnecessary else statements * dev: fix does not exists error for both project and workspace * dev: remove reimports * dev: iterate a dictionary * dev: remove unused commented code * dev: remove redefinition * dev: remove unused imports * dev: remove unused imports * dev: remove unnecessary f strings * dev: remove unused variables * dev: use literal structure to create the data structure * dev: add empty lines at the end of the file * dev: remove user middleware * dev: remove unnecessary default None
20 lines
716 B
Python
20 lines
716 B
Python
import pkgutil
|
|
import six
|
|
|
|
|
|
def import_submodules(context, root_module, path):
|
|
"""
|
|
Import all submodules and register them in the ``context`` namespace.
|
|
>>> import_submodules(locals(), __name__, __path__)
|
|
"""
|
|
for loader, module_name, is_pkg in pkgutil.walk_packages(
|
|
path,
|
|
root_module +
|
|
'.'):
|
|
# this causes a Runtime error with model conflicts
|
|
# module = loader.find_module(module_name).load_module(module_name)
|
|
module = __import__(module_name, globals(), locals(), ['__name__'])
|
|
for k, v in six.iteritems(vars(module)):
|
|
if not k.startswith('_'):
|
|
context[k] = v
|
|
context[module_name] = module
|