feat: partially write artifact module
This commit is contained in:
@@ -9,12 +9,9 @@ top of :class:`renders.common.BaseRender`.
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
from re import Pattern, compile
|
||||
from . import common
|
||||
from semver import Version
|
||||
|
||||
|
||||
_CMAKE_NAME_PATTERN: Pattern = compile(r"[a-zA-Z0-9_.+-]+")
|
||||
from . import common
|
||||
from .. import utils
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -56,11 +53,11 @@ class CMakeProperties:
|
||||
the version carries a prerelease or build component (unsupported by
|
||||
CMake config-version files).
|
||||
"""
|
||||
if _CMAKE_NAME_PATTERN.fullmatch(self.namespace_name) is None:
|
||||
if not utils.is_good_name(self.namespace_name):
|
||||
raise ValueError(
|
||||
"bad namespace component in CMake. consider manually specifying it"
|
||||
)
|
||||
if _CMAKE_NAME_PATTERN.fullmatch(self.target_name) is None:
|
||||
if not utils.is_good_name(self.target_name) is None:
|
||||
raise ValueError(
|
||||
"bad target name component in CMake. consider manually specifying it"
|
||||
)
|
||||
@@ -68,7 +65,7 @@ class CMakeProperties:
|
||||
raise ValueError("bad artifact dll file name in CMake")
|
||||
if self.artifact_lib == "":
|
||||
raise ValueError("bad artifact lib file name in CMake")
|
||||
if self.version.prerelease is not None or self.version.build is not None:
|
||||
if not utils.is_good_version(self.version):
|
||||
raise ValueError(
|
||||
"unsupported semantic version components (prerelease or build) in CMake"
|
||||
)
|
||||
|
||||
@@ -9,10 +9,25 @@ 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.match(s) is None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class PkgConfigProperties:
|
||||
"""Inputs required to render the pkg-config ``.pc`` file.
|
||||
@@ -49,11 +64,13 @@ class PkgConfigProperties:
|
||||
version carries a prerelease or build component (unsupported in
|
||||
pkg-config).
|
||||
"""
|
||||
if self.name == "":
|
||||
raise ValueError("unexpected blank name of pkg-config")
|
||||
if self.description == "":
|
||||
raise ValueError("unexpected blank description of pkg-config")
|
||||
if self.version.prerelease is not None or self.version.build is not None:
|
||||
if self.name == "" or not _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):
|
||||
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")
|
||||
if not utils.is_good_version(self.version):
|
||||
raise ValueError(
|
||||
"unsupported semantic version components (prerelease or build) in pkg-config"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user