mirror of
https://github.com/vinta/awesome-python.git
synced 2026-05-24 06:36:06 +08:00
style(website): apply ruff format
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,6 @@ from itertools import batched
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from build import extract_github_repo, load_stars
|
from build import extract_github_repo, load_stars
|
||||||
|
|
||||||
CACHE_MAX_AGE_HOURS = 12
|
CACHE_MAX_AGE_HOURS = 12
|
||||||
@@ -53,10 +52,7 @@ def build_graphql_query(repos: Sequence[str]) -> str:
|
|||||||
owner, name = repo.split("/", 1)
|
owner, name = repo.split("/", 1)
|
||||||
if not GITHUB_OWNER_RE.match(owner) or not GITHUB_NAME_RE.match(name):
|
if not GITHUB_OWNER_RE.match(owner) or not GITHUB_NAME_RE.match(name):
|
||||||
continue
|
continue
|
||||||
parts.append(
|
parts.append(f'repo_{i}: repository(owner: "{owner}", name: "{name}") {{ stargazerCount owner {{ login }} defaultBranchRef {{ target {{ ... on Commit {{ committedDate }} }} }} }}')
|
||||||
f'repo_{i}: repository(owner: "{owner}", name: "{name}") '
|
|
||||||
f"{{ stargazerCount owner {{ login }} defaultBranchRef {{ target {{ ... on Commit {{ committedDate }} }} }} }}"
|
|
||||||
)
|
|
||||||
if not parts:
|
if not parts:
|
||||||
return ""
|
return ""
|
||||||
return "query { " + " ".join(parts) + " }"
|
return "query { " + " ".join(parts) + " }"
|
||||||
|
|||||||
+22
-17
@@ -229,18 +229,22 @@ def _parse_list_entries(
|
|||||||
if sub_inline:
|
if sub_inline:
|
||||||
sub_link = _find_child(sub_inline, "link")
|
sub_link = _find_child(sub_inline, "link")
|
||||||
if sub_link:
|
if sub_link:
|
||||||
also_see.append(AlsoSee(
|
also_see.append(
|
||||||
name=render_inline_text(sub_link.children),
|
AlsoSee(
|
||||||
url=_href(sub_link),
|
name=render_inline_text(sub_link.children),
|
||||||
))
|
url=_href(sub_link),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
entries.append(ParsedEntry(
|
entries.append(
|
||||||
name=name,
|
ParsedEntry(
|
||||||
url=url,
|
name=name,
|
||||||
description=desc_html,
|
url=url,
|
||||||
also_see=also_see,
|
description=desc_html,
|
||||||
subcategory=subcategory,
|
also_see=also_see,
|
||||||
))
|
subcategory=subcategory,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
@@ -275,7 +279,6 @@ def _build_section(name: str, body: list[SyntaxTreeNode]) -> ParsedSection:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _is_bold_marker(node: SyntaxTreeNode) -> str | None:
|
def _is_bold_marker(node: SyntaxTreeNode) -> str | None:
|
||||||
"""Detect a bold-only paragraph used as a group marker.
|
"""Detect a bold-only paragraph used as a group marker.
|
||||||
|
|
||||||
@@ -321,11 +324,13 @@ def _parse_grouped_sections(
|
|||||||
nonlocal current_group_name, current_group_cats
|
nonlocal current_group_name, current_group_cats
|
||||||
if current_group_cats:
|
if current_group_cats:
|
||||||
name = current_group_name or "Other"
|
name = current_group_name or "Other"
|
||||||
groups.append(ParsedGroup(
|
groups.append(
|
||||||
name=name,
|
ParsedGroup(
|
||||||
slug=slugify(name),
|
name=name,
|
||||||
categories=list(current_group_cats),
|
slug=slugify(name),
|
||||||
))
|
categories=list(current_group_cats),
|
||||||
|
)
|
||||||
|
)
|
||||||
current_group_name = None
|
current_group_name = None
|
||||||
current_group_cats = []
|
current_group_cats = []
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,12 @@ class TestExtractGithubRepos:
|
|||||||
assert result == {"psf/requests"}
|
assert result == {"psf/requests"}
|
||||||
|
|
||||||
def test_multiple_repos(self):
|
def test_multiple_repos(self):
|
||||||
readme = (
|
readme = "* [requests](https://github.com/psf/requests) - HTTP.\n* [flask](https://github.com/pallets/flask) - Micro."
|
||||||
"* [requests](https://github.com/psf/requests) - HTTP.\n"
|
|
||||||
"* [flask](https://github.com/pallets/flask) - Micro."
|
|
||||||
)
|
|
||||||
result = extract_github_repos(readme)
|
result = extract_github_repos(readme)
|
||||||
assert result == {"psf/requests", "pallets/flask"}
|
assert result == {"psf/requests", "pallets/flask"}
|
||||||
|
|
||||||
def test_deduplicates(self):
|
def test_deduplicates(self):
|
||||||
readme = (
|
readme = "* [a](https://github.com/org/repo) - A.\n* [b](https://github.com/org/repo) - B."
|
||||||
"* [a](https://github.com/org/repo) - A.\n"
|
|
||||||
"* [b](https://github.com/org/repo) - B."
|
|
||||||
)
|
|
||||||
result = extract_github_repos(readme)
|
result = extract_github_repos(readme)
|
||||||
assert result == {"org/repo"}
|
assert result == {"org/repo"}
|
||||||
|
|
||||||
|
|||||||
@@ -350,10 +350,7 @@ def _content_nodes(md_text: str) -> list[SyntaxTreeNode]:
|
|||||||
|
|
||||||
class TestParseSectionEntries:
|
class TestParseSectionEntries:
|
||||||
def test_flat_entries(self):
|
def test_flat_entries(self):
|
||||||
nodes = _content_nodes(
|
nodes = _content_nodes("- [django](https://example.com/d) - A web framework.\n- [flask](https://example.com/f) - A micro framework.\n")
|
||||||
"- [django](https://example.com/d) - A web framework.\n"
|
|
||||||
"- [flask](https://example.com/f) - A micro framework.\n"
|
|
||||||
)
|
|
||||||
entries = _parse_section_entries(nodes)
|
entries = _parse_section_entries(nodes)
|
||||||
assert len(entries) == 2
|
assert len(entries) == 2
|
||||||
assert entries[0]["name"] == "django"
|
assert entries[0]["name"] == "django"
|
||||||
@@ -370,13 +367,7 @@ class TestParseSectionEntries:
|
|||||||
assert entries[0]["description"] == ""
|
assert entries[0]["description"] == ""
|
||||||
|
|
||||||
def test_subcategorized_entries(self):
|
def test_subcategorized_entries(self):
|
||||||
nodes = _content_nodes(
|
nodes = _content_nodes("- Algorithms\n - [algos](https://x.com/a) - Algo lib.\n - [sorts](https://x.com/s) - Sort lib.\n- Design Patterns\n - [patterns](https://x.com/p) - Pattern lib.\n")
|
||||||
"- Algorithms\n"
|
|
||||||
" - [algos](https://x.com/a) - Algo lib.\n"
|
|
||||||
" - [sorts](https://x.com/s) - Sort lib.\n"
|
|
||||||
"- Design Patterns\n"
|
|
||||||
" - [patterns](https://x.com/p) - Pattern lib.\n"
|
|
||||||
)
|
|
||||||
entries = _parse_section_entries(nodes)
|
entries = _parse_section_entries(nodes)
|
||||||
assert len(entries) == 3
|
assert len(entries) == 3
|
||||||
assert entries[0]["name"] == "algos"
|
assert entries[0]["name"] == "algos"
|
||||||
@@ -432,7 +423,7 @@ class TestParseSectionEntries:
|
|||||||
assert cats[0]["entry_count"] == 3
|
assert cats[0]["entry_count"] == 3
|
||||||
|
|
||||||
def test_description_html_escapes_xss(self):
|
def test_description_html_escapes_xss(self):
|
||||||
nodes = _content_nodes('- [lib](https://x.com) - A <script>alert(1)</script> lib.\n')
|
nodes = _content_nodes("- [lib](https://x.com) - A <script>alert(1)</script> lib.\n")
|
||||||
entries = _parse_section_entries(nodes)
|
entries = _parse_section_entries(nodes)
|
||||||
assert "<script>" not in entries[0]["description"]
|
assert "<script>" not in entries[0]["description"]
|
||||||
assert "<script>" in entries[0]["description"]
|
assert "<script>" in entries[0]["description"]
|
||||||
|
|||||||
Reference in New Issue
Block a user