How to use the dunamai.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 / tests / unit / test_dunamai.py View on Github external
def test__version__serialize__semver() -> None:
    style = Style.SemVer
    assert Version("0.1.0").serialize(style=style) == "0.1.0"

    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(
            style=style
        )
        == "0.1.0-alpha.2.post.3+abc"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(
            dirty=True, style=style
        )
        == "0.1.0-alpha.2.post.3+abc.dirty"
    )
    assert (
        Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(
github mtkennerly / dunamai / tests / unit / test_dunamai.py View on Github external
def test__check_version__pvp() -> None:
    style = Style.Pvp

    check_version("1", style=style)
    check_version("0.1", style=style)
    check_version("0.0.1", style=style)
    check_version("0.0.0.1", style=style)
    check_version("0.1.0-alpha-1", style=style)

    with pytest.raises(ValueError):
        check_version("0.1.0-a.1", style=style)
github mtkennerly / dunamai / dunamai / __main__.py View on Github external
from_vcs(
                Vcs(args.vcs),
                args.pattern,
                args.metadata,
                args.dirty,
                args.format,
                Style(args.style) if args.style else None,
                args.latest_tag,
                tag_dir,
                args.debug,
            )
        elif args.command == "check":
            version = from_stdin(args.version)
            if version is None:
                raise ValueError("A version must be specified")
            check_version(version, Style(args.style))
    except Exception as e:
        print(e, file=sys.stderr)
        sys.exit(1)
github mtkennerly / dunamai / dunamai / __main__.py View on Github external
def main() -> None:
    args = parse_args()
    try:
        if args.command == "from":
            tag_dir = getattr(args, "tag_dir", "tags")
            from_vcs(
                Vcs(args.vcs),
                args.pattern,
                args.metadata,
                args.dirty,
                args.format,
                Style(args.style) if args.style else None,
                args.latest_tag,
                tag_dir,
                args.debug,
            )
        elif args.command == "check":
            version = from_stdin(args.version)
            if version is None:
                raise ValueError("A version must be specified")
            check_version(version, Style(args.style))
    except Exception as e:
        print(e, file=sys.stderr)
        sys.exit(1)
github mtkennerly / poetry-dynamic-versioning / poetry_dynamic_versioning / __init__.py View on Github external
def _get_version(config: Mapping) -> Tuple[Version, str]:
    vcs = Vcs(config["vcs"])
    style = config["style"]
    if style is not None:
        style = Style(style)

    version = Version.from_vcs(
        vcs, config["pattern"], config["latest-tag"], config["subversion"]["tag-dir"]
    )
    if config["format-jinja"]:
        default_context = {
            "base": version.base,
            "stage": version.stage,
            "revision": version.revision,
            "distance": version.distance,
            "commit": version.commit,
            "dirty": version.dirty,
            "env": os.environ,
            "bump_version": bump_version,
            "serialize_pep440": serialize_pep440,
            "serialize_pvp": serialize_pvp,
github mtkennerly / dunamai / dunamai / __main__.py View on Github external
" This should contain one capture group named `base` corresponding to"
            " the release segment of the source, and optionally another two groups"
            " named `stage` and `revision` corresponding to a prerelease type"
            " (such as 'alpha' or 'rc') and number (such as in 'alpha-2' or 'rc3')"
        ),
    },
    {
        "triggers": ["--format"],
        "help": (
            "Custom output format. Available substitutions:"
            " {base}, {stage}, {revision}, {distance}, {commit}, {dirty}"
        ),
    },
    {
        "triggers": ["--style"],
        "choices": [x.value for x in Style],
        "help": (
            "Preconfigured output format."
            " Will default to PEP 440 if not set and no custom format given."
            " If you specify both a style and a custom format, then the format"
            " will be validated against the style's rules"
        ),
    },
    {
        "triggers": ["--latest-tag"],
        "action": "store_true",
        "dest": "latest_tag",
        "default": False,
        "help": "Only inspect the latest tag on the latest tagged commit for a pattern match",
    },
    {
        "triggers": ["--debug"],
github mtkennerly / dunamai / dunamai / __main__.py View on Github external
},
            },
        },
        "check": {
            "description": "Check if a version is valid for a style",
            "args": [
                {
                    "triggers": [],
                    "dest": "version",
                    "help": "Version to check; may be piped in",
                    "nargs": "?",
                },
                {
                    "triggers": ["--style"],
                    "choices": [x.value for x in Style],
                    "default": Style.Pep440.value,
                    "help": "Style against which to check",
                },
            ],
        },
    },
}


def build_parser(spec: Mapping, parser: argparse.ArgumentParser = None) -> argparse.ArgumentParser:
    if parser is None:
        parser = argparse.ArgumentParser(
            description=spec["description"], formatter_class=argparse.ArgumentDefaultsHelpFormatter
        )
    if "args" in spec:
        for arg in spec["args"]:
            triggers = arg["triggers"]