From 65e9cd663838055d5a9ce4ebe45fc92e790453f3 Mon Sep 17 00:00:00 2001 From: Drac Date: Mon, 16 Jun 2025 19:40:59 +0200 Subject: [PATCH] refactor: improve __init__.py a bit --- __init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 6943315..556cd7c 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,6 @@ import importlib +import logging +import os from .pyserver import ( get_key_from_jssetting, # noqa: F401 @@ -23,13 +25,15 @@ NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} for module_name in node_list: - imported_module = importlib.import_module(f".nodes.{module_name}", __name__) - - NODE_CLASS_MAPPINGS = {**NODE_CLASS_MAPPINGS, **imported_module.NODE_CLASS_MAPPINGS} - NODE_DISPLAY_NAME_MAPPINGS = {**NODE_DISPLAY_NAME_MAPPINGS, **imported_module.NODE_DISPLAY_NAME_MAPPINGS} + try: + imported_module = importlib.import_module(f".nodes.{module_name}", __name__) + NODE_CLASS_MAPPINGS.update(imported_module.NODE_CLASS_MAPPINGS) + NODE_DISPLAY_NAME_MAPPINGS.update(imported_module.NODE_DISPLAY_NAME_MAPPINGS) + except ImportError as e: + logging.warning(f"Could not import module '{module_name}': {e}") -WEB_DIRECTORY = "./js" +WEB_DIRECTORY = os.path.join(os.path.dirname(__file__), "js") __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]