Source code for smarter.common.utils.version

"""
Utility functions for version management.
"""

import re
from functools import cache

from smarter.common.const import VERSION


[docs] @cache def get_semantic_version() -> str: """ Return the semantic version number. Example valid values of __version__.py are: 0.1.17 0.1.17-alpha.1 0.1.17-beta.1 0.1.17-next.1 0.1.17-next.2 0.1.17-next.123456 0.1.17-next-major.1 0.1.17-next-major.2 0.1.17-next-major.123456 Note: - pypi does not allow semantic version numbers to contain a dash. - pypi does not allow semantic version numbers to contain a 'v' prefix. - pypi does not allow semantic version numbers to contain a 'next' suffix. """ if not isinstance(VERSION, dict): return "unknown" version = VERSION.get("__version__") if not version: return "unknown" version = re.sub(r"-next\.\d+", "", version) return re.sub(r"-next-major\.\d+", "", version)
__all__ = ["get_semantic_version"]