(path: Path)
| 61 | |
| 62 | |
| 63 | def load_plugin(path: Path) -> None: |
| 64 | namespace: str | None = None |
| 65 | info(f'Loading plugin from {path}') |
| 66 | |
| 67 | if os.path.isfile(path): |
| 68 | namespace = _import_via_path(path) |
| 69 | |
| 70 | if namespace and namespace in sys.modules: |
| 71 | # Version dependency via __archinstall__version__ variable (if present) in the plugin |
| 72 | # Any errors in version inconsistency will be handled through normal error handling if not defined. |
| 73 | version = get_version() |
| 74 | |
| 75 | if version is not None: |
| 76 | version_major_and_minor = version.rsplit('.', 1)[0] |
| 77 | |
| 78 | if sys.modules[namespace].__archinstall__version__ < float(version_major_and_minor): |
| 79 | error(f'Plugin {sys.modules[namespace]} does not support the current Archinstall version.') |
| 80 | |
| 81 | # Locate the plugin entry-point called Plugin() |
| 82 | # This in accordance with the entry_points() from setup.cfg above |
| 83 | if hasattr(sys.modules[namespace], 'Plugin'): |
| 84 | try: |
| 85 | plugins[namespace] = sys.modules[namespace].Plugin() |
| 86 | info(f'Plugin {plugins[namespace]} has been loaded.') |
| 87 | except Exception as err: |
| 88 | error( |
| 89 | f'Error: {err}', |
| 90 | f'The above error was detected when initiating the plugin: {path}', |
| 91 | ) |
| 92 | else: |
| 93 | warn(f"Plugin '{path}' is missing a valid entry-point or is corrupt.") |
no test coverage detected