diff --git a/scripts/orchestrate/docs.py b/scripts/orchestrate/docs.py index 807ac2f47..39ff56e0a 100644 --- a/scripts/orchestrate/docs.py +++ b/scripts/orchestrate/docs.py @@ -5,8 +5,8 @@ from __future__ import annotations import argparse import shutil import sys -from pathlib import Path +from core.paths import REPO_ROOT from orchestrate import runner from orchestrate.labels import STEP_LABELS, skip_notice from orchestrate.results import SKIPPED @@ -59,7 +59,7 @@ def docs_steps(args: argparse.Namespace, results: dict) -> bool: if args.skip_docs: skip_notice("render_site", "--skip-docs") results["render_site"] = SKIPPED - elif shutil.which("npm") is None or not Path("website/node_modules").is_dir(): + elif shutil.which("npm") is None or not (REPO_ROOT / "website" / "node_modules").is_dir(): skip_notice("render_site", "Node not set up: npm ci --prefix website") results["render_site"] = SKIPPED else: diff --git a/scripts/orchestrate/guards.py b/scripts/orchestrate/guards.py index 3b5242f7f..6d6ce994f 100644 --- a/scripts/orchestrate/guards.py +++ b/scripts/orchestrate/guards.py @@ -6,7 +6,7 @@ import argparse import os from pathlib import Path -from core.paths import PLATFORMS_DIR +from core.paths import PLATFORMS_DIR, REPO_ROOT from model.registry import load_data_dir_registry @@ -46,12 +46,16 @@ def refuse_offline_without_caches( On a fresh clone none is: --offline skips the refresh, and the run went through the database, verify and every pack before failing at the end of the build. Only an empty cache is refused here: with some cached, the - packs decide which ones they need and the build names the rest. + packs decide which ones they need and the build names the rest. A + relative cache is read from the repository root, where the steps run. """ if not args.offline or args.skip_packs: return registry = load_data_dir_registry(platforms_dir) - if registry and not any(os.path.isdir(e.get("local_cache") or "") for e in registry.values()): + if registry and not any( + e.get("local_cache") and os.path.isdir(os.path.join(REPO_ROOT, e["local_cache"])) + for e in registry.values() + ): parser.error( "no data directory is cached and --offline skips their refresh: run " "python scripts/refresh_data_dirs.py once, or drop --offline" @@ -66,7 +70,8 @@ def refuse_offline_export_without_originals( Seven formats carry code, so step 2e patches the platform's own file, which --offline does not fetch. On a fresh clone the database, verify - and the truth model were built before step 2e failed on every one. + and the truth model were built before step 2e failed on every one. A + relative cache is read from the repository root, where step 2e runs. """ if not (args.offline and args.with_export): return @@ -74,7 +79,7 @@ def refuse_offline_export_without_originals( lacking = sorted( name for name, exporter in discover_exporters().items() - if exporter.needs_original() and not any(Path(cache, name).glob("*")) + if exporter.needs_original() and not any(Path(REPO_ROOT, cache, name).glob("*")) ) if lacking: parser.error( diff --git a/tests/test_tool_messages.py b/tests/test_tool_messages.py index 13856878c..d6dbc7e46 100644 --- a/tests/test_tool_messages.py +++ b/tests/test_tool_messages.py @@ -390,6 +390,20 @@ class AnOfflineRunWithNoCacheStopsFirst(unittest.TestCase): guards.refuse_offline_without_caches(parser, self._args(), tmp) parser.error.assert_not_called() + def test_a_relative_cache_is_read_from_the_repository_root(self): + """The registry writes data/: started from scripts/, the run + looked for scripts/data/ and refused a checkout whose trees were cached.""" + with tempfile.TemporaryDirectory() as tmp: + (Path(tmp) / "_data_dirs.yml").write_text( + "data_directories:\n a:\n local_cache: tests\n" + ) + previous = os.getcwd() + self.addCleanup(os.chdir, previous) + os.chdir(REPO_ROOT / "scripts") + parser = mock.Mock() + guards.refuse_offline_without_caches(parser, self._args(), tmp) + parser.error.assert_not_called() + class AnOfflineExportWithNoOriginalsStopsFirst(unittest.TestCase): """pipeline.py --offline --with-export, which tools.md listed as a