def _get_provider_submodule_method(module_name: str, submodule_name: str, method_name: str) -> Optional[Callable]:
sub_module = "{}.{}".format(module_name, submodule_name)
try:
importlib.import_module(module_name, package='__path__')
except ImportError:
return None
if importlib.util.find_spec(sub_module):
site = importlib.import_module(sub_module, package=module_name)
if hasattr(site, method_name):
obj = getattr(site, method_name)
if inspect.isfunction(obj):
return obj
return None
# We should only create one ProviderContext over the program lifetime,
# to avoid having to search the file system every time it's created.
# This is why this should be outside Settings
评论列表
文章目录