From 8afccc3d0f3f4f38e1b58b039c8e5176f999770d Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:20:34 +0100 Subject: [PATCH] fix: follow scripts the site build reads as data --- .github/workflows/deploy-site.yml | 1 + tests/test_workflow_paths.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 1d4a9a553..20e7fe82b 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -12,6 +12,7 @@ on: # Every script the build runs or imports, and no other # (tests/test_workflow_paths.py). - "scripts/acquire/provenance.py" + - "scripts/check_platform_folder.py" - "scripts/core/__init__.py" - "scripts/core/anchors.py" - "scripts/core/artifacts.py" diff --git a/tests/test_workflow_paths.py b/tests/test_workflow_paths.py index a6664c242..2d9139797 100644 --- a/tests/test_workflow_paths.py +++ b/tests/test_workflow_paths.py @@ -32,9 +32,31 @@ def _module_file(name: str) -> Path | None: return None +def _path_parts(node: ast.expr) -> list[str]: + """The string segments of a `a / "b" / "c.py"` chain, outermost last.""" + if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Div): + return _path_parts(node.left) + _path_parts(node.right) + if isinstance(node, ast.Constant) and isinstance(node.value, str): + return [node.value] + return [] + + +def _read_scripts(node: ast.AST) -> set[Path]: + """A script read as data (`REPO_ROOT / "scripts" / "x" / "y.py"`) is an input too.""" + if not (isinstance(node, ast.BinOp) and isinstance(node.op, ast.Div)): + return set() + parts = _path_parts(node) + if "scripts" in parts and parts[-1].endswith(".py"): + target = REPO_ROOT.joinpath(*parts[parts.index("scripts"):]) + if target.is_file(): + return {target} + return set() + + def _imports(path: Path) -> set[Path]: found: set[Path] = set() for node in ast.walk(ast.parse(path.read_text(encoding="utf-8"))): + found.update(_read_scripts(node)) if isinstance(node, ast.Import): names = [alias.name for alias in node.names] elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module: