#!/usr/bin/env python3 """Keep raw module page frames from growing while shared layouts are adopted.""" from __future__ import annotations import pathlib import re import sys META_ROOT = pathlib.Path(__file__).resolve().parents[2] REPOS_ROOT = META_ROOT.parent BASELINE_PATH = pathlib.Path(__file__).with_name("shared-webui-layout-baseline.txt") WORKSPACE_BASELINE_PATH = pathlib.Path(__file__).with_name( "shared-webui-workspace-baseline.txt" ) RAW_PAGE_FRAME = 'className="content-pad workspace-data-page' RAW_WORKSPACE = re.compile(r']*\bsurface=\"panel-header\"" ) UNSAVED_GUARD_MARKERS = ( "useUnsavedDraftGuard", "useCampaignDraftEditor", "useRegisterUnsavedChanges", "semantic-editor-guard:", ) def baseline_paths(path: pathlib.Path) -> set[pathlib.Path]: return { pathlib.Path(line.strip()) for line in path.read_text(encoding="utf-8").splitlines() if line.strip() and not line.lstrip().startswith("#") } def source_paths() -> list[pathlib.Path]: paths: list[pathlib.Path] = [] for repository in sorted(REPOS_ROOT.glob("govoplan*")): source_root = repository / "webui" / "src" if source_root.is_dir(): paths.extend(sorted(source_root.rglob("*.tsx"))) return paths def relative(path: pathlib.Path) -> pathlib.Path: return path.relative_to(REPOS_ROOT) def main() -> int: sources = source_paths() source_text = {relative(path): path.read_text(encoding="utf-8") for path in sources} page_consumers = { path for path, text in source_text.items() if path != CENTRAL_LAYOUT and PAGE_LAYOUT_USAGE.search(text) } workspace_consumers = { path for path, text in source_text.items() if path != CENTRAL_WORKSPACE_LAYOUT and "