version ¶
Unified version detection and management system.
This module provides a clean, DRY approach to version handling across all environments: - Development (git describe) - Docker containers (VERSION file) - Production releases (environment variables) - Package metadata (fallback)
The system follows a clear priority order and provides consistent behavior.
Classes:
-
VersionError–Raised when version detection fails in an unexpected way.
-
VersionManager–Centralized version detection and management.
Functions:
-
get_version–Get the current version.
-
is_semantic_version–Check if a version is valid semantic version.
-
compare_versions–Compare two semantic versions.
-
get_version_info–Get detailed version information.
-
get_build_info–Get build information.
-
bump_version–Bump a semantic version.
-
satisfies_constraint–Check if a version satisfies a semver constraint.
-
generate_build_metadata–Generate build metadata string from git SHA and build date.
Classes¶
VersionManager ¶
VersionManager(root_path: Path | None = None)
Centralized version detection and management.
This class provides a single source of truth for version information across all environments and use cases.
Initialize the version manager.
Parameters:
-
root_path(Path, default:None) –Root path of the project. If None, will be auto-detected.
Methods:
-
get_version–Get the current version using the established priority order.
-
is_semantic_version–Check if a version string is a valid semantic version.
-
compare_versions–Compare two semantic version strings.
-
get_version_info–Get detailed information about a semantic version.
-
get_build_info–Get build information for the current version.
-
bump_version–Bump a semantic version.
-
satisfies_constraint–Check if a version satisfies a semver constraint.
-
generate_build_metadata–Generate build metadata string from git SHA and build date.
Functions¶
get_version ¶
Get the current version using the established priority order.
Priority order: 1. TUX_VERSION environment variable 2. VERSION file in project root 3. Git describe (if git is available) 4. "dev" as final fallback
Parameters:
-
force_refresh(bool, default:False) –If True, bypass cache and detect version fresh.
Returns:
-
str–The detected version string.
_from_environment ¶
_from_environment() -> str | None
Get version from TUX_VERSION environment variable.
Returns:
-
str or None–The version from environment, or None if not set.
_from_version_file ¶
_from_version_file() -> str | None
Get version from VERSION file in project root.
Returns:
-
str or None–The version from VERSION file, or None if not found.
_from_git ¶
_from_git() -> str | None
Get version from git describe.
Returns:
-
str or None–The version from git describe, or None if git is unavailable.
_normalize_version ¶
is_semantic_version ¶
compare_versions ¶
Compare two semantic version strings.
Parameters:
Returns:
-
int–-1 if version1 < version2, 0 if equal, 1 if version1 > version2.
Raises:
-
ValueError–If either version is not a valid semantic version.
get_version_info ¶
get_build_info ¶
Get build information for the current version.
Returns:
-
dict–Dictionary containing build metadata.
bump_version ¶
Bump a semantic version.
Parameters:
Returns:
-
str–The bumped version string.
Raises:
-
ValueError–If version is not semantic or bump_type is invalid.
satisfies_constraint ¶
Check if a version satisfies a semver constraint.
Parameters:
Returns:
-
bool–True if version satisfies the constraint.
Raises:
-
ValueError–If constraint syntax is invalid.
generate_build_metadata ¶
Generate build metadata string from git SHA and build date.
Parameters:
-
git_sha(str, default:None) –Git SHA (short form). If None, attempts to detect from git.
-
build_date(str, default:None) –Build date in YYYYMMDD format. If None, uses current date.
Returns:
-
str–Build metadata string (e.g., "sha.abcdef.20231029").
Functions¶
is_semantic_version ¶
compare_versions ¶
get_version_info ¶
get_build_info ¶
bump_version ¶
satisfies_constraint ¶
generate_build_metadata ¶
Generate build metadata string from git SHA and build date.
Parameters:
-
git_sha(str, default:None) –Git SHA (short form). If None, attempts to detect from git.
-
build_date(str, default:None) –Build date in YYYYMMDD format. If None, uses current date.
Returns:
-
str–Build metadata string (e.g., "sha.abcdef.20231029").