diff options
| author | Dennis Fink | 2026-11-12 22:07:12 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-12 22:07:12 +0100 |
| commit | c7993952c585b66acad5275e39dbf91cf662b975 (patch) | |
| tree | 976b3746444b3bd0bbb269bef9197c8b6a2e1696 /webmentions_ssg/tasks/source_parser.py | |
| parent | b930b4425b91aa42abcec6c3443685065a5ca242 (diff) | |
| download | webmentions-ssg-c7993952c585b66acad5275e39dbf91cf662b975.tar.gz webmentions-ssg-c7993952c585b66acad5275e39dbf91cf662b975.zip | |
chore(core): enable stricter Ruff lint rules
Expand Ruff checks for bugbear, complexity, pathlib, return statements,
simplifications, upgrades, and docstring style.
Apply the resulting behavior-neutral cleanup across application and test
code.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/tasks/source_parser.py | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/webmentions_ssg/tasks/source_parser.py b/webmentions_ssg/tasks/source_parser.py index cb15ab6..1bd498c 100644 --- a/webmentions_ssg/tasks/source_parser.py +++ b/webmentions_ssg/tasks/source_parser.py @@ -72,8 +72,7 @@ class ScannedSource: def source_url_for_path(relative_path: Path, base_url: str) -> str: - """ - Derive the public source URL from a relative filesystem path. + """Derive the public source URL from a relative filesystem path. :param relative_path: Path of the source document relative to the source root. :param base_url: Base URL under which source documents are published. @@ -87,8 +86,7 @@ def source_url_for_path(relative_path: Path, base_url: str) -> str: def canonical_url( document: BeautifulSoup, *, relative_path: Path, base_url: str | None ) -> str | None: - """ - Return the canonical URL declared by a source document. + """Return the canonical URL declared by a source document. Relative canonical URLs are resolved against the configured source base URL. @@ -122,11 +120,11 @@ def canonical_url( ) return resolved + return None def property_urls(entry: dict[str, Any], property_name: str) -> Iterator[str]: - """ - Yield URL values from a microformats property. + """Yield URL values from a microformats property. :param entry: Parsed microformats entry. :param property_name: Name of the property to inspect. @@ -146,8 +144,7 @@ def property_urls(entry: dict[str, Any], property_name: str) -> Iterator[str]: def parse_entry(element: Tag, base_url: str) -> dict[str, Any]: - """ - Parse and validate an h-entry with mf2py. + """Parse and validate an h-entry with mf2py. :param element: HTML element containing the h-entry. :param base_url: Base URL used when parsing the microformats data. @@ -180,8 +177,7 @@ def parse_entry(element: Tag, base_url: str) -> dict[str, Any]: def primary_entry( document: BeautifulSoup, source_url: str ) -> tuple[Tag, dict[str, Any]]: - """ - Return and validate the primary h-entry of a source document. + """Return and validate the primary h-entry of a source document. The document must contain exactly one h-entry whose ``u-url`` matches the source URL. @@ -211,8 +207,7 @@ def primary_entry( def content_element(entry: Tag) -> Tag: - """ - Return the e-content element of an h-entry. + """Return the e-content element of an h-entry. :param entry: HTML element containing the h-entry. :return: The h-entry's e-content element. @@ -228,8 +223,7 @@ def content_element(entry: Tag) -> Tag: def normalize_target(value: str, *, base_url: str, source_url: str) -> str | None: - """ - Resolve and validate a possible Webmention target URL. + """Resolve and validate a possible Webmention target URL. Empty values, non-HTTP URLs, and URLs referring to the source itself are discarded. @@ -240,9 +234,7 @@ def normalize_target(value: str, *, base_url: str, source_url: str) -> str | Non :return: Normalized target URL, or ``None`` if the value is not a valid Webmention target. """ - value = value.strip() - - if not value: + if not (value := value.strip()): return None target = urljoin(base_url, value) @@ -264,8 +256,7 @@ def iter_targets( source_url: str, ignored_hostnames: Iterable[str] = (), ) -> Iterator[str]: - """ - Yield outgoing Webmention targets from an h-entry. + """Yield outgoing Webmention targets from an h-entry. Targets are collected from links in the entry content and supported microformats reaction properties. Invalid, self-referencing, and ignored @@ -328,8 +319,7 @@ def scan_source_file( base_url: str | None, ignored_hostnames: Iterable[str] = (), ) -> ScannedSource: - """ - Scan one generated source document for outgoing Webmentions. + """Scan one generated source document for outgoing Webmentions. :param path: Path of the generated HTML document. :param root: Root directory containing generated source documents. |
