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]>
86 lines
2.5 KiB
Python
Vendored
86 lines
2.5 KiB
Python
Vendored
from __future__ import annotations
|
|
|
|
from asyncio import Future, gather
|
|
from typing import TYPE_CHECKING, Any, Awaitable, Generator
|
|
|
|
import rich.repr
|
|
from typing_extensions import Self
|
|
|
|
from textual._debug import get_caller_file_and_line
|
|
from textual.message_pump import MessagePump
|
|
|
|
if TYPE_CHECKING:
|
|
from textual.types import CallbackType
|
|
|
|
|
|
@rich.repr.auto(angular=True)
|
|
class AwaitComplete:
|
|
"""An 'optionally-awaitable' object which runs one or more coroutines (or other awaitables) concurrently."""
|
|
|
|
def __init__(
|
|
self, *awaitables: Awaitable, pre_await: CallbackType | None = None
|
|
) -> None:
|
|
"""Create an AwaitComplete.
|
|
|
|
Args:
|
|
awaitables: One or more awaitables to run concurrently.
|
|
"""
|
|
self._awaitables = awaitables
|
|
self._future: Future[Any] = gather(*awaitables)
|
|
self._pre_await: CallbackType | None = pre_await
|
|
self._caller = get_caller_file_and_line()
|
|
|
|
def __rich_repr__(self) -> rich.repr.Result:
|
|
yield self._awaitables
|
|
yield "pre_await", self._pre_await, None
|
|
yield "caller", self._caller, None
|
|
|
|
def set_pre_await_callback(self, pre_await: CallbackType | None) -> None:
|
|
"""Set a callback to run prior to awaiting.
|
|
|
|
This is used by Textual, mainly to check for possible deadlocks.
|
|
You are unlikely to need to call this method in an app.
|
|
|
|
Args:
|
|
pre_await: A callback.
|
|
"""
|
|
self._pre_await = pre_await
|
|
|
|
def call_next(self, node: MessagePump) -> Self:
|
|
"""Await after the next message.
|
|
|
|
Args:
|
|
node: The node which created the object.
|
|
"""
|
|
node.call_next(self)
|
|
return self
|
|
|
|
async def __call__(self) -> Any:
|
|
return await self
|
|
|
|
def __await__(self) -> Generator[Any, None, Any]:
|
|
_rich_traceback_omit = True
|
|
if self._pre_await is not None:
|
|
self._pre_await()
|
|
return self._future.__await__()
|
|
|
|
@property
|
|
def is_done(self) -> bool:
|
|
"""`True` if the task has completed."""
|
|
return self._future.done()
|
|
|
|
@property
|
|
def exception(self) -> BaseException | None:
|
|
"""An exception if the awaitables failed."""
|
|
if self._future.done():
|
|
return self._future.exception()
|
|
return None
|
|
|
|
@classmethod
|
|
def nothing(cls):
|
|
"""Returns an already completed instance of AwaitComplete."""
|
|
instance = cls()
|
|
instance._future = Future()
|
|
instance._future.set_result(None) # Mark it as completed with no result
|
|
return instance
|