Files
lucioandClaude Opus 5.5 60532a4043 Rebuild the UI on vendored Textual; make the checkout self-contained
The internal servers have no access to outside package repositories and
run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual
6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python
dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a
plain checkout runs with no pip and no network.

- dsflow/: the single script split into a package (pure moves of the
  backend sections); action rules moved to ops.py, free of Textual
- dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer,
  modal dialogs, filter, themes, mouse support
- tests/test_ui.py: headless UI tests through Textual's pilot
- tools/vendor.py (refresh vendor/), tools/screenshots.py (README images)
- README, CLAUDE.md, TODO and the feature doc updated for the new layout,
  the Python 3.8.1 floor and the vendoring rules

Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set
runs under `python -I -S` on both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-24 03:24:21 -07:00

97 lines
2.7 KiB
Python
Vendored

from __future__ import annotations
import asyncio
from functools import partial
from inspect import isawaitable, signature
from typing import TYPE_CHECKING, Any, Callable
from textual import active_app
if TYPE_CHECKING:
from textual.app import App
# Maximum seconds before warning about a slow callback
INVOKE_TIMEOUT_WARNING = 3
def count_parameters(func: Callable) -> int:
"""Count the number of parameters in a callable"""
try:
return func._param_count
except AttributeError:
pass
if isinstance(func, partial):
param_count = _count_parameters(func.func) - (
len(func.args) + len(func.keywords)
)
elif hasattr(func, "__self__"):
# Bound method
func = func.__func__ # type: ignore
param_count = _count_parameters(func) - 1
else:
param_count = _count_parameters(func)
try:
func._param_count = param_count
except TypeError:
pass
return param_count
def _count_parameters(func: Callable) -> int:
"""Count the number of parameters in a callable"""
return len(signature(func).parameters)
async def _invoke(callback: Callable, *params: object) -> Any:
"""Invoke a callback with an arbitrary number of parameters.
Args:
callback: The callable to be invoked.
Returns:
The return value of the invoked callable.
"""
_rich_traceback_guard = True
parameter_count = count_parameters(callback)
result = callback(*params[:parameter_count])
if isawaitable(result):
result = await result
return result
async def invoke(callback: Callable[..., Any], *params: object) -> Any:
"""Invoke a callback with an arbitrary number of parameters.
Args:
callback: The callable to be invoked.
Returns:
The return value of the invoked callable.
"""
app: App | None
try:
app = active_app.get()
except LookupError:
# May occur if this method is called outside of an app context (i.e. in a unit test)
app = None
if app is not None and "debug" in app.features:
# In debug mode we will warn about callbacks that may be stuck
def log_slow() -> None:
"""Log a message regarding a slow callback."""
assert app is not None
app.log.warning(
f"Callback {callback} is still pending after {INVOKE_TIMEOUT_WARNING} seconds"
)
call_later_handle = asyncio.get_running_loop().call_later(
INVOKE_TIMEOUT_WARNING, log_slow
)
try:
return await _invoke(callback, *params)
finally:
call_later_handle.cancel()
else:
return await _invoke(callback, *params)