misc.load_class(): Use jw.pkg.lib.LoadTypes
Make load_class() use jw.pkg.lib.LoadTypes, because it provides the possibility to nicely log which modules and classes it picks. TODO: Don't use importlib at all in module misc. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
26f3893579
commit
d4fd741c19
1 changed files with 6 additions and 2 deletions
|
|
@ -9,6 +9,8 @@ import tempfile
|
||||||
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
|
from jw.pkg.lib.Types import LoadTypes
|
||||||
|
|
||||||
from . import log
|
from . import log
|
||||||
|
|
||||||
_tmpfiles: set[str] = set()
|
_tmpfiles: set[str] = set()
|
||||||
|
|
@ -95,8 +97,10 @@ def load_classes(path, baseclass, flt = None): # export
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def load_class(module_path, baseclass, class_name_filter = None): # export
|
def load_class(module_path, baseclass, class_name_filter = None): # export
|
||||||
mod = importlib.import_module(module_path)
|
type_filter = None if baseclass is None else [baseclass]
|
||||||
classes = get_derived_classes(mod, baseclass, flt = class_name_filter)
|
classes = LoadTypes(
|
||||||
|
[module_path], type_name_filter = class_name_filter, type_filter = type_filter
|
||||||
|
).classes
|
||||||
if len(classes) == 0:
|
if len(classes) == 0:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f'no class matching "{class_name_filter}" of type "{baseclass}" '
|
f'no class matching "{class_name_filter}" of type "{baseclass}" '
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue