|
12 | 12 | import sys
|
13 | 13 | import inspect
|
14 | 14 | from typing import List
|
| 15 | +from pathlib import Path |
15 | 16 |
|
16 | 17 | from pfdl_scheduler.pfdl_base_classes import PFDLBaseClasses
|
17 | 18 |
|
18 | 19 | base_classes_registry = {}
|
19 | 20 |
|
20 |
| -PLUGIN_FOLDER_PATH = "./pfdl_scheduler/plugins" |
21 |
| - |
22 | 21 |
|
23 | 22 | def base_class(existing_class_name):
|
24 | 23 | """A Decorator to mark a class that will extend an existing class.
|
@@ -160,16 +159,18 @@ def load_plugin_modules(self, module_name, module_path):
|
160 | 159 | def load_plugins(self, plugins: List[str]):
|
161 | 160 | """Recursively load all Python files from plugin folders."""
|
162 | 161 | for plugin_folder in plugins:
|
163 |
| - plugin_path = os.path.join(PLUGIN_FOLDER_PATH, plugin_folder) |
164 |
| - |
165 |
| - if os.path.isdir(plugin_path): |
166 |
| - # Walk through all files in the plugin folder |
167 |
| - for root, _, files in os.walk(plugin_path): |
168 |
| - for file in files: |
169 |
| - if file.endswith(".py"): |
170 |
| - module_name = f"{plugin_folder}.{file[:-3]}" # Plugin folder + filename without .py |
171 |
| - module_path = os.path.join(root, file) |
172 |
| - self.load_plugin_modules(module_name, module_path) |
| 162 | + plugin_path = Path(__file__).parent / plugin_folder |
| 163 | + |
| 164 | + if not plugin_path.is_dir(): |
| 165 | + raise ValueError("given plugin could not be found") |
| 166 | + |
| 167 | + # Walk through all files in the plugin folder |
| 168 | + for root, _, files in os.walk(plugin_path): |
| 169 | + for file in files: |
| 170 | + if file.endswith(".py"): |
| 171 | + module_name = f"{plugin_folder}.{file[:-3]}" # Plugin folder + filename without .py |
| 172 | + module_path = os.path.join(root, file) |
| 173 | + self.load_plugin_modules(module_name, module_path) |
173 | 174 |
|
174 | 175 | def get_final_classes(self):
|
175 | 176 | """Return a dictionary of final classes after applying plugins."""
|
|
0 commit comments