|
3 | 3 | import os |
4 | 4 | import sys |
5 | 5 | import traceback |
| 6 | +import inspect |
6 | 7 | from importlib import util |
7 | 8 | from typing import Callable, Dict, List, Union |
8 | 9 |
|
@@ -269,15 +270,26 @@ def find_extensions_in_file(extension_path: str, module_name="extensions") -> li |
269 | 270 | else: |
270 | 271 | # TODO: Add documentation links to warnings |
271 | 272 | if hasattr(mod, "LABTHINGS_EXTENSIONS"): |
272 | | - return [ |
273 | | - ext_class() |
274 | | - for ext_class in getattr(mod, "LABTHINGS_EXTENSIONS") |
275 | | - if issubclass(ext_class, BaseExtension) |
276 | | - ] |
| 273 | + ext_objects = [] |
| 274 | + for ext_element in getattr(mod, "LABTHINGS_EXTENSIONS"): |
| 275 | + if inspect.isclass(ext_element) and issubclass( |
| 276 | + ext_element, BaseExtension |
| 277 | + ): |
| 278 | + ext_objects.append(ext_element()) |
| 279 | + elif isinstance(ext_element, BaseExtension): |
| 280 | + logging.warning( |
| 281 | + "%s: Extension instance passed instead of class. LABTHINGS_EXTENSIONS should contain classes, not instances.", |
| 282 | + ext_element, |
| 283 | + ) |
| 284 | + ext_objects.append(ext_element) |
| 285 | + else: |
| 286 | + logging.error( |
| 287 | + "Unsupported extension type %s. Skipping.", type(ext_element) |
| 288 | + ) |
| 289 | + return ext_objects |
277 | 290 | elif hasattr(mod, "__extensions__"): |
278 | 291 | logging.warning( |
279 | | - "Explicit extension list using the __extensions__ global is deprecated.", |
280 | | - "Please use LABTHINGS_EXTENSIONS instead.", |
| 292 | + "Explicit extension list using the __extensions__ global is deprecated. Please use LABTHINGS_EXTENSIONS instead." |
281 | 293 | ) |
282 | 294 | return [ |
283 | 295 | getattr(mod, ext_name) for ext_name in getattr(mod, "__extensions__") |
|
0 commit comments