Add _normalize_release_info() to ensure get_release_info() returns keys expected by the CLI release command regardless of whether the release-management capability is available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
"""
|
|
Version information for MarkiTect.
|
|
|
|
This module provides version information using setuptools-scm.
|
|
Version is automatically derived from git tags.
|
|
"""
|
|
|
|
try:
|
|
from ._version import version as __version__
|
|
except ImportError:
|
|
# Fallback when _version.py is not available (e.g., during development without setuptools-scm)
|
|
__version__ = "unknown"
|
|
|
|
def get_version():
|
|
"""Get the current version string."""
|
|
return __version__
|
|
|
|
def get_version_info():
|
|
"""Get comprehensive version information by delegating to release-management capability."""
|
|
try:
|
|
# Delegate to release-management capability
|
|
from pathlib import Path
|
|
project_root = Path(__file__).parent.parent
|
|
|
|
try:
|
|
from release_management.utils.version import get_version_info as rm_get_version_info
|
|
return rm_get_version_info(project_root)
|
|
except ImportError:
|
|
# Fallback if release-management capability is not available
|
|
pass
|
|
except Exception:
|
|
pass
|
|
|
|
# Simple fallback implementation
|
|
try:
|
|
from ._version import version_tuple, commit_id
|
|
except ImportError:
|
|
version_tuple = ("unknown",)
|
|
commit_id = "unknown"
|
|
|
|
return {
|
|
'full_version': __version__,
|
|
'short_version': __version__.split('.dev')[0] if '.dev' in __version__ else __version__,
|
|
'version_tuple': version_tuple,
|
|
'commit_id': commit_id,
|
|
'is_dev': '.dev' in __version__,
|
|
'git_commit': commit_id,
|
|
'git_branch': 'unknown',
|
|
'is_git_repo': False
|
|
}
|
|
|
|
def _normalize_release_info(raw):
|
|
"""Ensure release info dict has the keys the CLI release command expects."""
|
|
if 'full_version' in raw:
|
|
return raw # already in expected format
|
|
|
|
import subprocess
|
|
|
|
version = raw.get('version', 'unknown')
|
|
is_dev = raw.get('is_development', '.dev' in version)
|
|
commit = raw.get('git_commit', 'unknown')
|
|
|
|
# Detect git repo and current tag
|
|
is_git_repo = False
|
|
git_tag = None
|
|
try:
|
|
subprocess.check_output(['git', 'rev-parse', '--git-dir'], stderr=subprocess.DEVNULL)
|
|
is_git_repo = True
|
|
tag_out = subprocess.check_output(
|
|
['git', 'describe', '--tags', '--exact-match', 'HEAD'],
|
|
stderr=subprocess.DEVNULL,
|
|
).decode().strip()
|
|
if tag_out:
|
|
git_tag = tag_out
|
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
pass
|
|
|
|
return {
|
|
'full_version': version,
|
|
'release_type': 'development' if is_dev else 'release',
|
|
'build_from': 'git' if is_git_repo else 'source',
|
|
'commit': commit,
|
|
'clean_build': not is_dev,
|
|
'is_git_repo': is_git_repo,
|
|
'git_tag': git_tag,
|
|
}
|
|
|
|
|
|
def get_release_info():
|
|
"""Get release information by delegating to release-management capability."""
|
|
try:
|
|
from pathlib import Path
|
|
project_root = Path(__file__).parent.parent
|
|
|
|
try:
|
|
from release_management.utils.version import get_release_info as rm_get_release_info
|
|
return _normalize_release_info(rm_get_release_info(project_root))
|
|
except ImportError:
|
|
pass
|
|
except Exception:
|
|
pass
|
|
|
|
# Fallback — build from version_info directly
|
|
version_info = get_version_info()
|
|
return _normalize_release_info({
|
|
'version': version_info['full_version'],
|
|
'is_development': version_info['is_dev'],
|
|
'git_commit': version_info.get('git_commit', 'unknown'),
|
|
}) |