fix(core): add fallback to absolute imports in initialization.py

This commit is contained in:
pacnpal
2024-11-17 22:13:51 +00:00
parent e01d89bd94
commit ba6eb11e81

View File

@@ -4,18 +4,24 @@ from typing import TYPE_CHECKING, Optional, Dict, Any
import asyncio import asyncio
import logging import logging
from ..utils.exceptions import ( try:
ComponentError, # Try relative imports first
ErrorContext, from ..utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
ErrorSeverity from .lifecycle import LifecycleState
) except ImportError:
from ..core.lifecycle import LifecycleState # Fall back to absolute imports if relative imports fail
from videoarchiver.utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
from videoarchiver.core.lifecycle import LifecycleState
if TYPE_CHECKING: if TYPE_CHECKING:
from ..core.base import VideoArchiver try:
from .base import VideoArchiver
except ImportError:
from videoarchiver.core.base import VideoArchiver
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
async def initialize_cog(cog: "VideoArchiver") -> None: async def initialize_cog(cog: "VideoArchiver") -> None:
""" """
Initialize all components with proper error handling. Initialize all components with proper error handling.
@@ -46,6 +52,7 @@ async def initialize_cog(cog: "VideoArchiver") -> None:
) )
) )
def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None: def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None:
""" """
Handle initialization task completion. Handle initialization task completion.
@@ -74,6 +81,7 @@ def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None:
logger.error(f"Error in initialization callback: {str(e)}", exc_info=True) logger.error(f"Error in initialization callback: {str(e)}", exc_info=True)
# We don't raise here since this is a callback # We don't raise here since this is a callback
def get_init_status(cog: "VideoArchiver") -> Dict[str, Any]: def get_init_status(cog: "VideoArchiver") -> Dict[str, Any]:
""" """
Get initialization status information. Get initialization status information.