Skip to content

Versioning

versioning

Functions:

Name Description
get_last_release

Return the most recent git tag that matches semver format (vX.Y.Z).

get_last_tag

Return the most recent git tag in the current repository.

get_next_releases

Compute the next minor, patch, and major release tags from the last release.

is_valid_semver

Check whether a tag string follows the vX.Y.Z semver format.

get_last_release

get_last_release() -> Optional[str]

Return the most recent git tag that matches semver format (vX.Y.Z).

Returns:

Type Description
Optional[str]

Last semver-formatted release tag, or None if none is found.

Source code in oops/utils/versioning.py
def get_last_release() -> Optional[str]:
    """Return the most recent git tag that matches semver format (vX.Y.Z).

    Returns:
        Last semver-formatted release tag, or None if none is found.
    """
    try:
        last_tag = get_last_tag()
        if not last_tag:
            return None
    except Exception:
        return None

    if not bool(SEMVER_PATTERN.match(last_tag)):
        return None

    return last_tag

get_last_tag

get_last_tag() -> Optional[str]

Return the most recent git tag in the current repository.

Returns:

Type Description
Optional[str]

Most recent tag name, or None if no tags exist or the command fails.

Source code in oops/utils/versioning.py
def get_last_tag() -> Optional[str]:
    """Return the most recent git tag in the current repository.

    Returns:
        Most recent tag name, or None if no tags exist or the command fails.
    """
    try:
        out = run(["git", "describe", "--tags", "--abbrev=0"], capture=True)
        return out.strip() if out else None
    except subprocess.CalledProcessError:
        return None

get_next_releases

get_next_releases() -> tuple

Compute the next minor, patch, and major release tags from the last release.

Returns:

Type Description
tuple

Tuple of (minor_bump, patch_bump, major_bump) version strings, e.g.

tuple

("v1.3.0", "v1.2.4", "v2.0.0") when the last release is v1.2.3.

Raises:

Type Description
ValueError

If no valid semver release tag is found.

Source code in oops/utils/versioning.py
def get_next_releases() -> tuple:
    """Compute the next minor, patch, and major release tags from the last release.

    Returns:
        Tuple of (minor_bump, patch_bump, major_bump) version strings, e.g.
        ``("v1.3.0", "v1.2.4", "v2.0.0")`` when the last release is ``v1.2.3``.

    Raises:
        ValueError: If no valid semver release tag is found.
    """
    last_release = get_last_release()

    if not last_release:
        raise ValueError("No valid release found")

    m = SEMVER_PATTERN.match(last_release)

    if not m:
        raise ValueError(f"Last release tag '{last_release}' is not in valid semver format")

    x, y, z = int(m.group("x")), int(m.group("y")), int(m.group("z"))

    normal = f"v{x}.{y + 1}.0"
    fix = f"v{x}.{y}.{z + 1}"
    major = f"v{x + 1}.0.0"

    return normal, fix, major

is_valid_semver

is_valid_semver(tag: str) -> bool

Check whether a tag string follows the vX.Y.Z semver format.

Parameters:

Name Type Description Default

tag

str

Tag name to validate.

required

Returns:

Type Description
bool

True if the tag matches the semver pattern, False otherwise.

Source code in oops/utils/versioning.py
def is_valid_semver(tag: str) -> bool:
    """Check whether a tag string follows the vX.Y.Z semver format.

    Args:
        tag: Tag name to validate.

    Returns:
        True if the tag matches the semver pattern, False otherwise.
    """
    return bool(SEMVER_PATTERN.match(tag))