Skip to content

Commit c5bd364

Browse files
committed
Use playwright HEAD requests
1 parent a79e681 commit c5bd364

File tree

3 files changed

+1947
-3
lines changed

3 files changed

+1947
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ __pycache__/
1414

1515
# Build artifacts
1616
/dist/
17+
/build/
1718
/docs/generated/
1819
/docs/_build/
1920

tutorial-registry/validate.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from contextlib import contextmanager
1212
from pathlib import Path
1313
from textwrap import dedent
14+
from time import sleep
1415
from typing import TYPE_CHECKING, Any, Literal
1516

1617
import jsonschema
@@ -25,7 +26,7 @@
2526

2627

2728
@contextmanager
28-
def browser_context() -> Generator[any, None, None]:
29+
def _browser_context() -> Generator[Any, None, None]:
2930
with sync_playwright() as p:
3031
browser = p.chromium.launch(headless=True)
3132
try:
@@ -37,12 +38,14 @@ def browser_context() -> Generator[any, None, None]:
3738
def _check_url_exists(url: str, browser) -> None:
3839
page = browser.new_page()
3940
try:
40-
response = page.goto(url, timeout=10000)
41+
response = page.request.head(url, timeout=10000)
4142
if response is None or response.status != 200:
4243
raise ValueError(f"URL {url} is not reachable (status: {response.status if response else 'unknown'})")
4344
finally:
4445
page.close()
4546

47+
sleep(5)
48+
4649

4750
def _check_image(img_path: Path) -> None:
4851
"""Check that the image exists and that it is either SVG or fits into the 512x512 bounding box."""
@@ -69,7 +72,7 @@ def validate_tutorials(schema_file: Path, tutorials_dir: Path) -> Generator[dict
6972
known_links = set()
7073
known_primary_to_orders: dict[str, set[int]] = {}
7174

72-
with browser_context() as browser:
75+
with _browser_context() as browser:
7376
for tmp_meta_file in tutorials_dir.rglob("meta.yaml"):
7477
tutorial_id = tmp_meta_file.parent.name
7578
with tmp_meta_file.open() as f:

0 commit comments

Comments
 (0)