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]>
75 lines
2.0 KiB
Python
Vendored
75 lines
2.0 KiB
Python
Vendored
from __future__ import annotations
|
|
|
|
from time import monotonic
|
|
from typing import Callable
|
|
|
|
import rich.repr
|
|
|
|
|
|
@rich.repr.auto(angular=True)
|
|
class Clock:
|
|
"""An object to get relative time.
|
|
|
|
The `time` attribute of clock will return the time in seconds since the
|
|
Clock was created or reset.
|
|
|
|
"""
|
|
|
|
def __init__(self, *, get_time: Callable[[], float] = monotonic) -> None:
|
|
"""Create a clock.
|
|
|
|
Args:
|
|
get_time: A callable to get time in seconds.
|
|
start: Start the clock (time is 0 unless clock has been started).
|
|
"""
|
|
self._get_time = get_time
|
|
self._start_time = self._get_time()
|
|
|
|
def __rich_repr__(self) -> rich.repr.Result:
|
|
yield self.time
|
|
|
|
def clone(self) -> Clock:
|
|
"""Clone the Clock with an independent time."""
|
|
return Clock(get_time=self._get_time)
|
|
|
|
def reset(self) -> None:
|
|
"""Reset the clock."""
|
|
self._start_time = self._get_time()
|
|
|
|
@property
|
|
def time(self) -> float:
|
|
"""Time since creation or reset."""
|
|
return self._get_time() - self._start_time
|
|
|
|
|
|
class MockClock(Clock):
|
|
"""A mock clock object where the time may be explicitly set."""
|
|
|
|
def __init__(self, time: float = 0.0) -> None:
|
|
"""Construct a mock clock."""
|
|
self._time = time
|
|
super().__init__(get_time=lambda: self._time)
|
|
|
|
def clone(self) -> MockClock:
|
|
"""Clone the mocked clock (clone will return the same time as original)."""
|
|
clock = MockClock(self._time)
|
|
clock._get_time = self._get_time
|
|
clock._time = self._time
|
|
return clock
|
|
|
|
def reset(self) -> None:
|
|
"""A null-op because it doesn't make sense to reset a mocked clock."""
|
|
|
|
def set_time(self, time: float) -> None:
|
|
"""Set the time for the clock.
|
|
|
|
Args:
|
|
time: Time to set.
|
|
"""
|
|
self._time = time
|
|
|
|
@property
|
|
def time(self) -> float:
|
|
"""Time since creation or reset."""
|
|
return self._get_time()
|