Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/plugins.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds@gmail.com>2021-05-24 14:12:23 +0200
committerAnton Hvornum <anton.feeds@gmail.com>2021-05-24 14:12:23 +0200
commit250eb93f103acc6110782aad4f897edfc1781bd6 (patch)
tree8f96e6327080f070378c239aadae70c377f84391 /archinstall/lib/plugins.py
parentc7426067dd828697fc4b7e4157e811ddd9c4eb36 (diff)
Added better error handling.
Diffstat (limited to 'archinstall/lib/plugins.py')
-rw-r--r--archinstall/lib/plugins.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/archinstall/lib/plugins.py b/archinstall/lib/plugins.py
index 9dfa786b..8376f3d5 100644
--- a/archinstall/lib/plugins.py
+++ b/archinstall/lib/plugins.py
@@ -3,6 +3,7 @@ import importlib
import logging
import os
import sys
+import pathlib
import urllib.parse
import urllib.request
from importlib import metadata
@@ -37,17 +38,21 @@ def import_via_path(path :str, namespace=None): # -> module (not sure how to wri
if not namespace:
namespace = os.path.basename(path)
+ if namespace == '__init__.py':
+ path = pathlib.PurePath(path)
+ namespace = path.parent.name
+
try:
spec = importlib.util.spec_from_file_location(namespace, path)
imported = importlib.util.module_from_spec(spec)
sys.modules[namespace] = imported
spec.loader.exec_module(sys.modules[namespace])
+
+ return namespace
except Exception as err:
log(err, level=logging.ERROR)
log(f"The above error was detected when loading the plugin: {path}", fg="red", level=logging.ERROR)
- return sys.modules[namespace]
-
def load_plugin(path :str): # -> module (not sure how to write that in type definitions)
parsed_url = urllib.parse.urlparse(path)
@@ -55,6 +60,12 @@ def load_plugin(path :str): # -> module (not sure how to write that in type defi
if not parsed_url.scheme:
# Path was not found in any known examples, check if it's an absolute path
if os.path.isfile(path):
- return import_via_path(path)
+ namespace = import_via_path(path)
elif parsed_url.scheme in ('https', 'http'):
- return import_via_path(localize_path(path)) \ No newline at end of file
+ namespace = import_via_path(localize_path(path))
+
+ try:
+ plugins[namespace] = sys.modules[namespace].Plugin()
+ except Exception as err:
+ log(err, level=logging.ERROR)
+ log(f"The above error was detected when loading the plugin: {path}", fg="red", level=logging.ERROR) \ No newline at end of file