diff --git a/app/nullius/execution.py b/app/nullius/execution.py index aad62bf5..1236d793 100644 --- a/app/nullius/execution.py +++ b/app/nullius/execution.py @@ -1676,19 +1676,45 @@ def run_folder(name: str, root: Optional[str] = None) -> str: return path -def _run_deletion(name: str, home: str, root: Optional[str]) -> dict: +def size_of(path: str) -> int: + """The bytes of every file under *path*, links not followed; a file gone + since the walk listed it (a run still writing replaces its own) counts 0.""" + total = 0 + for d, _, names in os.walk(path): + for n in names: + try: + total += os.lstat(os.path.join(d, n)).st_size + except FileNotFoundError: + pass + return total + + +def _deletable(name: str, root: Optional[str]) -> tuple: + """A run's folder and record, when it is a run that has ended; ValueError + (alive, or not a run) or OSError (its record unreadable) otherwise.""" path = run_folder(name, root) with open(os.path.join(path, RECORD), encoding="utf-8") as fh: rec = json.load(fh) - ex = next((e for e in EXECUTIONS.values() if os.path.realpath(e.dir) == path), None) + ex = next((e for e in EXECUTIONS.values() if e.plan.name == name and os.path.realpath(e.dir) == path), None) state = ex.state if ex is not None else rec.get("state") if state in ALIVE: raise ValueError(f"{name} is {state}: stop it before you delete it") + return path, rec + + +def deletable(names: List[str], root: Optional[str] = None) -> None: + """Raise as ``deletion`` would for the runs *names*, without working out what goes.""" + for n in dict.fromkeys(names): + _deletable(n, root) + + +def _run_deletion(name: str, home: str, root: Optional[str], holding: Callable) -> dict: + path, rec = _deletable(name, root) plan = rec.get("plan") or {} # a run refused at the name check never made the host folder: one of that name there is not its own host = hosts.parse(plan["host"]) if plan.get("host") and (rec.get("launched") or rec.get("step") not in ("connect", "name")) else None held = [] - for ws, roots in workspace.holding(home, path): + for ws, roots in holding(path): dirs = parse.find_job_dirs(roots) ids = [j.job_id for j in workspace.load_jobs(ws, roots)] # a job of the same id from another root shares these judgements: they stay @@ -1696,18 +1722,19 @@ def _run_deletion(name: str, home: str, root: Optional[str]) -> dict: judged = judgements.job_dirs(ws.dir, [i for i in ids if i.split("~")[0] not in others]) held.append({"ws": ws, "roots": roots, "jobs": dirs, "judged": judged, "judgements": sum(len(os.listdir(d)) for d in judged)}) - size = sum(os.lstat(os.path.join(d, n)).st_size for d, _, names in os.walk(path) for n in names) - return {"name": name, "dir": path, "bytes": size, "host": host, "workspaces": held, + return {"name": name, "dir": path, "bytes": size_of(path), "host": host, "workspaces": held, "judgements": sum(w["judgements"] for w in held)} -def deletion(names: List[str], home: str, root: Optional[str] = None) -> dict: +def deletion(names: List[str], home: str, root: Optional[str] = None, holding: Optional[Callable] = None) -> dict: """What deleting the runs *names* of one launch removes: per run (``runs``) its folder and size, the host copy that is its own, and per workspace that holds it its roots, parsed jobs and judgement folders; the totals, and the number of copies per host. ValueError when any of them is alive or is not - a run: nothing goes then.""" - runs = [_run_deletion(n, home, root) for n in dict.fromkeys(names)] + a run: nothing goes then. ``holding``: a run folder's ``workspace.holding``, + when the caller has it already.""" + holding = holding or (lambda path: workspace.holding(home, path)) + runs = [_run_deletion(n, home, root, holding) for n in dict.fromkeys(names)] copies: Dict[str, int] = {} for r in runs: if r["host"]: diff --git a/app/nullius/runs/parse.py b/app/nullius/runs/parse.py index 364ef7cb..4d6e7290 100644 --- a/app/nullius/runs/parse.py +++ b/app/nullius/runs/parse.py @@ -852,10 +852,10 @@ def _budget(b) -> dict: "shards": num(b.get("shards")) or 0, "shards_stopped": num(b.get("shards_stopped")) or 0} -def parse_job(job_dir: str, reuse=None) -> Job: +def parse_job(job_dir: str, reuse=None, trials: bool = True) -> Job: """One job directory. ``reuse(trial_dir)``: a Trial already parsed from files that have not changed since (a workspace's cache, for a running - job), or None to parse it.""" + job), or None to parse it. ``trials=False``: the job's own records only.""" res = verifier._read_json(os.path.join(job_dir, "result.json")) or {} cfg = verifier._read_json(os.path.join(job_dir, "config.json")) or {} stats = res.get("stats") or {} @@ -909,7 +909,7 @@ def parse_job(job_dir: str, reuse=None) -> Job: dataset_path=redact(dataset_path), ) - for name in sorted(os.listdir(job_dir)): + for name in sorted(os.listdir(job_dir)) if trials else (): sub = os.path.join(job_dir, name) if os.path.isdir(sub) and os.path.isfile(os.path.join(sub, "result.json")): t = (reuse(sub) if reuse else None) or parse_trial(job.job_id, sub) diff --git a/app/nullius/workspace.py b/app/nullius/workspace.py index 5f982f57..2020aa5f 100644 --- a/app/nullius/workspace.py +++ b/app/nullius/workspace.py @@ -237,12 +237,19 @@ def delete(home_dir: str, name: str) -> bool: def holding(home_dir: str, folder: str) -> list: """Every workspace with a root in *folder*: [(workspace, those roots)].""" - inside = os.path.join(os.path.realpath(folder), "") - found = [] + return holding_all(home_dir, [folder])[folder] + + +def holding_all(home_dir: str, folders) -> dict: + """``holding`` of each of *folders*, each workspace and root read once.""" + inside = {f: os.path.join(os.path.realpath(f), "") for f in folders} + found = {f: [] for f in folders} for ws in list_all(home_dir): - roots = [r for r in ws.roots if os.path.join(os.path.realpath(r), "").startswith(inside)] - if roots: - found.append((ws, roots)) + real = [(r, os.path.join(os.path.realpath(r), "")) for r in ws.roots] + for f, prefix in inside.items(): + roots = [r for r, rr in real if rr.startswith(prefix)] + if roots: + found[f].append((ws, roots)) return found diff --git a/app/static/runs/launches.css b/app/static/runs/launches.css index 4450ab50..24c322f9 100644 --- a/app/static/runs/launches.css +++ b/app/static/runs/launches.css @@ -113,3 +113,41 @@ dialog.std-how.launch-delete { width: min(520px, calc(100vw - 32px)); } .launch-agents tr.la-shard .la-who a { font-weight: 400; color: var(--text-dim); } .la-note { color: var(--patch_failed_tests); } .la-gap { display: block; margin-top: 2px; font: 11.5px var(--sans); color: var(--patch_failed_tests); } + +/* the Launches page: one row per launch */ +.inventory .inv-open { display: inline; } +.inventory .inv-open .linkish { padding: 0; text-align: left; } +/* as the Runs page's table: text columns keep a floor and short values stay on one line, so past the box's width the table scrolls instead of squeezing */ +.inventory td[data-col="launch"] { min-width: 12rem; overflow-wrap: anywhere; } +.inventory td[data-col="bench"], .inventory td[data-col="ws"] { min-width: 8rem; } +.inventory td[data-col="machines"] { min-width: 10rem; } +.inventory td[data-col="started"], .inventory td.num { white-space: nowrap; } +@media (max-width: 640px) { .inventory td[data-col="launch"] { min-width: 9rem; } } /* a phone keeps room beside the pinned title */ +.grid.sortable.inventory thead th:not([data-type]) { cursor: default; } +.grid.sortable.inventory thead th:not([data-type])::after { content: none; } +.inventory td.inv-acts { position: relative; white-space: nowrap; } /* holds its hidden reason, inside the table's scroll */ /* Add, then Delete, side by side on every row */ +.inventory .launch-add-btn:focus-visible { color: var(--text); } +.inventory .launch-delete-btn:hover, .inventory .launch-delete-btn:focus-visible { color: var(--bad); } +.inventory .icon-btn[aria-disabled="true"] { opacity: .4; background: none; border-color: transparent; cursor: default; } /* Delete it cannot: the slot kept, greyed, its reason reachable */ +/* State and Launch stay put while the table scrolls sideways; State's header is its name for a screen reader only */ +.inventory { --inv-state-w: 2.2rem; } +.inventory [data-col="state"] { width: var(--inv-state-w); min-width: var(--inv-state-w); padding-left: 0; padding-right: 0; text-align: center; } +.inventory [data-col="launch"] { --sticky-left: var(--inv-state-w); } +.inventory .sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } +/* a run's state: its icon, coloured as the Runs page's state dots */ +.inventory td[data-col="state"] .ic { vertical-align: middle; } +.inventory .st-finished, .inventory .st-running, .inventory .st-preparing { color: var(--resolved); } +.inventory .st-failed, .inventory .st-refused, .inventory .st-stopped { color: var(--bad); } +.inventory .st-paused, .inventory .st-stopping { color: var(--patch_failed_tests); } +.inventory .st-running { animation: inv-beat 2s ease-in-out infinite; } +@keyframes inv-beat { 50% { opacity: .45; } } +@media (prefers-reduced-motion: reduce) { .inventory .st-running { animation: none; } } +.inv-cols { margin-top: 1rem; } +.launch-delete select { margin-left: 8px; } +/* Add to workspace: the name field only for a new workspace, under its label as the select is */ +.launch-delete .launch-add-new { display: none; } +.launch-delete .launch-add-new input { display: block; width: 100%; margin-top: 4px; } +.launch-delete form:has(option[value=""]:checked) .launch-add-new { display: block; } +/* ten columns fit at 1280 px: narrower gutters, and a count takes only its width */ +.inventory th, .inventory td { padding-left: .4rem; padding-right: .4rem; } +.inventory th.num, .inventory td.num { width: 1%; } diff --git a/app/static/style.css b/app/static/style.css index cc8ddce9..3ecd015e 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -370,6 +370,7 @@ button.seg:hover { filter: brightness(1.25); } .menu label:hover { background: var(--surface-2); color: var(--text); } .menu input { accent-color: var(--accent); } .table-note { color: var(--text-faint); font-size: .8rem; } +.table-pager { margin-top: .6rem; } .empty-note { color: var(--text-dim); font-size: .88rem; padding: 1.5rem 0; text-align: center; } .grid.sortable thead th { cursor: pointer; user-select: none; white-space: nowrap; } @@ -405,19 +406,20 @@ button.seg:hover { filter: brightness(1.25); } does scroll horizontally. */ /* the checkbox and Run columns stay put while you scroll sideways, so a row - never loses its identity */ -.table-wrap .grid th.pick-col, .table-wrap .grid td.pick-col { - position: sticky; left: 0; z-index: 2; background: var(--bg); + never loses its identity; so do a table's .sticky-col cells, at --sticky-left */ +.table-wrap .grid th.pick-col, .table-wrap .grid td.pick-col, .table-wrap .grid .sticky-col { + position: sticky; left: var(--sticky-left, 0); z-index: 2; background: var(--bg); } +.table-wrap .grid .sticky-col.sticky-edge { box-shadow: 1px 0 0 var(--border-soft); } .table-wrap .grid th[data-col="run"], .table-wrap .grid td[data-col="run"] { position: sticky; left: 2.2rem; z-index: 2; background: var(--bg); box-shadow: 1px 0 0 var(--border-soft); } .table-wrap .grid thead th.pick-col, -.table-wrap .grid thead th[data-col="run"] { z-index: 4; background: var(--bg); } +.table-wrap .grid thead th[data-col="run"], .table-wrap .grid thead th.sticky-col { z-index: 4; background: var(--bg); } /* opaque sticky cells would hide the row hover, so repaint them to match */ .table-wrap .grid tbody tr:hover td.pick-col, -.table-wrap .grid tbody tr:hover td[data-col="run"] { background: var(--surface); } +.table-wrap .grid tbody tr:hover td[data-col="run"], .table-wrap .grid tbody tr:hover td.sticky-col { background: var(--surface); } /* compact density — same data, ~35% less width */ .grid.compact { font-size: .88rem; } @@ -441,6 +443,16 @@ button.seg:hover { filter: brightness(1.25); } right: 0; left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; max-height: 18rem; overflow-y: auto; min-width: 200px; } +/* a table's Filter and Sort by menus (the tools macro): no header carets, an arrow on the sorted column only */ +.grid.sortable.tools thead th:not([data-sorted])::after { content: none; } +.tools-menu { min-width: 220px; max-height: min(70vh, 34rem); overflow-y: auto; } +.tools-menu fieldset { margin: 0; padding: .3rem 0; border: 0; border-top: 1px solid var(--border-soft); min-width: 0; } +.tools-menu fieldset:first-of-type { border-top: 0; } +.tools-menu legend { float: left; padding: .3rem .45rem; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); } +.tools-menu .tools-all { display: flex; justify-content: flex-end; gap: .75rem; padding: .3rem .45rem; font-size: .8rem; } +.tools-menu label { clear: both; } +.tools-menu .tools-clear { align-self: flex-start; padding: .2rem .45rem .4rem; font-size: .8rem; } +.tools-count { margin-left: .4rem; padding: 0 .4em; border-radius: 99px; background: var(--accent-soft); color: var(--text); font-size: .72rem; font-variant-numeric: tabular-nums; } .menu-head { display: flex; gap: .75rem; padding: .15rem .45rem .4rem; border-bottom: 1px solid var(--border-soft); margin-bottom: .25rem; } .chip.clear { border-style: dashed; } diff --git a/app/static/tables.js b/app/static/tables.js new file mode 100644 index 00000000..baab63f3 --- /dev/null +++ b/app/static/tables.js @@ -0,0 +1,217 @@ +/* A table.grid's sortable headers and per-column value filters, shared by the + tables that have them. */ +window.NulliusTable = { + /* A header with data-type sorts its column on a click or Enter; num sorts + descending first. A cell's data-sort wins over its text. A header that + carries data-sorted at load is the sort the rows came in. The sorted + header carries aria-sort. `after` runs after each sort. Returns resort(), + to sort rows put in since; resort.set(index, dir) sorts by that header + (dir 1 up, -1 down), set(null) puts the rows back in the order they came + in; resort.state() is {col, dir}. */ + sortable(table, after = () => {}) { + const heads = [...table.tHead.rows[0].cells], body = table.tBodies[0], order = [...body.rows]; + const first = heads.find(th => th.dataset.sorted); + let col = first ? heads.indexOf(first) : null, dir = first?.dataset.sorted === 'asc' ? 1 : -1; + const key = (row, type) => { + const cell = row.cells[col]; + const raw = cell.dataset.sort ?? cell.textContent.trim(); + return type === 'num' ? parseFloat(raw) || 0 : raw.toLowerCase(); + }; + const resort = () => { + if (col === null) return; + const type = heads[col].dataset.type || 'text'; + [...body.rows].sort((a, b) => { + const x = key(a, type), y = key(b, type); + return (x < y ? -1 : x > y ? 1 : 0) * dir; + }).forEach(r => body.appendChild(r)); + after(); + }; + const mark = () => heads.forEach((th, idx) => { + th.toggleAttribute('data-sorted', idx === col); + th.toggleAttribute('aria-sort', idx === col); + if (idx === col) { th.dataset.sorted = dir > 0 ? 'asc' : 'desc'; th.setAttribute('aria-sort', dir > 0 ? 'ascending' : 'descending'); } + }); + resort.set = (idx, d = 1) => { + col = idx; dir = d; mark(); + if (idx !== null) return resort(); + order.forEach(r => body.appendChild(r)); + after(); + }; + resort.state = () => ({col, dir}); + mark(); + heads.forEach((th, idx) => { + if (!th.dataset.type) return; + th.tabIndex = 0; + const sort = () => resort.set(idx, col === idx ? -dir : (th.dataset.type === 'num' ? -1 : 1)); + th.addEventListener('click', sort); + th.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); sort(); } }); + }); + return resort; + }, + + /* The value lists (data-filter-menu) under `scope`: the filter_button + macro's, each opened by its caret, or the tools macro's. `allowed`: + column -> the Set of values ticked, or null when all are. A row passes + when, for each column, one of its values (data-f-