From f054759e2f7b50a613f736ac38b4bbac02748429 Mon Sep 17 00:00:00 2001 From: Mike Mulligan Date: Thu, 1 Oct 2026 08:19:51 -0400 Subject: [PATCH] fix: close every file build-manifest.py opens The section @include read and the .mu-release.yaml, .mu-manifest.yaml and computed.json loads passed open() straight to read(), yaml or json and never closed the file; `python3 -X dev` printed a ResourceWarning for each. They now read inside with blocks, still as utf-8, and the manifest they produce is byte-identical. --- build-manifest.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build-manifest.py b/build-manifest.py index a90a229..9fe1bc8 100644 --- a/build-manifest.py +++ b/build-manifest.py @@ -190,7 +190,9 @@ def build_sections(base: dict, repo_root: str, autogen: bool, strip_cfg) -> dict if m: full = resolve_in_repo(repo_root, m.group("path")) if full: - resolved[key] = convert(open(full, encoding="utf-8").read(), m.group("ext"), key, strip_cfg) + with open(full, encoding="utf-8") as fh: + included = fh.read() + resolved[key] = convert(included, m.group("ext"), key, strip_cfg) continue sys.stderr.write(f"build-manifest: section '{key}' include '{m.group('path')}' not found — literal\n") resolved[key] = body @@ -224,7 +226,8 @@ def main() -> None: repo_root = args.repo_root cfg = {} if args.config and os.path.isfile(args.config): - cfg = yaml.safe_load(open(args.config, encoding="utf-8")) or {} + with open(args.config, encoding="utf-8") as fh: + cfg = yaml.safe_load(fh) or {} sec_cfg = cfg.get("sections") or {} autogen = bool(sec_cfg.get("autogen", True)) strip_cfg = sec_cfg.get("strip_title") @@ -232,11 +235,13 @@ def main() -> None: base = {} base_path = os.path.join(repo_root, BASE_FILE) if os.path.isfile(base_path): - base = yaml.safe_load(open(base_path, encoding="utf-8")) or {} + with open(base_path, encoding="utf-8") as fh: + base = yaml.safe_load(fh) or {} if not isinstance(base, dict): sys.exit(f"build-manifest: {BASE_FILE} must be a mapping") - computed = json.load(open(args.computed, encoding="utf-8")) + with open(args.computed, encoding="utf-8") as fh: + computed = json.load(fh) shots = computed.pop("_screenshots", None) # {N: src} from release.sh (channel URLs) sections = build_sections(base, repo_root, autogen, strip_cfg)