Skip to content

versionmgr

Utility functions for managing pyRevit versions.

Examples:

from pyrevit import versionmgr
v = versionmgr.get_pyrevit_version()
v.get_formatted()
'4.10-beta2'

Attributes

mlogger = get_logger(__name__) module-attribute

VERSION_REGEX = '\\A(\\d+)\\.(\\d+)\\.(\\d+)\\.?(.+)?\\Z' module-attribute

Functions:

parse_version_string(version_string)

Split a version string into (major, minor, patch, metadata) parts.

The whole value has to be a version. An unanchored match would let a malformed session value contribute a version to the string the About window shows, which is the same class of stale report this module exists to prevent.

Parameters:

Name Type Description Default
version_string str

version string, e.g. "7.0.0.26273+1554"

required

Returns:

Type Description
tuple

(int, int, int, str) parts, or None if the string is not a version

Source code in pyrevitlib/pyrevit/versionmgr/__init__.py
def parse_version_string(version_string):
    """Split a version string into (major, minor, patch, metadata) parts.

    The whole value has to be a version. An unanchored match would let a malformed
    session value contribute a version to the string the About window shows, which
    is the same class of stale report this module exists to prevent.

    Args:
        version_string (str): version string, e.g. "7.0.0.26273+1554"

    Returns:
        (tuple): (int, int, int, str) parts, or None if the string is not a version
    """
    if not version_string:
        return None

    try:
        matches = re.findall(VERSION_REGEX, safe_strtype(version_string).strip())[0]
    except (IndexError, re.error):
        return None

    try:
        major, minor, patch = (int(matches[0]), int(matches[1]), int(matches[2]))
    except (TypeError, ValueError):
        return None

    metadata = matches[3] if len(matches) == 4 else ""
    return major, minor, patch, metadata

get_loaded_build_version()

Version of the build the running session loaded, or None.

The loader seeds PYREVIT_VERSION from the informational version of the loaded pyRevit Runtime assembly, so this is the build actually executing in Revit. The version file in the clone describes the checkout instead, and the two disagree whenever the clone's bin/ came from a release image or from CI artifacts.

Returns:

Type Description
str

version string of the loaded build, or None outside a session

Source code in pyrevitlib/pyrevit/versionmgr/__init__.py
def get_loaded_build_version():
    """Version of the build the running session loaded, or None.

    The loader seeds ``PYREVIT_VERSION`` from the informational version of the loaded
    pyRevit Runtime assembly, so this is the build actually executing in Revit. The
    version file in the clone describes the checkout instead, and the two disagree
    whenever the clone's ``bin/`` came from a release image or from CI artifacts.

    Returns:
        (str): version string of the loaded build, or None outside a session
    """
    try:
        return envvars.get_pyrevit_env_var(envvars.VERSION_ENVVAR)
    except Exception as env_err:
        mlogger.debug("Can not read the session build version. | %s", env_err)
    return None

get_pyrevit_repo()

Return pyRevit repository.

Returns:

Type Description
RepoInfo

repo wrapper object

Source code in pyrevitlib/pyrevit/versionmgr/__init__.py
def get_pyrevit_repo():
    """Return pyRevit repository.

    Returns:
        (pyrevit.coreutils.git.RepoInfo): repo wrapper object
    """
    try:
        return git.get_repo(HOME_DIR)
    except Exception as repo_err:
        mlogger.debug("Can not create repo from directory: %s | %s", HOME_DIR, repo_err)

get_pyrevit_version()

Return information about active pyRevit version.

The version reported is the one stamped into the assemblies the session loaded, falling back on the clone's version file when no session is running.

Returns:

Type Description
_PyRevitVersion

version wrapper object

Source code in pyrevitlib/pyrevit/versionmgr/__init__.py
def get_pyrevit_version():
    """Return information about active pyRevit version.

    The version reported is the one stamped into the assemblies the session loaded,
    falling back on the clone's version file when no session is running.

    Returns:
        (_PyRevitVersion): version wrapper object
    """
    try:
        commit_hash = get_pyrevit_repo().last_commit_hash
    except Exception as ver_err:
        mlogger.debug("Can not get pyRevit patch number. | %s", ver_err)
        commit_hash = ""

    return _PyRevitVersion(commit_hash, get_loaded_build_version())

get_pyrevit_cli_version()

Return version of shipped pyRevit CLI utility.

Returns:

Type Description
str

version string of pyRevit CLI utility binary

Source code in pyrevitlib/pyrevit/versionmgr/__init__.py
def get_pyrevit_cli_version():
    """Return version of shipped pyRevit CLI utility.

    Returns:
        (str): version string of pyRevit CLI utility binary
    """
    return coreutils.get_exe_version(PYREVIT_CLI_PATH)