3 Commits
Author SHA1 Message Date
Mike Mulligan f054759e2f 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.
2026-10-01 08:19:51 -04:00
Mike Mulligan 42625f4b23 fix: close the file read_text() opens
read_text() returned open(...).read() without closing the file, which
left it to garbage collection and raised a ResourceWarning in the test
run. Read it inside a with block; the encoding stays utf-8.
2026-10-01 07:53:01 -04:00
Mike Mulligan 57910d9c86 fix: keep readme.txt subheads off the lines around them
wporg_subheads() turned `= 0.5.0 =` into `**0.5.0**` with no blank line
after it. Python-Markdown won't let a list interrupt a paragraph, so each
version's `* ` items joined the heading's paragraph as literal text, and
nl2br put <br /> between them. Every changelog published through this
action rendered that way (mu-migration, manifest-updater,
em-event-submissions). A subhead with no blank line before it also joined
the previous version's last item.

The bold line now has a blank line on each side, so it stays its own
block, as wp.org's <h4> does. A subhead that already had blank lines
around it renders exactly as before.

Adds the repo's first tests (stdlib unittest, run with
`python3 -m unittest discover -s tests`) and ignores __pycache__/.
2026-10-01 07:52:01 -04:00
4 changed files with 100 additions and 7 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
__pycache__/
+11
View File
@@ -206,3 +206,14 @@ the version comes from `style.css`'s `Version:` header.
5. **Cut a Gitea release** on the source repo and attach the zip (idempotent on re-run/re-tag). 5. **Cut a Gitea release** on the source repo and attach the zip (idempotent on re-run/re-tag).
6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with 6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with
retry + jitter for concurrent releases. retry + jitter for concurrent releases.
---
## Tests
`build-manifest.py` has `unittest` tests under `tests/`. They need the same `markdown` +
`pyyaml` packages `release.sh` installs. From the repo root:
```bash
python3 -m unittest discover -s tests
```
+21 -7
View File
@@ -68,8 +68,14 @@ def md_to_html(text: str) -> str:
def wporg_subheads(text: str) -> str: def wporg_subheads(text: str) -> str:
"""wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears """wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears
floats on h*, so heading-led content gaps below the sidebar).""" floats on h*, so heading-led content gaps below the sidebar).
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"**\1**", text)
The bold line is set off by a blank line on each side so it stays its own
block, as wp.org's <h4> does. Python-Markdown won't let a list interrupt a
paragraph, so without the blank after it a `= 1.0 =` line's `* ` items became
literal text joined by nl2br's <br />; without the blank before it, a subhead
straight after a list joined that list's last item."""
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"\n**\1**\n", text)
def strip_leading_title(md: str) -> str: def strip_leading_title(md: str) -> str:
@@ -128,7 +134,10 @@ def resolve_in_repo(repo_root: str, rel: str):
def read_text(repo_root: str, name: str): def read_text(repo_root: str, name: str):
p = os.path.join(repo_root, name) p = os.path.join(repo_root, name)
return open(p, encoding="utf-8").read() if os.path.isfile(p) else None if not os.path.isfile(p):
return None
with open(p, encoding="utf-8") as fh:
return fh.read()
def parse_readme_sections(repo_root: str) -> dict: def parse_readme_sections(repo_root: str) -> dict:
@@ -181,7 +190,9 @@ def build_sections(base: dict, repo_root: str, autogen: bool, strip_cfg) -> dict
if m: if m:
full = resolve_in_repo(repo_root, m.group("path")) full = resolve_in_repo(repo_root, m.group("path"))
if full: 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 continue
sys.stderr.write(f"build-manifest: section '{key}' include '{m.group('path')}' not found — literal\n") sys.stderr.write(f"build-manifest: section '{key}' include '{m.group('path')}' not found — literal\n")
resolved[key] = body resolved[key] = body
@@ -215,7 +226,8 @@ def main() -> None:
repo_root = args.repo_root repo_root = args.repo_root
cfg = {} cfg = {}
if args.config and os.path.isfile(args.config): 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 {} sec_cfg = cfg.get("sections") or {}
autogen = bool(sec_cfg.get("autogen", True)) autogen = bool(sec_cfg.get("autogen", True))
strip_cfg = sec_cfg.get("strip_title") strip_cfg = sec_cfg.get("strip_title")
@@ -223,11 +235,13 @@ def main() -> None:
base = {} base = {}
base_path = os.path.join(repo_root, BASE_FILE) base_path = os.path.join(repo_root, BASE_FILE)
if os.path.isfile(base_path): 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): if not isinstance(base, dict):
sys.exit(f"build-manifest: {BASE_FILE} must be a mapping") 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) shots = computed.pop("_screenshots", None) # {N: src} from release.sh (channel URLs)
sections = build_sections(base, repo_root, autogen, strip_cfg) sections = build_sections(base, repo_root, autogen, strip_cfg)
+67
View File
@@ -0,0 +1,67 @@
"""Tests for build-manifest.py. Run from the repo root:
python3 -m unittest discover -s tests
Needs the same `markdown` + `pyyaml` packages release.sh installs.
"""
import importlib.util
import os
import tempfile
import unittest
_BUILDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, "build-manifest.py")
_SPEC = importlib.util.spec_from_file_location("build_manifest", _BUILDER)
if _SPEC is None or _SPEC.loader is None:
raise ImportError(f"cannot load build-manifest.py from {_BUILDER}")
bm = importlib.util.module_from_spec(_SPEC)
_SPEC.loader.exec_module(bm)
def readme_sections(readme: str) -> dict:
with tempfile.TemporaryDirectory() as root:
with open(os.path.join(root, "readme.txt"), "w", encoding="utf-8") as fh:
fh.write(readme)
return bm.build_sections({}, root, True, None)
class ReadmeSubheadTest(unittest.TestCase):
def test_changelog_versions_render_as_headings_over_lists(self):
sections = readme_sections(
"=== Plugin ===\n\n"
"== Changelog ==\n\n"
"= 2.0.0 =\n"
"* Added a thing.\n"
"* Fixed a thing.\n"
"= 1.0.0 =\n"
"* Initial release.\n"
"* Second line.\n"
)
self.assertEqual(
sections["changelog"],
"<p><strong>2.0.0</strong></p>\n"
"<ul>\n<li>Added a thing.</li>\n<li>Fixed a thing.</li>\n</ul>\n"
"<p><strong>1.0.0</strong></p>\n"
"<ul>\n<li>Initial release.</li>\n<li>Second line.</li>\n</ul>",
)
def test_subhead_already_set_off_by_blank_lines_is_unchanged(self):
sections = readme_sections(
"=== Plugin ===\n\n"
"== Frequently Asked Questions ==\n\n"
"= Does it work? =\n\n"
"Yes, it does.\n\n"
"**Commands**\n\n"
"* one\n"
"* two\n"
)
self.assertEqual(
sections["faq"],
"<p><strong>Does it work?</strong></p>\n"
"<p>Yes, it does.</p>\n"
"<p><strong>Commands</strong></p>\n"
"<ul>\n<li>one</li>\n<li>two</li>\n</ul>",
)
if __name__ == "__main__":
unittest.main()