misc.load_object(): Allow multi-value module path
load_path() takes a string as module path. To broaded its versatility, allow also multiple strings to be searched in order. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
cb3ad84fda
commit
20a8ab91f7
1 changed files with 6 additions and 4 deletions
|
|
@ -96,13 +96,15 @@ def load_classes( # export
|
|||
return ret
|
||||
|
||||
def load_class( # export
|
||||
module_path: str,
|
||||
module_path: str | Iterable[str],
|
||||
baseclass: type,
|
||||
class_name_filter: str | None = None
|
||||
) -> type[Any]:
|
||||
if isinstance(module_path, str):
|
||||
module_path = [module_path]
|
||||
type_filter = None if baseclass is None else [baseclass]
|
||||
classes: Iterable[type[Any]] = LoadTypes(
|
||||
[module_path], type_name_filter = class_name_filter, type_filter = type_filter
|
||||
module_path, type_name_filter = class_name_filter, type_filter = type_filter
|
||||
).classes
|
||||
size = len(list(classes))
|
||||
if size != 1:
|
||||
|
|
@ -111,7 +113,7 @@ def load_class( # export
|
|||
msg += f' matching "{class_name_filter}'
|
||||
if baseclass is not None:
|
||||
msg += f' of type "{baseclass}" '
|
||||
msg += f'found in module "{module_path}"'
|
||||
msg += f'found in modules {", ".join(module_path)}'
|
||||
for c in classes:
|
||||
log.slog(log.ERR, f'Found {c!r}')
|
||||
raise Exception(msg)
|
||||
|
|
@ -136,7 +138,7 @@ def load_class_names( # export
|
|||
return ret
|
||||
|
||||
def load_object( # export
|
||||
module_path: str,
|
||||
module_path: str | Iterable[str],
|
||||
baseclass: type,
|
||||
class_name_filter: str|None = None,
|
||||
*args,
|
||||
|
|
|
|||
Loading…
Reference in a new issue