mirror of
https://github.com/vinta/awesome-python.git
synced 2026-03-23 13:56:43 +08:00
refactor(build): remove unused group_categories wrapper
group_categories only ever appended a Resources group when the resources list was non-empty. All call sites passed an empty list, making it a no-op indirection. Inline parsed_groups directly and remove the dead code along with its tests. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,26 +9,7 @@ from pathlib import Path
|
|||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from readme_parser import parse_readme, slugify
|
from readme_parser import parse_readme
|
||||||
|
|
||||||
|
|
||||||
def group_categories(
|
|
||||||
parsed_groups: list[dict],
|
|
||||||
resources: list[dict],
|
|
||||||
) -> list[dict]:
|
|
||||||
"""Combine parsed groups with resources for template rendering."""
|
|
||||||
groups = list(parsed_groups)
|
|
||||||
|
|
||||||
if resources:
|
|
||||||
groups.append(
|
|
||||||
{
|
|
||||||
"name": "Resources",
|
|
||||||
"slug": slugify("Resources"),
|
|
||||||
"categories": list(resources),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return groups
|
|
||||||
|
|
||||||
|
|
||||||
class StarData(TypedDict):
|
class StarData(TypedDict):
|
||||||
@@ -152,12 +133,11 @@ def build(repo_root: str) -> None:
|
|||||||
subtitle = stripped
|
subtitle = stripped
|
||||||
break
|
break
|
||||||
|
|
||||||
parsed_groups, _resources = parse_readme(readme_text)
|
parsed_groups, _ = parse_readme(readme_text)
|
||||||
|
|
||||||
categories = [cat for g in parsed_groups for cat in g["categories"]]
|
categories = [cat for g in parsed_groups for cat in g["categories"]]
|
||||||
total_entries = sum(c["entry_count"] for c in categories)
|
total_entries = sum(c["entry_count"] for c in categories)
|
||||||
groups = group_categories(parsed_groups, [])
|
entries = extract_entries(categories, parsed_groups)
|
||||||
entries = extract_entries(categories, groups)
|
|
||||||
|
|
||||||
stars_data = load_stars(website / "data" / "github_stars.json")
|
stars_data = load_stars(website / "data" / "github_stars.json")
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
@@ -186,8 +166,7 @@ def build(repo_root: str) -> None:
|
|||||||
(site_dir / "index.html").write_text(
|
(site_dir / "index.html").write_text(
|
||||||
tpl_index.render(
|
tpl_index.render(
|
||||||
categories=categories,
|
categories=categories,
|
||||||
resources=[],
|
groups=parsed_groups,
|
||||||
groups=groups,
|
|
||||||
subtitle=subtitle,
|
subtitle=subtitle,
|
||||||
entries=entries,
|
entries=entries,
|
||||||
total_entries=total_entries,
|
total_entries=total_entries,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from pathlib import Path
|
|||||||
from build import (
|
from build import (
|
||||||
build,
|
build,
|
||||||
extract_github_repo,
|
extract_github_repo,
|
||||||
group_categories,
|
|
||||||
load_stars,
|
load_stars,
|
||||||
sort_entries,
|
sort_entries,
|
||||||
)
|
)
|
||||||
@@ -42,40 +41,6 @@ class TestSlugify:
|
|||||||
assert slugify(" Date and Time ") == "date-and-time"
|
assert slugify(" Date and Time ") == "date-and-time"
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# group_categories
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
class TestGroupCategories:
|
|
||||||
def test_appends_resources(self):
|
|
||||||
parsed_groups = [
|
|
||||||
{"name": "G1", "slug": "g1", "categories": [{"name": "Cat1"}]},
|
|
||||||
]
|
|
||||||
resources = [{"name": "Newsletters", "slug": "newsletters"}]
|
|
||||||
groups = group_categories(parsed_groups, resources)
|
|
||||||
group_names = [g["name"] for g in groups]
|
|
||||||
assert "G1" in group_names
|
|
||||||
assert "Resources" in group_names
|
|
||||||
|
|
||||||
def test_no_resources_no_extra_group(self):
|
|
||||||
parsed_groups = [
|
|
||||||
{"name": "G1", "slug": "g1", "categories": [{"name": "Cat1"}]},
|
|
||||||
]
|
|
||||||
groups = group_categories(parsed_groups, [])
|
|
||||||
assert len(groups) == 1
|
|
||||||
assert groups[0]["name"] == "G1"
|
|
||||||
|
|
||||||
def test_preserves_group_order(self):
|
|
||||||
parsed_groups = [
|
|
||||||
{"name": "Second", "slug": "second", "categories": [{"name": "C2"}]},
|
|
||||||
{"name": "First", "slug": "first", "categories": [{"name": "C1"}]},
|
|
||||||
]
|
|
||||||
groups = group_categories(parsed_groups, [])
|
|
||||||
assert groups[0]["name"] == "Second"
|
|
||||||
assert groups[1]["name"] == "First"
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# build (integration)
|
# build (integration)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user