diff --git a/scripts/check_generated_files_current.py b/scripts/check_generated_files_current.py index c9152a4..3ac4b2a 100644 --- a/scripts/check_generated_files_current.py +++ b/scripts/check_generated_files_current.py @@ -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. """ @@ -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 @@ -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): diff --git a/tests/test_check_generated_files_current.py b/tests/test_check_generated_files_current.py index ed0fc97..574aaa8 100644 --- a/tests/test_check_generated_files_current.py +++ b/tests/test_check_generated_files_current.py @@ -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