GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ocpi-python/scripts/bump_version.py at main · codexistente/ocpi-python

Expand file tree

/

bump_version.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
146 lines (109 loc) · 4.46 KB
/

bump_version.py

Copy path

File metadata and controls

executable file
·
146 lines (109 loc) · 4.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
"""Automatic version bumping script for CalVer (YYYY.M.PATCH).
This script bumps the version based on commit messages following Conventional Commits:
- feat: bumps M (minor)
- fix: bumps PATCH
- BREAKING CHANGE: bumps M (minor) and resets PATCH
- Any other: bumps PATCH
Version format: YYYY.M.PATCH (e.g., 2026.1.9)
"""
import re
import sys
from datetime import datetime
from pathlib import Path
def get_current_version() -> str:
"""Get current version from ocpi/__init__.py."""
init_file = Path("ocpi/__init__.py")
if not init_file.exists():
raise FileNotFoundError("ocpi/__init__.py not found")
content = init_file.read_text()
match = re.search(r'__version__\s*=\s*["\']([^"\']+)["\']', content)
if not match:
raise ValueError("Could not find __version__ in ocpi/__init__.py")
return match.group(1)
def parse_version(version: str) -> tuple[int, int, int]:
"""Parse CalVer version string into (year, month, patch)."""
match = re.match(r"(\d{4})\.(\d+)\.(\d+)", version)
if not match:
raise ValueError(f"Invalid version format: {version}. Expected YYYY.M.PATCH")
return int(match.group(1)), int(match.group(2)), int(match.group(3))
def format_version(year: int, month: int, patch: int) -> str:
"""Format version components into CalVer string."""
return f"{year}.{month}.{patch}"
def bump_version(current_version: str, bump_type: str) -> str:
"""Bump version based on type.
Args:
current_version: Current version string (e.g., "2026.1.9")
bump_type: One of "major", "minor", "patch", or "auto"
Returns:
New version string
"""
year, month, patch = parse_version(current_version)
current_year = datetime.now().year
if bump_type == "major" or bump_type == "minor":
# For CalVer, "minor" means bumping M
# If year changed, reset to 1.0
if year < current_year:
return format_version(current_year, 1, 0)
return format_version(year, month + 1, 0)
elif bump_type == "patch":
return format_version(year, month, patch + 1)
elif bump_type == "auto":
# Auto-detect from git commits (will be handled by GitHub Actions)
# Default to patch bump
return format_version(year, month, patch + 1)
else:
raise ValueError(f"Unknown bump type: {bump_type}")
def update_version_file(new_version: str) -> None:
"""Update version in ocpi/__init__.py."""
init_file = Path("ocpi/__init__.py")
content = init_file.read_text()
# Replace version
new_content = re.sub(
r'__version__\s*=\s*["\'][^"\']+["\']',
f'__version__ = "{new_version}"',
content,
)
init_file.write_text(new_content)
print(f"✅ Updated ocpi/__init__.py to version {new_version}")
def update_pyproject_version(new_version: str) -> None:
"""Update version in pyproject.toml if using hatch.version.path."""
pyproject_file = Path("pyproject.toml")
if not pyproject_file.exists():
return
content = pyproject_file.read_text()
# Check if using hatch.version.path
if "[tool.hatch.version]" in content and "path" in content:
# Version is read from file, so we don't need to update pyproject.toml
return
print("ℹ️ pyproject.toml uses dynamic version from ocpi/__init__.py")
def main():
"""Main entry point."""
if len(sys.argv) < 2:
print("Usage: bump_version.py <bump_type>")
print(" bump_type: major, minor, patch, or auto")
sys.exit(1)
bump_type = sys.argv[1]
try:
current_version = get_current_version()
print(f"Current version: {current_version}")
new_version = bump_version(current_version, bump_type)
print(f"New version: {new_version}")
if new_version == current_version:
print("⚠️ Version unchanged")
sys.exit(0)
update_version_file(new_version)
update_pyproject_version(new_version)
print(f"\n✅ Version bumped from {current_version} to {new_version}")
print("\nNext steps:")
print(" 1. Review the changes")
print(
f" 2. Commit: git add ocpi/__init__.py && git commit -m 'chore: bump version to {new_version}'"
)
print(f" 3. Tag: git tag v{new_version}")
print(" 4. Push: git push && git push --tags")
except Exception as e:
print(f"❌ Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.