def get_version()

in setup.py [0:0]


def get_version() -> str:
    """Retrieves the version of the library."""
    if version := os.getenv("BUILD_VERSION"):
        return version
    cwd = os.path.dirname(os.path.abspath(__file__))
    version_file_path = os.path.join(_PACKAGE_NAME, _VERSION_FILE)
    version_regex = r"__version__: str = ['\"]([^'\"]*)['\"]"
    with open(version_file_path, "r") as f:
        search = re.search(version_regex, f.read(), re.M)
    assert search
    version = search.group(1)

    try:
        sha = (
            subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd)
            .decode("ascii")
            .strip()
        )
        version += "+" + sha[:7]
    except Exception:
        pass
    return version