Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 26 additions & 4 deletions lessons/09-opening-an-issue/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 24 additions & 5 deletions tools/capture_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading