doc: add docstring and do some refactor

This commit is contained in:
2026-08-05 15:53:52 +08:00
parent 816e3a59d0
commit 520bfc2054
7 changed files with 264 additions and 21 deletions
@@ -9,25 +9,11 @@ rendering on top of :class:`renders.common.BaseRender`.
from dataclasses import dataclass
from typing import Any
from re import Pattern, compile
from . import common
from .. import utils
from semver import Version
_EOL_PATTERN: Pattern = compile(r"[\r\n]")
def _is_good_sentence(s: str) -> bool:
"""Check whether given string has EOL chars.
This function is used for checking human-readable name and description,
because EOL chars are not allowed in these properties.
:returns: True if given string don't contain any EOL chars, otherwise false.
"""
return _EOL_PATTERN.search(s) is None
@dataclass(frozen=True)
class PkgConfigProperties:
"""Inputs required to render the pkg-config ``.pc`` file.
@@ -64,9 +50,9 @@ class PkgConfigProperties:
version carries a prerelease or build component (unsupported in
pkg-config).
"""
if self.name == "" or not _is_good_sentence(self.name):
if self.name == "" or not utils.is_good_sentence(self.name):
raise ValueError("bad name (blank or has EOL chars) of pkg-config")
if self.description == "" or not _is_good_sentence(self.description):
if self.description == "" or not utils.is_good_sentence(self.description):
raise ValueError("bad description (blank or has EOL chars) of pkg-config")
if not utils.is_good_name(self.artifact):
raise ValueError("bad artifact name in pkg-config")