MCPcopy Create free account
hub / github.com/archlinux/archinstall / _import_via_path

Function _import_via_path

archinstall/lib/plugins.py:34–60  ·  view source on GitHub ↗
(path: Path, namespace: str | None = None)

Source from the content-addressed store, hash-verified

32
33
34def _import_via_path(path: Path, namespace: str | None = None) -> str:
35 if not namespace:
36 namespace = os.path.basename(path)
37
38 if namespace == '__init__.py':
39 namespace = path.parent.name
40
41 try:
42 spec = importlib.util.spec_from_file_location(namespace, path)
43 if spec and spec.loader:
44 imported = importlib.util.module_from_spec(spec)
45 sys.modules[namespace] = imported
46 spec.loader.exec_module(sys.modules[namespace])
47
48 return namespace
49 except Exception as err:
50 error(
51 f'Error: {err}',
52 f'The above error was detected when loading the plugin: {path}',
53 )
54
55 try:
56 del sys.modules[namespace]
57 except Exception:
58 pass
59
60 return namespace
61
62
63def load_plugin(path: Path) -> None:

Callers 1

load_pluginFunction · 0.85

Calls 1

errorFunction · 0.90

Tested by

no test coverage detected