From ef33a9597126ad5b52e4b9befdbaad55254ba471 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:57:07 +0100 Subject: [PATCH] refactor: decide the recorded trees in one place --- scripts/freshness/profiles.py | 11 +------- scripts/sitegen/sources.py | 47 ++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/scripts/freshness/profiles.py b/scripts/freshness/profiles.py index 7eb3c0ee3..289cade18 100644 --- a/scripts/freshness/profiles.py +++ b/scripts/freshness/profiles.py @@ -18,16 +18,7 @@ def check_source_paths(profiles: dict) -> Finding: tries is recorded, read or not, so a lacking one was never tried.""" from sitegen import sources as sitegen_sources - pinned = { - sitegen_sources.tree_key(repo, pin) - for profile in profiles.values() if sitegen_sources.cited_paths(profile) - for repo, pin in sitegen_sources.profile_trees(profile) - } | { - # The platform build files pin_build names, linked from a page too. - sitegen_sources.tree_key(repo, pin) - for profile in profiles.values() - for repo, pin, _path in sitegen_sources.build_files(profile) - } + pinned = sitegen_sources.pinned_trees(profiles) try: recorded = set(json.loads(sitegen_sources.SOURCE_PATHS.read_text(encoding="utf-8"))) except (OSError, ValueError) as exc: diff --git a/scripts/sitegen/sources.py b/scripts/sitegen/sources.py index 28037bf12..54e880ed0 100644 --- a/scripts/sitegen/sources.py +++ b/scripts/sitegen/sources.py @@ -298,33 +298,40 @@ def _listed_directories( return frozenset(found) if listed else None +def pinned_sources(profiles: dict) -> list[tuple[upstream.Repo, str, frozenset[str]]]: + """Each tree source-paths.json records, as (repo, pin, paths to look up): + every tree a profile citing a path pins, then the platform build files + `pin_build` names, linked from a page too.""" + found: list[tuple[upstream.Repo, str, frozenset[str]]] = [] + for _name, profile in sorted(profiles.items()): + paths = frozenset(cited_paths(profile)) + if paths: + found.extend((repo, pin, paths) for repo, pin in profile_trees(profile)) + found.extend((repo, pin, frozenset({path})) for repo, pin, path in build_files(profile)) + return found + + +def pinned_trees(profiles: dict) -> set[str]: + """The tree keys source-paths.json records, read or not.""" + return {tree_key(repo, pin) for repo, pin, _paths in pinned_sources(profiles)} + + def build_source_paths( profiles: dict, cache_dirs: list[Path], fetch: bool = False, ) -> tuple[dict[str, list[str]], list[str]]: """The cited paths each cached tree holds, and the trees not cached.""" held: dict[str, set[str]] = {} unread: set[str] = set() - for _name, profile in sorted(profiles.items()): - paths = cited_paths(profile) - if not paths: + for repo, pin, paths in pinned_sources(profiles): + tree = _cached_tree(repo, pin, cache_dirs, fetch) + if tree is None: + tree = _listed_directories(repo, pin, set(paths), cache_dirs, fetch) + if tree is None: + unread.add(tree_key(repo, pin)) continue - for repo, pin in profile_trees(profile): - tree = _cached_tree(repo, pin, cache_dirs, fetch) - if tree is None: - tree = _listed_directories(repo, pin, paths, cache_dirs, fetch) - if tree is None: - unread.add(tree_key(repo, pin)) - continue - # Recorded even when it holds no cited path, so a pinned tree - # missing from the record is one no run has read. - held.setdefault(tree_key(repo, pin), set()).update(paths & tree) - for repo, pin, path in build_files(profile): - tree = (_cached_tree(repo, pin, cache_dirs, fetch) - or _listed_directories(repo, pin, {path}, cache_dirs, fetch)) - if tree is None: - unread.add(tree_key(repo, pin)) - continue - held.setdefault(tree_key(repo, pin), set()).update({path} & tree) + # Recorded even when it holds no cited path, so a pinned tree + # missing from the record is one no run has read. + held.setdefault(tree_key(repo, pin), set()).update(paths & tree) return {key: sorted(paths) for key, paths in sorted(held.items())}, sorted(unread)