Add YAPF style + ignore, and format tracked Python files

This commit is contained in:
2025-12-29 18:42:02 -08:00
parent c019c00aed
commit 507946a3e4
108 changed files with 11664 additions and 6494 deletions

View File

@@ -21,7 +21,9 @@ class WorkersModal(ModalScreen):
"""Modal screen for monitoring running and finished workers."""
BINDINGS = [
Binding("escape", "cancel", "Cancel"),
Binding("escape",
"cancel",
"Cancel"),
]
CSS_PATH = "workers.tcss"
@@ -72,7 +74,11 @@ class WorkersModal(ModalScreen):
with Horizontal(id="running-controls"):
yield Button("Refresh", id="running-refresh-btn", variant="primary")
yield Button("Stop Selected", id="running-stop-btn", variant="warning")
yield Button(
"Stop Selected",
id="running-stop-btn",
variant="warning"
)
yield Button("Stop All", id="running-stop-all-btn", variant="error")
# Finished tab content (initially visible)
@@ -81,9 +87,21 @@ class WorkersModal(ModalScreen):
yield self.finished_table
with Horizontal(id="finished-controls"):
yield Button("Refresh", id="finished-refresh-btn", variant="primary")
yield Button("Clear Selected", id="finished-clear-btn", variant="warning")
yield Button("Clear All", id="finished-clear-all-btn", variant="error")
yield Button(
"Refresh",
id="finished-refresh-btn",
variant="primary"
)
yield Button(
"Clear Selected",
id="finished-clear-btn",
variant="warning"
)
yield Button(
"Clear All",
id="finished-clear-all-btn",
variant="error"
)
# Shared textarea for displaying worker logs
with Vertical(id="logs-section"):
@@ -99,14 +117,27 @@ class WorkersModal(ModalScreen):
# Set up running workers table
if self.running_table:
self.running_table.add_columns(
"ID", "Type", "Status", "Pipe", "Progress", "Started", "Details"
"ID",
"Type",
"Status",
"Pipe",
"Progress",
"Started",
"Details"
)
self.running_table.zebra_stripes = True
# Set up finished workers table
if self.finished_table:
self.finished_table.add_columns(
"ID", "Type", "Result", "Pipe", "Started", "Completed", "Duration", "Details"
"ID",
"Type",
"Result",
"Pipe",
"Started",
"Completed",
"Duration",
"Details"
)
self.finished_table.zebra_stripes = True
@@ -199,7 +230,13 @@ class WorkersModal(ModalScreen):
if not self.running_workers:
self.running_table.add_row(
"---", "---", "---", "---", "---", "---", "No workers running"
"---",
"---",
"---",
"---",
"---",
"---",
"No workers running"
)
logger.debug(f"[workers-modal] No running workers to display")
return
@@ -257,7 +294,10 @@ class WorkersModal(ModalScreen):
f"[workers-modal] Updated running table with {len(self.running_workers)} workers"
)
except Exception as e:
logger.error(f"[workers-modal] Error updating running table: {e}", exc_info=True)
logger.error(
f"[workers-modal] Error updating running table: {e}",
exc_info=True
)
def _update_finished_table(self) -> None:
"""Update the finished workers table."""
@@ -270,7 +310,14 @@ class WorkersModal(ModalScreen):
if not self.finished_workers:
self.finished_table.add_row(
"---", "---", "---", "---", "---", "---", "---", "No finished workers"
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"No finished workers"
)
logger.debug(f"[workers-modal] No finished workers to display")
return
@@ -336,12 +383,17 @@ class WorkersModal(ModalScreen):
f"[workers-modal-update] Finished table row_count after update: {self.finished_table.row_count}"
)
except Exception as e:
logger.error(f"[workers-modal] Error updating finished table: {e}", exc_info=True)
logger.error(
f"[workers-modal] Error updating finished table: {e}",
exc_info=True
)
def on_data_table_row_highlighted(self, event: DataTable.RowHighlighted) -> None:
"""Handle row highlight in tables - display stdout."""
try:
logger.info(f"[workers-modal] Row highlighted, cursor_row: {event.cursor_row}")
logger.info(
f"[workers-modal] Row highlighted, cursor_row: {event.cursor_row}"
)
# Get the selected worker from the correct table
workers_list = None
@@ -372,7 +424,10 @@ class WorkersModal(ModalScreen):
f"[workers-modal] Row {event.cursor_row} out of bounds for list of size {len(workers_list) if workers_list else 0}"
)
except Exception as e:
logger.error(f"[workers-modal] Error handling row highlight: {e}", exc_info=True)
logger.error(
f"[workers-modal] Error handling row highlight: {e}",
exc_info=True
)
def on_data_table_cell_highlighted(self, event: DataTable.CellHighlighted) -> None:
"""Handle cell highlight in tables - display stdout (backup for row selection)."""
@@ -410,14 +465,19 @@ class WorkersModal(ModalScreen):
logger.debug(f"[workers-modal] Error handling cell highlight: {e}")
def _update_stdout_display(
self, worker_id: str, worker: Optional[Dict[str, Any]] = None
self,
worker_id: str,
worker: Optional[Dict[str,
Any]] = None
) -> None:
"""Update the stdout textarea with logs from the selected worker."""
try:
if not self.stdout_display:
logger.error("[workers-modal] stdout_display not initialized")
return
logger.debug(f"[workers-modal] Updating stdout display for worker: {worker_id}")
logger.debug(
f"[workers-modal] Updating stdout display for worker: {worker_id}"
)
worker_data = worker or self._locate_worker(worker_id)
stdout_text = self._resolve_worker_stdout(worker_id, worker_data)
pipe_text = self._resolve_worker_pipe(worker_id, worker_data)
@@ -429,7 +489,9 @@ class WorkersModal(ModalScreen):
if timeline_text:
sections.append("Timeline:\n" + timeline_text)
logs_body = (stdout_text or "").strip()
sections.append("Logs:\n" + (logs_body if logs_body else "(no logs recorded)"))
sections.append(
"Logs:\n" + (logs_body if logs_body else "(no logs recorded)")
)
combined_text = "\n\n".join(sections)
logger.debug(
f"[workers-modal] Setting textarea to {len(combined_text)} chars (stdout_len={len(stdout_text or '')})"
@@ -442,7 +504,10 @@ class WorkersModal(ModalScreen):
pass
logger.info(f"[workers-modal] Updated stdout display successfully")
except Exception as e:
logger.error(f"[workers-modal] Error updating stdout display: {e}", exc_info=True)
logger.error(
f"[workers-modal] Error updating stdout display: {e}",
exc_info=True
)
def _locate_worker(self, worker_id: str) -> Optional[Dict[str, Any]]:
for worker in self.running_workers or []:
@@ -453,7 +518,12 @@ class WorkersModal(ModalScreen):
return worker
return None
def _resolve_worker_stdout(self, worker_id: str, worker: Optional[Dict[str, Any]]) -> str:
def _resolve_worker_stdout(
self,
worker_id: str,
worker: Optional[Dict[str,
Any]]
) -> str:
if worker and worker.get("stdout"):
return worker.get("stdout", "") or ""
manager = getattr(self.app_instance, "worker_manager", None)
@@ -461,10 +531,17 @@ class WorkersModal(ModalScreen):
try:
return manager.get_stdout(worker_id) or ""
except Exception as exc:
logger.debug(f"[workers-modal] Could not fetch stdout for {worker_id}: {exc}")
logger.debug(
f"[workers-modal] Could not fetch stdout for {worker_id}: {exc}"
)
return ""
def _resolve_worker_pipe(self, worker_id: str, worker: Optional[Dict[str, Any]]) -> str:
def _resolve_worker_pipe(
self,
worker_id: str,
worker: Optional[Dict[str,
Any]]
) -> str:
if worker and worker.get("pipe"):
return str(worker.get("pipe"))
record = self._fetch_worker_record(worker_id)
@@ -479,17 +556,24 @@ class WorkersModal(ModalScreen):
try:
return manager.get_worker(worker_id)
except Exception as exc:
logger.debug(f"[workers-modal] Could not fetch worker record {worker_id}: {exc}")
logger.debug(
f"[workers-modal] Could not fetch worker record {worker_id}: {exc}"
)
return None
def _get_worker_events(self, worker_id: str, limit: int = 250) -> List[Dict[str, Any]]:
def _get_worker_events(self,
worker_id: str,
limit: int = 250) -> List[Dict[str,
Any]]:
manager = getattr(self.app_instance, "worker_manager", None)
if not manager:
return []
try:
return manager.get_worker_events(worker_id, limit=limit)
except Exception as exc:
logger.debug(f"[workers-modal] Could not fetch worker events {worker_id}: {exc}")
logger.debug(
f"[workers-modal] Could not fetch worker events {worker_id}: {exc}"
)
return []
def _format_worker_timeline(self, events: List[Dict[str, Any]]) -> str:
@@ -540,7 +624,7 @@ class WorkersModal(ModalScreen):
text = str(pipe_value or "").strip()
if not text:
return "(none)"
return text if len(text) <= limit else text[: limit - 3] + "..."
return text if len(text) <= limit else text[:limit - 3] + "..."
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Handle button presses."""
@@ -568,9 +652,12 @@ class WorkersModal(ModalScreen):
if 0 <= selected_row < len(self.running_workers):
worker = self.running_workers[selected_row]
worker_id = worker.get("id")
if self.app_instance and hasattr(self.app_instance, "stop_worker"):
if self.app_instance and hasattr(self.app_instance,
"stop_worker"):
self.app_instance.stop_worker(worker_id)
logger.info(f"[workers-modal] Stopped worker: {worker_id}")
logger.info(
f"[workers-modal] Stopped worker: {worker_id}"
)
self.refresh_workers()
except Exception as e:
logger.error(f"[workers-modal] Error stopping worker: {e}")
@@ -593,18 +680,20 @@ class WorkersModal(ModalScreen):
if 0 <= selected_row < len(self.finished_workers):
worker = self.finished_workers[selected_row]
worker_id = worker.get("id")
if self.app_instance and hasattr(
self.app_instance, "clear_finished_worker"
):
if self.app_instance and hasattr(self.app_instance,
"clear_finished_worker"):
self.app_instance.clear_finished_worker(worker_id)
logger.info(f"[workers-modal] Cleared worker: {worker_id}")
logger.info(
f"[workers-modal] Cleared worker: {worker_id}"
)
self.refresh_workers()
except Exception as e:
logger.error(f"[workers-modal] Error clearing worker: {e}")
elif button_id == "finished-clear-all-btn":
# Clear all finished workers
if self.app_instance and hasattr(self.app_instance, "clear_all_finished_workers"):
if self.app_instance and hasattr(self.app_instance,
"clear_all_finished_workers"):
self.app_instance.clear_all_finished_workers()
logger.info("[workers-modal] Cleared all finished workers")
self.refresh_workers()