Files
dssc/dsflow/cli.py
T
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

98 lines
5.3 KiB
Python

"""Command line: argument parsing, `status`, and dispatch to the UI or the runner."""
import argparse
import json
import os
import sys
import tempfile
import time
from .common import JOB_FILE, ME, VERSION, FlowError, fmt_dur, job_state, read_json
from .demo import setup_demo
from .flow import Flow
from .runner import Runner
def cmd_status(flow, as_json):
job = read_json(flow.path(JOB_FILE))
if as_json:
print(json.dumps(dict(state=job_state(job), job=job), indent=1, sort_keys=True))
return 0 if job and job.get("status") in ("passed", "running", "queued") else 1
if not job:
print("no sanity run recorded in %s" % flow.ws)
return 1
st = job_state(job)
label = "RUNNER LOST" if st == "orphaned" else job["status"].upper()
start = job.get("started") or job["created"]
print("run %s %s (%s, elapsed %s)" % (job["id"], label, job.get("host", "?"),
fmt_dur((job.get("finished") or time.time()) - start)))
print("mode: %s%s" % ("check in" if job["mode"] == "checkin" else "unlock only",
", tag %s" % job["tag"] if job.get("tag") else ""))
print("files: %s" % " ".join(job["files"] + job["new_files"]))
if job.get("locked_by_job"):
print("locked by run: %s" % " ".join(job["locked_by_job"]))
for s in job["steps"]:
mark = {"pending": ".", "running": ">", "done": "+", "failed": "x", "cancelled": "-", "skipped": "-"}[s["status"]]
el = ((s.get("t1") or time.time()) - s["t0"]) if s.get("t0") else None
print(" [%s] %-34s %-9s %s" % (mark, s["label"], fmt_dur(el), s.get("detail", "")))
if job.get("summary"):
print(job["summary"])
return 0 if job["status"] in ("passed", "running", "queued") and st != "orphaned" else 1
def main(argv=None):
ap = argparse.ArgumentParser(
prog="dsflow_tui.py", description="Terminal UI for the dsflow DesignSync check-in flow.",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="examples:\n"
" dsflow_tui.py # from the workspace root\n"
" dsflow_tui.py status # progress of the current sanity run\n"
" dsflow_tui.py --sanity-cmd 'sim/regress.sh --cfg {cfg}'\n"
" dsflow_tui.py --demo # sandbox with a fake dssc\n"
" DEMO_FAIL=jaguar_1x1 dsflow_tui.py --demo # watch a failing run release its locks")
ap.add_argument("command", nargs="?", default="tui", choices=("tui", "status", "_runjob"),
help="tui (default) or status")
ap.add_argument("--ws", default=os.getcwd(), help="workspace root (default: current directory)")
ap.add_argument("--conf", help="dsflow.conf (default: $DSFLOW_CONF or <ws>/flow/dsflow.conf)")
ap.add_argument("--sanity-cmd", help="external sanity command; {cfg} and {ws} are substituted "
"(default: SANITY_SCRIPT from dsflow.conf, else run_sanity)")
ap.add_argument("--tags", help="comma-separated tags offered for batch tagging (default: DSFLOW_TAGS)")
ap.add_argument("--auto-refresh", type=int, default=0, metavar="SEC",
help="re-query DesignSync every SEC seconds (default: only on r / after actions)")
ap.add_argument("--json", action="store_true", help="status: print JSON")
ap.add_argument("--theme", default="tokyo-night",
help="colour theme (default tokyo-night; ctrl+p in the app lists the others)")
ap.add_argument("--demo", action="store_true", help="run against a sandbox workspace with a fake dssc")
ap.add_argument("--demo-dir", default=os.path.join(tempfile.gettempdir(), "dsflow_tui_demo-" + ME))
ap.add_argument("--demo-reset", action="store_true", help="rebuild the demo sandbox from scratch")
ap.add_argument("--version", action="version", version="dsflow_tui " + VERSION)
args = ap.parse_args(argv)
if args.demo:
args.ws, args.conf = setup_demo(args.demo_dir, args.demo_reset)
conf = args.conf or os.environ.get("DSFLOW_CONF") or os.path.join(args.ws, "flow", "dsflow.conf")
tags = [t for t in (args.tags or "").replace(",", " ").split() if t] or None
try:
flow = Flow(args.ws, conf, args.sanity_cmd, tags)
flow.load_vars()
except FlowError as e:
print("dsflow_tui: %s" % e, file=sys.stderr)
return 2
if args.command == "_runjob":
return Runner(flow).main()
if args.command == "status":
return cmd_status(flow, args.json)
if not sys.stdout.isatty():
print("dsflow_tui: the TUI needs a terminal (use `status` for scripts)", file=sys.stderr)
return 2
if sys.version_info < (3, 8, 1):
print("dsflow_tui: the TUI needs Python >= 3.8.1 (this is %s); `status` still works"
% sys.version.split()[0], file=sys.stderr)
return 2
from .ui.app import DsflowApp # imported late: status and the runner don't need Textual
DsflowApp(flow, auto_refresh=args.auto_refresh, theme=args.theme).run()
job = read_json(flow.path(JOB_FILE))
if job_state(job) == "active":
print("dsflow_tui: sanity run %s is still going in the background." % job["id"])
print(" follow it with: %s status (or reopen the TUI)" % os.path.basename(sys.argv[0]))
return 0