diff --git a/lessons/09-opening-an-issue/captures/bot-check.png b/lessons/09-opening-an-issue/captures/bot-check.png new file mode 100644 index 0000000..c316707 Binary files /dev/null and b/lessons/09-opening-an-issue/captures/bot-check.png differ diff --git a/lessons/09-opening-an-issue/captures/report.png b/lessons/09-opening-an-issue/captures/report.png new file mode 100644 index 0000000..b90e00c Binary files /dev/null and b/lessons/09-opening-an-issue/captures/report.png differ diff --git a/lessons/09-opening-an-issue/script.md b/lessons/09-opening-an-issue/script.md index 6bd0fd8..b16f65d 100644 --- a/lessons/09-opening-an-issue/script.md +++ b/lessons/09-opening-an-issue/script.md @@ -158,14 +158,36 @@ bullets: > Found one? Open issues, new issue, and pick the bug hunt form. Fill in > every field. +## Scene 8: A finished report +visual: browser +url: https://github.com/thejesh23/first-python-contribution/issues/30 +caption: A finished bug-hunt report: every part a maintainer needs +image: captures/report.png +height: 2600 +crop: 100,190,920,670 + +> Here is a finished report. The title says what goes wrong. The steps are +> one command anyone can paste. + +> Expected quotes the readme. And actual is the real output, pasted as text. + +## Scene 9: The bot checks it +visual: browser +url: https://github.com/thejesh23/first-python-contribution/issues/30 +caption: The bot ran the command, and hands over to a maintainer +image: captures/bot-check.png +height: 2600 +crop: 100,1225,920,370 + > Within a minute, a bot checks your report. It even runs your command, and -> compares the result with a correct split bill. So it knows if your steps +> compares the result with a correct split bill. So it knows your steps > really show the bug. -> Fix anything it marks, by editing your issue. Then a maintainer reviews -> it. Please don't fix the bug in a pull request. The next learner needs it. +> Anything marked with a cross, fix by editing your issue. The bot checks +> again. Then a maintainer reviews it. Please don't fix the bug in a pull +> request. The next learner needs it. -## Scene 8: Done +## Scene 10: Done visual: slide title: A report anyone can reproduce bullets: diff --git a/tools/capture_pages.py b/tools/capture_pages.py index 889c62e..3aa7e1d 100644 --- a/tools/capture_pages.py +++ b/tools/capture_pages.py @@ -36,7 +36,7 @@ def parse_box(text: str) -> tuple[int, int, int, int]: return x, y, w, h -def capture(url: str, out: Path, height: int = 900) -> None: +def capture(url: str, out: Path, height: int = 900, budget_ms: int = LOAD_BUDGET_MS) -> None: out.parent.mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory() as profile: subprocess.run( @@ -46,7 +46,7 @@ def capture(url: str, out: Path, height: int = 900) -> None: "--disable-gpu", "--hide-scrollbars", f"--user-data-dir={profile}", - f"--virtual-time-budget={LOAD_BUDGET_MS}", + f"--virtual-time-budget={budget_ms}", f"--window-size={WIDTH},{height}", f"--screenshot={out}", url, @@ -66,6 +66,27 @@ def crop(path: Path, box: tuple[int, int, int, int]) -> None: tmp.replace(path) +def looks_blank(path: Path) -> bool: + """True if the image is (nearly) one flat colour: the page hadn't drawn yet.""" + gray = subprocess.run( + ["ffmpeg", "-loglevel", "error", "-i", str(path), "-vf", "scale=96:-1,format=gray", "-f", "rawvideo", "-"], + check=True, + capture_output=True, + ).stdout + return max(gray) - min(gray) < 16 + + +def capture_scene(scene: script_format.Scene, out: Path) -> None: + """Capture a scene's page, retrying with more load time when it comes out blank (a busy machine).""" + for attempt in range(3): + capture(scene.fields["url"], out, int(scene.fields.get("height", 900)), LOAD_BUDGET_MS * (attempt + 1)) + if scene.fields.get("crop"): + crop(out, parse_box(scene.fields["crop"])) + if not looks_blank(out): + return + raise RuntimeError(f"{out.name} is still blank after 3 tries: is {scene.fields['url']} up?") + + def main(argv: list[str]) -> int: if len(argv) != 1: print("usage: python tools/capture_pages.py LESSON-FOLDER", file=sys.stderr) @@ -78,9 +99,7 @@ def main(argv: list[str]) -> int: if scene.visual != "browser" or not image or image in done: continue out = lesson / image - capture(scene.fields["url"], out, int(scene.fields.get("height", 900))) - if scene.fields.get("crop"): - crop(out, parse_box(scene.fields["crop"])) + capture_scene(scene, out) done.add(image) print(f"captured {scene.fields['url']} -> {out.relative_to(lesson.parent.parent)}") return 0