Skip to content

Commit 8a11944

Browse files
committed
feat: implement dynamic version management with git tags as single source of truth
- Remove obsolete version management files and documentation - Update all scripts to use dynamic version resolution from git tags - Implement robust fallback system for packaged environments - Ensure version consistency across build tools and package - Follow best practices: git tags → env → fallback → default - Remove unnecessary documentation files per best practices
1 parent 54b2e8f commit 8a11944

File tree

6 files changed

+71
-27
lines changed

6 files changed

+71
-27
lines changed

route_planner/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,25 @@
66
and comprehensive offline support.
77
"""
88

9-
__version__ = "1.1.11"
9+
def _get_version():
10+
"""Get version from git tags (single source of truth) or fallback."""
11+
try:
12+
import subprocess
13+
from pathlib import Path
14+
project_root = Path(__file__).parent.parent
15+
result = subprocess.run(
16+
['git', 'describe', '--tags', '--abbrev=0'],
17+
cwd=project_root,
18+
capture_output=True,
19+
text=True,
20+
check=True
21+
)
22+
return result.stdout.strip().lstrip('v')
23+
except (subprocess.CalledProcessError, FileNotFoundError, ImportError):
24+
# Fallback for environments without git or in packaged distributions
25+
return "1.1.11"
26+
27+
__version__ = _get_version()
1028
__author__ = "Route Planner Development Team"
1129

1230
# Ensure config is available at package level

scripts/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This directory contains automation scripts that handle version management, envir
1111
```bash
1212
# Version Management
1313
python scripts/version.py # Show current version
14-
python scripts/version.py --update 1.2.3 # Update package version to 1.2.3
14+
python scripts/version.py --update X.Y.Z # Update package version to X.Y.Z (e.g., 1.2.3)
1515

1616
# Environment & Development
1717
python scripts/setup_env.py # Setup development environment
@@ -97,10 +97,10 @@ route-planner # If installed globally
9797
python scripts/version.py
9898

9999
# Update version for release
100-
python scripts/version.py --update 2.1.0
100+
python scripts/version.py --update X.Y.Z
101101

102102
# Prepare release (updates changelog, creates tag)
103-
python scripts/prepare_release.py --version 2.1.0
103+
python scripts/prepare_release.py --version X.Y.Z
104104
```
105105

106106
### 📦 Building Packages

scripts/build_appimage.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@ def get_version():
5656
from scripts.version import get_version
5757
return get_version()
5858
except ImportError:
59-
# Fallback to a default version
60-
print("⚠️ Could not determine version, using 1.0.0")
61-
return "1.0.0"
59+
# Fallback: try to get version from git or use default
60+
print("⚠️ Could not determine version from package, trying git...")
61+
try:
62+
import subprocess
63+
result = subprocess.run(['git', 'describe', '--tags', '--abbrev=0'],
64+
capture_output=True, text=True, check=True)
65+
return result.stdout.strip().lstrip('v')
66+
except (subprocess.CalledProcessError, FileNotFoundError):
67+
print("⚠️ Git not available, using fallback version 1.0.0")
68+
return "1.0.0"
6269

6370
def build_appimage():
6471
"""Build an AppImage package for Route Planner."""

scripts/build_flatpak.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@ def get_version():
7575
from scripts.version import get_version
7676
return get_version()
7777
except ImportError:
78-
# Fallback to a default version
79-
print("⚠️ Could not determine version, using 1.0.0")
80-
return "1.0.0"
78+
# Fallback: try to get version from git or use default
79+
print("⚠️ Could not determine version from package, trying git...")
80+
try:
81+
import subprocess
82+
result = subprocess.run(['git', 'describe', '--tags', '--abbrev=0'],
83+
capture_output=True, text=True, check=True)
84+
return result.stdout.strip().lstrip('v')
85+
except (subprocess.CalledProcessError, FileNotFoundError):
86+
print("⚠️ Git not available, using fallback version 1.0.0")
87+
return "1.0.0"
8188

8289
def create_flatpak_manifest():
8390
"""Create a Flatpak manifest for Route Planner."""

scripts/prepare_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def add_release_notes_entry(version):
170170
def main():
171171
if len(sys.argv) != 2:
172172
print("Usage: python scripts/prepare_release.py <version>")
173-
print("Example: python scripts/prepare_release.py 1.2.0")
173+
print("Example: python scripts/prepare_release.py X.Y.Z (semantic versioning)")
174174
sys.exit(1)
175175

176176
new_version = sys.argv[1]

scripts/version.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,49 +41,61 @@ def get_version_from_package():
4141
return None
4242

4343
def get_version():
44-
"""Get current version. Priority: git -> package -> env -> default."""
45-
# Try git first (for releases)
44+
"""Get current version. Priority: git tags -> env -> package -> default."""
45+
# Priority 1: Git tags (single source of truth)
4646
version = get_version_from_git()
4747
if version:
4848
return version
4949

50-
# Try package version
51-
version = get_version_from_package()
52-
if version:
53-
return version
54-
55-
# Try environment (for CI)
50+
# Priority 2: Environment (for CI overrides)
5651
version = os.getenv('VERSION')
5752
if version:
5853
return version.lstrip('v')
5954

60-
# Default fallback
55+
# Priority 3: Package version (fallback for development)
56+
version = get_version_from_package()
57+
if version:
58+
return version
59+
60+
# Priority 4: Default fallback
6161
return "0.0.0"
6262

6363
def update_package_version(new_version):
64-
"""Update version in __init__.py."""
64+
"""Update fallback version in __init__.py and create git tag."""
6565
if not INIT_FILE.exists():
6666
print(f"Error: {INIT_FILE} not found")
6767
return False
6868

6969
try:
70+
# Update the fallback version in the package
7071
with open(INIT_FILE, 'r', encoding='utf-8') as f:
7172
content = f.read()
7273

74+
# Update the fallback version in the _get_version function
7375
updated = re.sub(
74-
r'__version__ = [\'"][^\'"]*[\'"]',
75-
f'__version__ = "{new_version}"',
76+
r'return "[\d\.]+"',
77+
f'return "{new_version}"',
7678
content
7779
)
7880

7981
if content != updated:
8082
with open(INIT_FILE, 'w', encoding='utf-8') as f:
8183
f.write(updated)
82-
print(f"Updated version to {new_version}")
83-
return True
84-
else:
85-
print(f"Version already {new_version}")
84+
print(f"Updated fallback version to {new_version}")
85+
86+
# Create git tag (this becomes the real source of truth)
87+
try:
88+
import subprocess
89+
subprocess.run(['git', 'tag', f'v{new_version}'], check=True)
90+
print(f"Created git tag v{new_version}")
8691
return True
92+
except subprocess.CalledProcessError as e:
93+
if "already exists" in str(e):
94+
print(f"Tag v{new_version} already exists")
95+
return True
96+
else:
97+
print(f"Error creating git tag: {e}")
98+
return False
8799

88100
except Exception as e:
89101
print(f"Error updating version: {e}")

0 commit comments

Comments
 (0)