Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s
CI / tests (pull_request) Successful in 3m43s
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
"""The chunks of one project that run at once, each in its own tmux window: which may start now, and how each starts (docs/decisions.md → `loop-claude: each chunk runs in its own tmux window`)."""
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
@@ -116,21 +115,19 @@ def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Map
|
||||
return config
|
||||
session = loop_session(loop_run.root, paths.home)
|
||||
handed = {name: value for name, value in env.items() if name.startswith(HANDED)}
|
||||
lock = project_lock(loop_run.root, paths.home)
|
||||
try:
|
||||
with starting(lock):
|
||||
windows = tmux.listed(session, effects.tmux)
|
||||
if refused := refusal(session, windows, loop_run.root, effects.tmux):
|
||||
return refused
|
||||
chunks = chunks_to_start(windows, loop_run, leaving, config.parallel_chunks, paths, effects)
|
||||
for chunk in chunks:
|
||||
started = tmux.start_chunk(tmux.Window(session, chunk, ""), loop_run.root, handed, [str(launcher), CHUNK_FLAG, chunk, loop_run.task], windows, True, effects.tmux)
|
||||
if isinstance(started, Failure):
|
||||
return started
|
||||
windows = started
|
||||
return chunks
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot lock {lock / LOCK}: {failure.strerror}")
|
||||
with starting(project_lock(loop_run.root, paths.home)) as unlocked:
|
||||
if unlocked:
|
||||
return unlocked
|
||||
windows = tmux.listed(session, effects.tmux)
|
||||
if refused := refusal(session, windows, loop_run.root, effects.tmux):
|
||||
return refused
|
||||
chunks = chunks_to_start(windows, loop_run, leaving, config.parallel_chunks, paths, effects)
|
||||
for chunk in chunks:
|
||||
started = tmux.start_chunk(tmux.Window(session, chunk, ""), loop_run.root, handed, [str(launcher), CHUNK_FLAG, chunk, loop_run.task], windows, True, effects.tmux)
|
||||
if isinstance(started, Failure):
|
||||
return started
|
||||
windows = started
|
||||
return chunks
|
||||
|
||||
|
||||
def refusal(session: str, windows: list[tmux.Listed], root: str, run: tmux.Tmux) -> Failure | None:
|
||||
@@ -165,5 +162,5 @@ def held_beside(chunk: str, root: str, paths: Paths, effects: Effects) -> list[i
|
||||
|
||||
def wait_for_starts(root: str, home: pathlib.Path) -> None:
|
||||
"""Returns once no loop of the project is starting windows: start_chunks holds LOCK while it starts them. Where the lock cannot be taken, it returns at once."""
|
||||
with contextlib.suppress(OSError), starting(project_lock(root, home)):
|
||||
with starting(project_lock(root, home)):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user