def dynamic_import(mod_path, obj_name=None):
try:<EOL><INDENT>module = __import__(mod_path, fromlist=['<STR_LIT>'])<EOL><DEDENT>except ImportError as error:<EOL><INDENT>raise errors.DynamicImportFailed(<EOL>module='<STR_LIT:.>'.join([mod_path, obj_name]), reason=error)<EOL><DEDENT>importlib.reload(module)<EOL>if obj_name is None:<EOL><INDENT>obj = module<EOL><DEDENT>elif hasattr(module, obj_name):<EOL><INDENT>obj = getattr(module, obj_name)<EOL><DEDENT>else:<EOL><INDENT>raise errors.DynamicImportFailed(<EOL>module='<STR_LIT:.>'.join([mod_path, obj_name]),<EOL>reason='<STR_LIT>'.<EOL>format(module.__name__, obj_name))<EOL>return None<EOL><DEDENT>return obj<EOL>
Take a string and return the corresponding module