mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
Using TYPE_CHECKING for type hints
Moving runtime imports to appropriate locations Using string literal type annotations Importing shared utilities through the utils package
This commit is contained in:
@@ -15,10 +15,13 @@ from typing import (
|
||||
Callable,
|
||||
Awaitable,
|
||||
Tuple,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from ..processor.queue_handler import QueueHandler
|
||||
if TYPE_CHECKING:
|
||||
from ..processor.queue_handler import QueueHandler
|
||||
|
||||
from ..ffmpeg.ffmpeg_manager import FFmpegManager
|
||||
from ..utils.exceptions import CleanupError
|
||||
|
||||
@@ -192,7 +195,7 @@ class CleanupManager:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
queue_handler: QueueHandler,
|
||||
queue_handler: "QueueHandler",
|
||||
ffmpeg_mgr: Optional[FFmpegManager] = None,
|
||||
strategy: CleanupStrategy = CleanupStrategy.NORMAL,
|
||||
) -> None:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Tuple
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Tuple, TYPE_CHECKING
|
||||
|
||||
import discord # type: ignore
|
||||
from discord.ext import commands # type: ignore
|
||||
@@ -15,14 +15,15 @@ from ..core.types import (
|
||||
ProcessorState,
|
||||
ComponentStatus,
|
||||
)
|
||||
from ..processor.cleanup_manager import CleanupManager, CleanupStrategy
|
||||
from ..processor.constants import REACTIONS
|
||||
from ..processor.message_handler import MessageHandler
|
||||
from ..processor.queue_handler import QueueHandler
|
||||
from ..processor.status_display import StatusDisplay
|
||||
from ..utils import progress_tracker
|
||||
from ..utils.exceptions import ProcessorError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..processor.cleanup_manager import CleanupManager
|
||||
from ..processor.message_handler import MessageHandler
|
||||
from ..processor.queue_handler import QueueHandler
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
|
||||
@@ -171,10 +172,15 @@ class VideoProcessor(IComponent):
|
||||
self.health_monitor = HealthMonitor(self)
|
||||
|
||||
try:
|
||||
# Import handlers here to avoid circular imports
|
||||
from ..processor.queue_handler import QueueHandler
|
||||
from ..processor.message_handler import MessageHandler
|
||||
from ..processor.cleanup_manager import CleanupManager, CleanupStrategy
|
||||
|
||||
# Initialize handlers
|
||||
self.queue_handler = QueueHandler(bot, config_manager, components)
|
||||
self.message_handler = MessageHandler(bot, config_manager, queue_manager)
|
||||
self.cleanup_manager = CleanupManager(
|
||||
self.queue_handler: "QueueHandler" = QueueHandler(bot, config_manager, components)
|
||||
self.message_handler: "MessageHandler" = MessageHandler(bot, config_manager, queue_manager)
|
||||
self.cleanup_manager: "CleanupManager" = CleanupManager(
|
||||
self.queue_handler, ffmpeg_mgr, CleanupStrategy.NORMAL
|
||||
)
|
||||
|
||||
@@ -292,6 +298,9 @@ class VideoProcessor(IComponent):
|
||||
# Get active operations
|
||||
active_ops = self.operation_tracker.get_active_operations()
|
||||
|
||||
# Import StatusDisplay here to avoid circular imports
|
||||
from ..processor.status_display import StatusDisplay
|
||||
|
||||
# Create and send status embed
|
||||
embed = await StatusDisplay.create_queue_status_embed(
|
||||
queue_status, active_ops
|
||||
|
||||
@@ -4,7 +4,7 @@ import asyncio
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from enum import auto, Enum
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple, TypedDict
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple, TypedDict, TYPE_CHECKING
|
||||
|
||||
import discord # type: ignore
|
||||
from discord.ext import commands # type: ignore
|
||||
@@ -14,9 +14,11 @@ from ..processor.constants import REACTIONS
|
||||
from ..processor.message_validator import MessageValidator, ValidationError
|
||||
from ..processor.url_extractor import URLExtractor, URLMetadata
|
||||
from ..queue.types import QueuePriority
|
||||
from ..queue.manager import EnhancedVideoQueueManager
|
||||
from ..utils.exceptions import MessageHandlerError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..queue.manager import EnhancedVideoQueueManager
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
|
||||
@@ -207,7 +209,7 @@ class MessageHandler:
|
||||
self,
|
||||
bot: discord.Client,
|
||||
config_manager: ConfigManager,
|
||||
queue_manager: EnhancedVideoQueueManager,
|
||||
queue_manager: "EnhancedVideoQueueManager",
|
||||
) -> None:
|
||||
self.bot = bot
|
||||
self.config_manager = config_manager
|
||||
|
||||
@@ -8,7 +8,7 @@ from typing import Optional, Dict, Any, List, Tuple, Set, TypedDict, ClassVar, C
|
||||
from datetime import datetime
|
||||
import discord # type: ignore
|
||||
|
||||
from ..utils import progress_tracker
|
||||
from .. import utils # Import the utils package
|
||||
from ..database.video_archive_db import VideoArchiveDB
|
||||
from ..utils.download_manager import DownloadManager
|
||||
from ..utils.message_manager import MessageManager
|
||||
@@ -378,7 +378,7 @@ class QueueHandler:
|
||||
return
|
||||
|
||||
# Update progress tracking
|
||||
progress_tracker.update_download_progress(
|
||||
utils.progress_tracker.update_download_progress(
|
||||
url,
|
||||
{
|
||||
"percent": progress,
|
||||
@@ -425,9 +425,9 @@ class QueueHandler:
|
||||
download_task, timeout=self.DOWNLOAD_TIMEOUT
|
||||
)
|
||||
if success:
|
||||
progress_tracker.complete_download(url)
|
||||
utils.progress_tracker.complete_download(url)
|
||||
else:
|
||||
progress_tracker.increment_download_retries(url)
|
||||
utils.progress_tracker.increment_download_retries(url)
|
||||
return success, file_path, error
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Enhanced queue manager for video processing"""
|
||||
|
||||
import asyncio
|
||||
from enum import Enum
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional, Tuple, Dict, Any, List, Set, Callable
|
||||
|
||||
Reference in New Issue
Block a user