How to use the dunamai.__init__.Style function in dunamai

To help you get started, we’ve selected a few dunamai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mtkennerly / dunamai / dunamai / __init__.py View on Github external
def check_version(version: str, style: Style = Style.Pep440) -> None:
    """
    Check if a version is valid for a style.

    :param version: Version to check.
    :param style: Style against which to check.
    """
    name, pattern = {
        Style.Pep440: ("PEP 440", _VALID_PEP440),
        Style.SemVer: ("Semantic Versioning", _VALID_SEMVER),
        Style.Pvp: ("PVP", _VALID_PVP),
    }[style]
    failure_message = "Version '{}' does not conform to the {} style".format(version, name)
    if not re.search(pattern, version):
        raise ValueError(failure_message)
    if style == Style.SemVer:
        parts = re.split(r"[.-]", version.split("+", 1)[0])
        if any(re.search(r"^0[0-9]+$", x) for x in parts):
            raise ValueError(failure_message)
github mtkennerly / dunamai / dunamai / __init__.py View on Github external
if metadata is not False:
            if (metadata or self.distance > 0) and self.commit is not None:
                meta_parts.append(self.commit)
            if dirty and self.dirty:
                meta_parts.append("dirty")

        pre_parts = []
        if self.stage is not None:
            pre_parts.append(self.stage)
            if self.revision is not None:
                pre_parts.append(str(self.revision))
        if self.distance > 0:
            pre_parts.append("post")
            pre_parts.append(str(self.distance))

        if style == Style.Pep440:
            if self.distance <= 0:
                out = serialize_pep440(
                    self.base, stage=self.stage, revision=self.revision, metadata=meta_parts
                )
            else:
                out = serialize_pep440(
                    self.base,
                    stage=self.stage,
                    revision=self.revision,
                    post=self.distance,
                    dev=0,
                    metadata=meta_parts,
                )
        elif style == Style.SemVer:
            out = serialize_semver(self.base, pre=pre_parts, metadata=meta_parts)
        elif style == Style.Pvp: