misc: Add load_function()

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-01-29 16:54:10 +01:00
commit cc7aeeac31

View file

@ -105,6 +105,10 @@ def load_class_names(path, baseclass, flt=None, remove_flt=False): # export
def load_object(module_path, baseclass, class_name_filter=None, *args, **kwargs): # export def load_object(module_path, baseclass, class_name_filter=None, *args, **kwargs): # export
return load_class(module_path, baseclass, class_name_filter=class_name_filter)(*args, **kwargs) return load_class(module_path, baseclass, class_name_filter=class_name_filter)(*args, **kwargs)
def load_function(module_path, name): # export
mod = importlib.import_module(module_path)
return getattr(mod, name)
def commit_tmpfile(tmp: str, path: str) -> None: # export def commit_tmpfile(tmp: str, path: str) -> None: # export
caller = log.get_caller_pos() caller = log.get_caller_pos()
if os.path.isfile(path) and filecmp.cmp(tmp, path): if os.path.isfile(path) and filecmp.cmp(tmp, path):