Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions archinstall/lib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path

from .output import error, info, warn
from .storage import storage

plugins = {}

Expand Down Expand Up @@ -74,13 +73,6 @@ def _import_via_path(path: Path, namespace: str | None = None) -> str | None:
return namespace


def _find_nth(haystack: list[str], needle: str, n: int) -> int | None:
indices = [idx for idx, elem in enumerate(haystack) if elem == needle]
if n <= len(indices):
return indices[n - 1]
return None


def load_plugin(path: Path) -> None:
namespace: str | None = None
parsed_url = urllib.parse.urlparse(str(path))
Expand All @@ -96,12 +88,16 @@ def load_plugin(path: Path) -> None:
namespace = _import_via_path(localized)

if namespace and namespace in sys.modules:
from .args import arch_config_handler

# Version dependency via __archinstall__version__ variable (if present) in the plugin
# Any errors in version inconsistency will be handled through normal error handling if not defined.
if hasattr(sys.modules[namespace], '__archinstall__version__'):
archinstall_major_and_minor_version = float(storage['__version__'][: _find_nth(storage['__version__'], '.', 2)])
version = arch_config_handler.config.version

if version is not None:
version_major_and_minor = version.rsplit('.', 1)[0]

if sys.modules[namespace].__archinstall__version__ < archinstall_major_and_minor_version:
if sys.modules[namespace].__archinstall__version__ < float(version_major_and_minor):
error(f'Plugin {sys.modules[namespace]} does not support the current Archinstall version.')

# Locate the plugin entry-point called Plugin()
Expand Down