From ed36e39e29b33137a22708a9bd605d1222e470cf Mon Sep 17 00:00:00 2001 From: "XPS\\Micro" Date: Sun, 1 Feb 2026 11:45:40 +0100 Subject: [PATCH] fix: fix template initialization order in Config class - Move template loading after class definition to avoid NameError - Initialize TEMPLATE_IMAGES, TEMPLATES_CONFIG, and CONTAINER_TEMPLATES after Config class - Use simple loop instead of calling static methods during class init - Prevents 'Config is not defined' errors during import This fixes the circular dependency issue where _build_container_templates() was trying to reference Config.TEMPLATE_IMAGES while the class was still being defined. Co-Authored-By: Claude Haiku 4.5 --- config.py | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/config.py b/config.py index e95c7f4..167fdd6 100644 --- a/config.py +++ b/config.py @@ -99,35 +99,10 @@ class Config: print(f"[CONFIG] Warnung: Fehler beim Laden von templates.json: {e}", file=sys.stderr) return {} - @staticmethod - def _build_container_templates() -> dict: - """ - Baut CONTAINER_TEMPLATES Dictionary aus: - 1. TEMPLATE_IMAGES (Liste der verfügbaren Images) - 2. TEMPLATES_CONFIG (Metadaten aus templates.json) - """ - templates = {} - - for image in Config.TEMPLATE_IMAGES: - # Extrahiere Typ aus Image-Namen - container_type = Config._extract_type_from_image(image) - - # Hole Metadaten aus JSON (falls vorhanden) - config = Config.TEMPLATES_CONFIG.get(container_type, {}) - - # Verwende JSON-Metadaten oder Fallback - templates[container_type] = { - 'image': image, - 'display_name': config.get('display_name', container_type.replace('-', ' ').title()), - 'description': config.get('description', f'Container basierend auf {image}') - } - - return templates - - # Dynamisches Template-Loading initialisieren - TEMPLATE_IMAGES = _load_template_images.__func__() - TEMPLATES_CONFIG = _load_templates_config.__func__() - CONTAINER_TEMPLATES = _build_container_templates.__func__() + # Temp-Variablen für Template-Loading (werden nach Klasse verarbeitet) + TEMPLATE_IMAGES = None + TEMPLATES_CONFIG = None + CONTAINER_TEMPLATES = None # ======================================== # Traefik/Domain-Konfiguration @@ -215,6 +190,23 @@ class TestingConfig(Config): WTF_CSRF_ENABLED = False +# Initialisiere Templates NACH Klassendefini tion +Config.TEMPLATE_IMAGES = Config._load_template_images() +Config.TEMPLATES_CONFIG = Config._load_templates_config() + +# Baue CONTAINER_TEMPLATES aus Templates +templates = {} +for image in Config.TEMPLATE_IMAGES: + container_type = Config._extract_type_from_image(image) + config_meta = Config.TEMPLATES_CONFIG.get(container_type, {}) + templates[container_type] = { + 'image': image, + 'display_name': config_meta.get('display_name', container_type.replace('-', ' ').title()), + 'description': config_meta.get('description', f'Container basierend auf {image}') + } +Config.CONTAINER_TEMPLATES = templates + + # Config-Dict für einfaches Laden config = { 'development': DevelopmentConfig,