Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

fix: allow plugins to import local modules

author: pi66
date: 2026-07-04 14:31
hash: d65963d9dca2474f7a1503f785597ed6e408211b

Diffstat:

M

src/build.py
4 ++++++++++++++++++++++++++++++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
diff --git a/src/build.py b/src/build.py
index 5ef9b87..cf4bbfb 100644
--- a/src/build.py
+++ b/src/build.py
@@ -26,6 +26,8 @@ replace_filters = [
 ]

 def load_plugins(path):
+    module_dir = dirname(abspath(path))
+    sys.path.insert(0, module_dir)
     try:
         spec = importlib.util.spec_from_file_location("plugins", path)
         module = importlib.util.module_from_spec(spec)
@@ -39,6 +41,8 @@ def load_plugins(path):

     except Exception as e:
         raise RuntimeError(f"Failed loading plugin {path}: {e}") from e
+    finally:
+        sys.path.pop(0)


 def html_filter(html_content:str):