How to use the dunamai.Vcs 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 / integration / test_dunamai.py View on Github external
assert from_vcs(latest_tag=True) == Version("0.1.0", commit="abc", dirty=False)
        assert run("dunamai from git") == "0.1.0"
        assert run("dunamai from any") == "0.1.0"

        # Additional one-off checks not in other VCS integration tests:
        assert run(r'dunamai from any --pattern "(?P\d\.\d\.\d)"') == "0.1.0"
        run(r'dunamai from any --pattern "(\d\.\d\.\d)"', 1)
        assert run('dunamai from any --format "v{base}"') == "v0.1.0"
        assert run('dunamai from any --style "semver"') == "0.1.0"
        assert (
            run('dunamai from any --format "v{base}" --style "semver"', 1)
            == "Version 'v0.1.0' does not conform to the Semantic Versioning style"
        )
        assert run("dunamai from any --latest-tag") == "0.1.0"
        assert from_explicit_vcs(Vcs.Any) == Version("0.1.0", commit="abc", dirty=False)
        assert from_explicit_vcs(Vcs.Git) == Version("0.1.0", commit="abc", dirty=False)

        (vcs / "foo.txt").write_text("bye")
        assert from_vcs() == Version("0.1.0", commit="abc", dirty=True)

        run("git add .")
        run('git commit -m "Second"')
        assert from_vcs() == Version("0.1.0", distance=1, commit="abc", dirty=False)
        assert from_any_vcs() == Version("0.1.0", distance=1, commit="abc", dirty=False)

        run("git tag unmatched")
        assert from_vcs() == Version("0.1.0", distance=1, commit="abc", dirty=False)
        with pytest.raises(ValueError):
            from_vcs(latest_tag=True)

        run("git tag v0.2.0 -m 'Annotated'")
        run("git tag v0.1.1 HEAD~1")
github mtkennerly / dunamai / dunamai / __main__.py View on Github external
Vcs.Any.value: {
                    "description": "Generate version from any detected VCS",
                    "args": [
                        *common_sub_args,
                        {
                            "triggers": ["--tag-dir"],
                            "default": "tags",
                            "help": "Location of tags relative to the root (Subversion)",
                        },
                    ],
                },
                Vcs.Git.value: {
                    "description": "Generate version from Git",
                    "args": common_sub_args,
                },
                Vcs.Mercurial.value: {
                    "description": "Generate version from Mercurial",
                    "args": common_sub_args,
                },
                Vcs.Darcs.value: {
                    "description": "Generate version from Darcs",
                    "args": common_sub_args,
                },
                Vcs.Subversion.value: {
                    "description": "Generate version from Subversion",
                    "args": [
                        *common_sub_args,
                        {
                            "triggers": ["--tag-dir"],
                            "default": "tags",
                            "help": "Location of tags relative to the root",
                        },
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,
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)