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 <noreply@anthropic.com>
This commit is contained in:
XPS\Micro 2026-02-01 11:45:40 +01:00
parent b41fd980ce
commit ed36e39e29

View File

@ -99,35 +99,10 @@ class Config:
print(f"[CONFIG] Warnung: Fehler beim Laden von templates.json: {e}", file=sys.stderr) print(f"[CONFIG] Warnung: Fehler beim Laden von templates.json: {e}", file=sys.stderr)
return {} return {}
@staticmethod # Temp-Variablen für Template-Loading (werden nach Klasse verarbeitet)
def _build_container_templates() -> dict: TEMPLATE_IMAGES = None
""" TEMPLATES_CONFIG = None
Baut CONTAINER_TEMPLATES Dictionary aus: CONTAINER_TEMPLATES = None
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__()
# ======================================== # ========================================
# Traefik/Domain-Konfiguration # Traefik/Domain-Konfiguration
@ -215,6 +190,23 @@ class TestingConfig(Config):
WTF_CSRF_ENABLED = False 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-Dict für einfaches Laden
config = { config = {
'development': DevelopmentConfig, 'development': DevelopmentConfig,