* Fix 3530

* Update
This commit is contained in:
Daniel Girtler 2025-05-29 21:54:28 +10:00 committed by GitHub
parent d4b16cb406
commit 8bed035e21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 11 deletions

View File

@ -8,7 +8,6 @@ from importlib import metadata
from pathlib import Path
from .output import error, info, warn
from .storage import storage
plugins = {}
@ -74,13 +73,6 @@ def _import_via_path(path: Path, namespace: str | None = None) -> str:
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))
@ -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 sys.modules[namespace].__archinstall__version__ < archinstall_major_and_minor_version:
if version is not None:
version_major_and_minor = version.rsplit('.', 1)[0]
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()