WIP: I HATE PYTHON

This commit is contained in:
2026-03-05 13:55:40 -05:00
parent 107608cd76
commit 5e69617f88
43 changed files with 1854 additions and 1671 deletions

View File

@@ -1,13 +1,13 @@
"""
Decoupled event emission system for cross-module communication.
"""
import asyncio
import queue
from typing import Callable, Any, Dict, List, Tuple
class EventEmitter:
"""
Simple event emitter for decoupled communication between modules.
"""
Simple event emitter for decoupled communication between modules.
"""
def __init__(self) -> None:
"""Initializes the EventEmitter with an empty listener map."""
@@ -15,25 +15,25 @@ class EventEmitter:
def on(self, event_name: str, callback: Callable[..., Any]) -> None:
"""
Registers a callback for a specific event.
Args:
event_name: The name of the event to listen for.
callback: The function to call when the event is emitted.
"""
Registers a callback for a specific event.
Args:
event_name: The name of the event to listen for.
callback: The function to call when the event is emitted.
"""
if event_name not in self._listeners:
self._listeners[event_name] = []
self._listeners[event_name].append(callback)
def emit(self, event_name: str, *args: Any, **kwargs: Any) -> None:
"""
Emits an event, calling all registered callbacks.
Args:
event_name: The name of the event to emit.
*args: Positional arguments to pass to callbacks.
**kwargs: Keyword arguments to pass to callbacks.
"""
Emits an event, calling all registered callbacks.
Args:
event_name: The name of the event to emit.
*args: Positional arguments to pass to callbacks.
**kwargs: Keyword arguments to pass to callbacks.
"""
if event_name in self._listeners:
for callback in self._listeners[event_name]:
callback(*args, **kwargs)
@@ -42,46 +42,46 @@ class EventEmitter:
"""Clears all registered listeners."""
self._listeners.clear()
class AsyncEventQueue:
class SyncEventQueue:
"""
Synchronous event queue for decoupled communication using queue.Queue.
"""
Asynchronous event queue for decoupled communication using asyncio.Queue.
"""
def __init__(self) -> None:
"""Initializes the AsyncEventQueue with an internal asyncio.Queue."""
self._queue: asyncio.Queue[Tuple[str, Any]] = asyncio.Queue()
"""Initializes the SyncEventQueue with an internal queue.Queue."""
self._queue: queue.Queue[Tuple[str, Any]] = queue.Queue()
async def put(self, event_name: str, payload: Any = None) -> None:
def put(self, event_name: str, payload: Any = None) -> None:
"""
Puts an event into the queue.
Args:
event_name: The name of the event.
payload: Optional data associated with the event.
"""
await self._queue.put((event_name, payload))
Puts an event into the queue.
Args:
event_name: The name of the event.
payload: Optional data associated with the event.
"""
self._queue.put((event_name, payload))
async def get(self) -> Tuple[str, Any]:
def get(self) -> Tuple[str, Any]:
"""
Gets an event from the queue.
Returns:
A tuple containing (event_name, payload).
"""
return await self._queue.get()
Gets an event from the queue.
Returns:
A tuple containing (event_name, payload).
"""
return self._queue.get()
def task_done(self) -> None:
"""Signals that a formerly enqueued task is complete."""
self._queue.task_done()
async def join(self) -> None:
def join(self) -> None:
"""Blocks until all items in the queue have been gotten and processed."""
await self._queue.join()
self._queue.join()
class UserRequestEvent:
"""
Payload for a user request event.
"""
Payload for a user request event.
"""
def __init__(self, prompt: str, stable_md: str, file_items: List[Any], disc_text: str, base_dir: str) -> None:
self.prompt = prompt