Skip to content

Commit 93c720a

Browse files
authored
Merge pull request #10 from gaussian/develop
Add continue-from-previous feature for grouped shots
2 parents c6e6819 + bef90f6 commit 93c720a

4 files changed

Lines changed: 549 additions & 213 deletions

File tree

shots/config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ShotSpec:
1616
id: str
1717
description: str
1818
url: str | None = None # absolute or relative
19+
continue_from_prev: bool = False # reuse browser page from previous shot in group
1920
viewport_preset: str | None = None
2021
viewport: dict[str, int] | None = None # width/height/scale
2122
full_page: bool | None = None
@@ -63,6 +64,7 @@ def _parse_shot(s: dict[str, Any], ctx: str) -> ShotSpec:
6364
id=sid,
6465
description=desc,
6566
url=str(s["url"]).strip() if s.get("url") else None,
67+
continue_from_prev=bool(s.get("continue", False)),
6668
viewport_preset=str(s["viewport_preset"]).strip() if s.get("viewport_preset") else None,
6769
viewport={k: int(v) for k, v in viewport.items()} if viewport else None,
6870
full_page=bool(s["full_page"]) if "full_page" in s else None,
@@ -121,6 +123,25 @@ def load_config(path: str) -> RunConfig:
121123

122124
shots = [_parse_shot(s, f"groups[{gi}].shots[{si}]") for si, s in enumerate(shots_raw)]
123125

126+
for si, sh in enumerate(shots):
127+
if sh.continue_from_prev:
128+
if si == 0:
129+
raise ValueError(
130+
f"groups[{gi}].shots[{si}] ('{sh.id}'): continue cannot be "
131+
f"the first shot in a group."
132+
)
133+
if sh.url is not None:
134+
raise ValueError(
135+
f"groups[{gi}].shots[{si}] ('{sh.id}'): continue and url "
136+
f"are mutually exclusive."
137+
)
138+
if sh.viewport or sh.viewport_preset:
139+
raise ValueError(
140+
f"groups[{gi}].shots[{si}] ('{sh.id}'): continue shots "
141+
f"cannot override viewport (they inherit from the chain's "
142+
f"starting shot)."
143+
)
144+
124145
if output == "png" and len(shots) > 1:
125146
raise ValueError(
126147
f"groups[{gi}] ('{gid}'): output='png' requires exactly 1 shot, got {len(shots)}. "
@@ -144,6 +165,11 @@ def load_config(path: str) -> RunConfig:
144165

145166
for si, s in enumerate(shots_raw):
146167
shot = _parse_shot(s, f"shots[{si}]")
168+
if shot.continue_from_prev:
169+
raise ValueError(
170+
f"shots[{si}] ('{shot.id}'): continue is only valid inside "
171+
f"a multi-shot group (use 'groups' with output='pdf')."
172+
)
147173
groups.append(ShotGroup(id=shot.id, shots=[shot]))
148174

149175
return RunConfig(base_url=base_url, start=start, defaults=defaults, groups=groups, out_dir=out_dir)

0 commit comments

Comments
 (0)