feat: Enhance version update script to synchronize version in Makefile alongside pyproject.toml
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to update the version in pyproject.toml from the .env file.
|
||||
Script to update the version in pyproject.toml and Makefile from the .env file.
|
||||
|
||||
This script reads the VERSION variable from .env and updates the version
|
||||
field in pyproject.toml to keep them synchronized.
|
||||
field in pyproject.toml and Makefile to keep them synchronized.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -98,7 +98,7 @@ def update_pyproject_version(pyproject_path: Path, new_version: str) -> bool:
|
||||
return False
|
||||
|
||||
if current_version == new_version:
|
||||
print(f"Version is already up to date: {current_version}")
|
||||
print(f"pyproject.toml version is already up to date: {current_version}")
|
||||
return True
|
||||
|
||||
# Replace only the specific version line in the [project] section
|
||||
@@ -117,7 +117,7 @@ def update_pyproject_version(pyproject_path: Path, new_version: str) -> bool:
|
||||
with open(pyproject_path, "w", encoding="utf-8") as f:
|
||||
f.write(new_content)
|
||||
|
||||
print(f"Updated version from {current_version} to {new_version}")
|
||||
print(f"Updated pyproject.toml version from {current_version} to {new_version}")
|
||||
return True
|
||||
|
||||
except FileNotFoundError:
|
||||
@@ -128,6 +128,71 @@ def update_pyproject_version(pyproject_path: Path, new_version: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def update_makefile_version(makefile_path: Path, new_version: str) -> bool:
|
||||
"""
|
||||
Update the version in Makefile.
|
||||
|
||||
Args:
|
||||
makefile_path: Path to the Makefile
|
||||
new_version: The new version string
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
with open(makefile_path, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# Split content into lines for processing
|
||||
lines = content.split("\n")
|
||||
version_line_index = None
|
||||
current_version = None
|
||||
|
||||
# Find the VERSION= line
|
||||
for i, line in enumerate(lines):
|
||||
# Look for VERSION=x.y.z pattern (at start of line or after whitespace)
|
||||
version_pattern = r"^(\s*)VERSION\s*=\s*(.+)$"
|
||||
version_match = re.match(version_pattern, line)
|
||||
if version_match:
|
||||
current_version = version_match.group(2).strip()
|
||||
version_line_index = i
|
||||
break
|
||||
|
||||
if current_version is None or version_line_index is None:
|
||||
print("ERROR: VERSION variable not found in Makefile")
|
||||
return False
|
||||
|
||||
if current_version == new_version:
|
||||
print(f"Makefile version is already up to date: {current_version}")
|
||||
return True
|
||||
|
||||
# Replace the VERSION line
|
||||
old_line = lines[version_line_index]
|
||||
new_line = re.sub(
|
||||
r"^(\s*VERSION\s*=\s*)(.+)$",
|
||||
f"\\g<1>{new_version}",
|
||||
old_line,
|
||||
)
|
||||
lines[version_line_index] = new_line
|
||||
|
||||
# Reconstruct the content
|
||||
new_content = "\n".join(lines)
|
||||
|
||||
# Write back to file
|
||||
with open(makefile_path, "w", encoding="utf-8") as f:
|
||||
f.write(new_content)
|
||||
|
||||
print(f"Updated Makefile version from {current_version} to {new_version}")
|
||||
return True
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"ERROR: Makefile not found at {makefile_path}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to update Makefile: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def update_uv_lock(project_root: Path) -> bool:
|
||||
"""
|
||||
Update uv.lock file to reflect changes in pyproject.toml.
|
||||
@@ -172,13 +237,13 @@ def update_uv_lock(project_root: Path) -> bool:
|
||||
|
||||
def main() -> int:
|
||||
"""
|
||||
Main function to update version from .env to pyproject.toml.
|
||||
Main function to update version from .env to pyproject.toml and Makefile.
|
||||
|
||||
Returns:
|
||||
Exit code: 0 for success, 1 for failure
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Update version in pyproject.toml from .env file"
|
||||
description="Update version in pyproject.toml and Makefile from .env file"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-uv-lock",
|
||||
@@ -193,9 +258,11 @@ def main() -> int:
|
||||
|
||||
env_path = project_root / ".env"
|
||||
pyproject_path = project_root / "pyproject.toml"
|
||||
makefile_path = project_root / "Makefile"
|
||||
|
||||
print(f"Reading version from: {env_path}")
|
||||
print(f"Updating version in: {pyproject_path}")
|
||||
print(f"Updating version in: {makefile_path}")
|
||||
|
||||
# Read version from .env
|
||||
version = read_version_from_env(env_path)
|
||||
@@ -204,11 +271,19 @@ def main() -> int:
|
||||
|
||||
print(f"Found version in .env: {version}")
|
||||
|
||||
# Track if any updates were made
|
||||
_updates_made = False
|
||||
|
||||
# Update pyproject.toml
|
||||
pyproject_updated = update_pyproject_version(pyproject_path, version)
|
||||
if not pyproject_updated:
|
||||
return 1
|
||||
|
||||
# Update Makefile
|
||||
makefile_updated = update_makefile_version(makefile_path, version)
|
||||
if not makefile_updated:
|
||||
return 1
|
||||
|
||||
print("Version update completed successfully!")
|
||||
|
||||
# Update uv.lock unless explicitly skipped
|
||||
|
||||
Reference in New Issue
Block a user