From c85f81bb24530061373ae35adcbd46400f4912a4 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 19 Apr 2026 21:56:06 +0800 Subject: [PATCH] refactor(build): accept Path directly in build() signature Remove internal str->Path conversion; callers and tests now pass Path objects directly. Co-Authored-By: Claude --- website/build.py | 9 ++++----- website/tests/test_build.py | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/website/build.py b/website/build.py index 9e141a39..5f532f3c 100644 --- a/website/build.py +++ b/website/build.py @@ -133,11 +133,10 @@ def format_stars_short(stars: int) -> str: return str(stars) -def build(repo_root: str) -> None: +def build(repo_root: Path) -> None: """Main build: parse README, render single-page HTML via Jinja2 templates.""" - repo = Path(repo_root) - website = repo / "website" - readme_text = (repo / "README.md").read_text(encoding="utf-8") + website = repo_root / "website" + readme_text = (repo_root / "README.md").read_text(encoding="utf-8") subtitle = "" for line in readme_text.split("\n"): @@ -208,4 +207,4 @@ def build(repo_root: str) -> None: if __name__ == "__main__": - build(str(Path(__file__).parent.parent)) + build(Path(__file__).parent.parent) diff --git a/website/tests/test_build.py b/website/tests/test_build.py index 3b406607..878e84b6 100644 --- a/website/tests/test_build.py +++ b/website/tests/test_build.py @@ -108,7 +108,7 @@ class TestBuild: Help! """) self._make_repo(tmp_path, readme) - build(str(tmp_path)) + build(tmp_path) site = tmp_path / "website" / "output" assert (site / "index.html").exists() @@ -135,7 +135,7 @@ class TestBuild: stale.mkdir(parents=True) (stale / "index.html").write_text("old", encoding="utf-8") - build(str(tmp_path)) + build(tmp_path) assert not (tmp_path / "website" / "output" / "categories" / "stale").exists() @@ -162,7 +162,7 @@ class TestBuild: Done. """) self._make_repo(tmp_path, readme) - build(str(tmp_path)) + build(tmp_path) index_html = (tmp_path / "website" / "output" / "index.html").read_text() assert "Alpha" in index_html @@ -186,7 +186,7 @@ class TestBuild: Done. """) self._make_repo(tmp_path, readme) - build(str(tmp_path)) + build(tmp_path) index_html = (tmp_path / "website" / "output" / "index.html").read_text() assert "django" in index_html @@ -224,7 +224,7 @@ class TestBuild: } (data_dir / "github_stars.json").write_text(json.dumps(stars), encoding="utf-8") - build(str(tmp_path)) + build(tmp_path) html = (tmp_path / "website" / "output" / "index.html").read_text(encoding="utf-8") # Star-sorted: high-stars (5000) before low-stars (100) before no-stars (None)