Only parse profile classes when loading modules (#2088)
Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
parent
6d908e8cd7
commit
8e40de85fb
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import sys
|
import sys
|
||||||
|
import inspect
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -276,12 +277,15 @@ class ProfileHandler:
|
||||||
profiles = []
|
profiles = []
|
||||||
for k, v in module.__dict__.items():
|
for k, v in module.__dict__.items():
|
||||||
if isinstance(v, type) and v.__module__ == module.__name__:
|
if isinstance(v, type) and v.__module__ == module.__name__:
|
||||||
try:
|
bases = inspect.getmro(v)
|
||||||
cls_ = v()
|
|
||||||
if isinstance(cls_, Profile):
|
if Profile in bases:
|
||||||
profiles.append(cls_)
|
try:
|
||||||
except Exception:
|
cls_ = v()
|
||||||
debug(f'Cannot import {module}, it does not appear to be a Profile class')
|
if isinstance(cls_, Profile):
|
||||||
|
profiles.append(cls_)
|
||||||
|
except Exception:
|
||||||
|
debug(f'Cannot import {module}, it does not appear to be a Profile class')
|
||||||
|
|
||||||
return profiles
|
return profiles
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue