Skip to content
Snippets Groups Projects
Commit 5b56ec34 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[python] add _register_special_funcs, for instance for dune-gdt

parent fb73d5ae
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,19 @@ _init_logger_calls = set()
_test_logger_calls = set()
def _register_special_funcs(mod, base_name=''):
if isinstance(mod, dict):
mod_dict = mod
else:
mod_dict = import_module('.{}'.format(mod), base_name).__dict__
if '_init_mpi' in mod_dict:
_init_mpi_calls.add(mod_dict['_init_mpi'])
if '_init_logger' in mod_dict:
_init_logger_calls.add(mod_dict['_init_logger'])
if '_test_logger' in mod_dict:
_test_logger_calls.add(mod_dict['_test_logger'])
def guarded_import(globs, base_name, mod_name):
# see https://stackoverflow.com/questions/43059267/how-to-do-from-module-import-using-importlib
try:
......@@ -42,12 +55,7 @@ def guarded_import(globs, base_name, mod_name):
else:
names = [x for x in mod.__dict__ if not x.startswith("_")]
# import special init functions which should be present in every module
if '_init_mpi' in mod.__dict__:
_init_mpi_calls.add(mod.__dict__['_init_mpi'])
if '_init_logger' in mod.__dict__:
_init_logger_calls.add(mod.__dict__['_init_logger'])
if '_test_logger' in mod.__dict__:
_test_logger_calls.add(mod.__dict__['_test_logger'])
_register_special_funcs(mod.__dict__)
# check the rest for duplicity
for nm in names:
if nm in globs:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment