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
19 changes: 18 additions & 1 deletion scripts/check_generated_files_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
after CI's own build_explainers.py/generate_og_images.py steps to be
meaningful, though CI still runs it there too.

The regeneration timeout can be configured with the optional
FAIRCODE_BUILD_TIMEOUT environment variable (in seconds). Invalid or
non-positive values fall back to the default of 600 seconds.
Run locally: python3 scripts/check_generated_files_current.py
Exit code: 0 = everything current, 1 = something is genuinely stale.
"""
Expand All @@ -76,9 +79,11 @@
import subprocess
import sys
import tempfile
import os
from contextlib import ExitStack
from pathlib import Path


from PIL import Image

ROOT = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -128,7 +133,19 @@ def _expected_og_slugs():
return ["home", "profiler"] + [entry["slug"] for entry in entries]


BUILD_TIMEOUT = 600.0 # seconds for each of the three regeneration steps (#1292)
def _get_build_timeout() -> float:
"""Returns the build timeout from FAIRCODE_BUILD_TIMEOUT, or 600 seconds."""
try:
timeout = float(os.environ.get("FAIRCODE_BUILD_TIMEOUT", "600"))
if timeout > 0:
return timeout
except ValueError:
pass

return 600.0


BUILD_TIMEOUT = _get_build_timeout() # seconds for each of the three regeneration steps (#1292)


class BuilderTimeout(RuntimeError):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_check_generated_files_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,26 @@ def test_builder_names_say_which_step_stalled():
assert script._builder_name(["python", "scripts/build_explainers.py"]) == "scripts/build_explainers.py"
assert "MCP results mirror" in script._builder_name(["python", "-c", "from scripts.freeze_paper_results import x"])
assert str(script.BuilderTimeout("scripts/x.py", 5)) == "scripts/x.py did not finish within 5 s"

def test_build_timeout_uses_environment_variable(monkeypatch):
script = _script()
monkeypatch.setenv("FAIRCODE_BUILD_TIMEOUT", "120")

assert script._get_build_timeout() == 120.0


def test_build_timeout_defaults_to_600(monkeypatch):
script = _script()
monkeypatch.delenv("FAIRCODE_BUILD_TIMEOUT", raising=False)

assert script._get_build_timeout() == 600.0


@pytest.mark.parametrize("value", ["abc", "", "0", "-10"])
def test_build_timeout_invalid_values_fall_back_to_600(
monkeypatch, value
):
script = _script()
monkeypatch.setenv("FAIRCODE_BUILD_TIMEOUT", value)

assert script._get_build_timeout() == 600.0
Loading