How to use the dunamai.Version.from_git 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 / poetry-dynamic-versioning / tests / test_poetry_dynamic_versioning.py View on Github external
def test__get_version__defaults(config):
    v, s = plugin._get_version(config)
    assert v == Version.from_git()
    assert s == Version.from_git().serialize()
github mtkennerly / poetry-dynamic-versioning / tests / test_poetry_dynamic_versioning.py View on Github external
def test__get_version__defaults(config):
    v, s = plugin._get_version(config)
    assert v == Version.from_git()
    assert s == Version.from_git().serialize()
github mtkennerly / dunamai / tests / integration / test_dunamai.py View on Github external
def test__version__from_git(tmp_path) -> None:
    vcs = tmp_path / "dunamai-git"
    vcs.mkdir()
    run = make_run_callback(vcs)
    from_vcs = make_from_callback(Version.from_git)

    with chdir(vcs):
        run("git init")
        assert from_vcs() == Version("0.0.0", distance=0, commit=None, dirty=True)

        (vcs / "foo.txt").write_text("hi")
        assert from_vcs() == Version("0.0.0", distance=0, commit=None, dirty=True)

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

        # Additional one-off check not in other VCS integration tests:
        # when the only tag in the repository does not match the pattern.
        run("git tag other")
        with pytest.raises(ValueError):
github systemslab / popper / src / popper / __init__.py View on Github external
_dunamai_found = _dunamai_spec is not None

if _dunamai_found:

    # if dunamai is found, then we use it to display the version
    import dunamai

    # if codebase is inside a git repo, define GIT_DIR so dunamai gets the info for the
    # popper repo instead of wherever popper is being invoked from
    _git_dir = os.path.join(_repo_dir, ".git")

    if os.path.isdir(_git_dir):
        os.environ["GIT_DIR"] = _git_dir

    try:
        __version__ = dunamai.Version.from_git().serialize()
        _ver = f"__popper_version__ = '{__version__}'"
    except RuntimeError as e:
        # only raise if not a dunamai-raised error
        if "This does not appear to be a Git project" not in str(e):
            raise e

    with open(_version_file, "w") as v:
        v.write(_ver + "\n")

    # unset GIT_DIR
    os.environ.pop("GIT_DIR", None)

elif os.path.isfile(_version_file):
    # codebase not in a popper repo, and version file exists, so let's read from it
    from popper._version import __popper_version__ as _ver