From 39b65bc9941de8b61f4710780472301fb9210313 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 19 Apr 2026 22:00:45 +0800 Subject: [PATCH] refactor(build): inline format_stars_short into its call site The helper only appeared once and the logic is two lines, so the named function added indirection without clarity. Removed the four dedicated unit tests that covered the function directly. Co-Authored-By: Claude --- website/build.py | 12 ++++-------- website/tests/test_build.py | 20 -------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/website/build.py b/website/build.py index 6f864a11..8689ca90 100644 --- a/website/build.py +++ b/website/build.py @@ -117,13 +117,6 @@ def extract_entries( return entries -def format_stars_short(stars: int) -> str: - """Format star count as compact string like '230k'.""" - if stars >= 1000: - return f"{stars // 1000}k" - return str(stars) - - def build(repo_root: Path) -> None: """Main build: parse README, render single-page HTML via Jinja2 templates.""" website = repo_root / "website" @@ -146,7 +139,10 @@ def build(repo_root: Path) -> None: stars_data = load_stars(website / "data" / "github_stars.json") repo_self = stars_data.get("vinta/awesome-python", {}) - repo_stars = format_stars_short(repo_self["stars"]) if "stars" in repo_self else None + repo_stars = None + if "stars" in repo_self: + stars_val = repo_self["stars"] + repo_stars = f"{stars_val // 1000}k" if stars_val >= 1000 else str(stars_val) for entry in entries: repo_key = extract_github_repo(entry["url"]) diff --git a/website/tests/test_build.py b/website/tests/test_build.py index 878e84b6..0b22609a 100644 --- a/website/tests/test_build.py +++ b/website/tests/test_build.py @@ -10,7 +10,6 @@ from build import ( detect_source_type, extract_entries, extract_github_repo, - format_stars_short, load_stars, sort_entries, ) @@ -363,25 +362,6 @@ class TestDetectSourceType: assert detect_source_type("https://github.com/org/repo/wiki") is None -# --------------------------------------------------------------------------- -# format_stars_short -# --------------------------------------------------------------------------- - - -class TestFormatStarsShort: - def test_under_1000(self): - assert format_stars_short(500) == "500" - - def test_exactly_1000(self): - assert format_stars_short(1000) == "1k" - - def test_large_number(self): - assert format_stars_short(52000) == "52k" - - def test_zero(self): - assert format_stars_short(0) == "0" - - # --------------------------------------------------------------------------- # extract_entries # ---------------------------------------------------------------------------