Skip to content

Commit

Permalink
Only parse profile classes when loading modules (#2088)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Girtler <[email protected]>
  • Loading branch information
svartkanin and svartkanin authored Sep 22, 2023
1 parent 6d908e8 commit 8e40de8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions archinstall/lib/profile/profiles_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import importlib.util
import sys
import inspect
from collections import Counter
from functools import cached_property
from pathlib import Path
Expand Down Expand Up @@ -276,12 +277,15 @@ def _load_profile_class(self, module: ModuleType) -> List[Profile]:
profiles = []
for k, v in module.__dict__.items():
if isinstance(v, type) and v.__module__ == module.__name__:
try:
cls_ = v()
if isinstance(cls_, Profile):
profiles.append(cls_)
except Exception:
debug(f'Cannot import {module}, it does not appear to be a Profile class')
bases = inspect.getmro(v)

if Profile in bases:
try:
cls_ = v()
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

Expand Down

0 comments on commit 8e40de8

Please sign in to comment.