style: Fix black formatting issues in bump_version.py
- Fix spacing and indentation to pass black formatter - Ensure code quality standards are met for CI workflow 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ def parse_version(version_string: str) -> Tuple[int, int, int]:
|
||||
def bump_version(version: Tuple[int, int, int], bump_type: str) -> Tuple[int, int, int]:
|
||||
"""Apply version bump according to semantic versioning rules."""
|
||||
major, minor, patch = version
|
||||
|
||||
|
||||
if bump_type == "major":
|
||||
return (major + 1, 0, 0)
|
||||
elif bump_type == "minor":
|
||||
@@ -41,22 +41,22 @@ def bump_version(version: Tuple[int, int, int], bump_type: str) -> Tuple[int, in
|
||||
def update_config_file(new_version: str) -> None:
|
||||
"""Update version and timestamp in config.py while preserving structure."""
|
||||
config_path = Path(__file__).parent.parent / "config.py"
|
||||
|
||||
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"config.py not found at {config_path}")
|
||||
|
||||
|
||||
# Read the current content
|
||||
content = config_path.read_text()
|
||||
|
||||
|
||||
# Update version using regex to preserve formatting
|
||||
version_pattern = r'(__version__\s*=\s*["\'])[\d\.]+(["\'])'
|
||||
content = re.sub(version_pattern, rf'\g<1>{new_version}\g<2>', content)
|
||||
|
||||
content = re.sub(version_pattern, rf"\g<1>{new_version}\g<2>", content)
|
||||
|
||||
# Update the __updated__ field with current date
|
||||
current_date = datetime.now().strftime("%Y-%m-%d")
|
||||
updated_pattern = r'(__updated__\s*=\s*["\'])[\d\-]+(["\'])'
|
||||
content = re.sub(updated_pattern, rf'\g<1>{current_date}\g<2>', content)
|
||||
|
||||
content = re.sub(updated_pattern, rf"\g<1>{current_date}\g<2>", content)
|
||||
|
||||
# Write back the updated content
|
||||
config_path.write_text(content)
|
||||
print(f"Updated config.py: version={new_version}, updated={current_date}")
|
||||
@@ -65,16 +65,16 @@ def update_config_file(new_version: str) -> None:
|
||||
def get_current_version() -> str:
|
||||
"""Extract current version from config.py."""
|
||||
config_path = Path(__file__).parent.parent / "config.py"
|
||||
|
||||
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"config.py not found at {config_path}")
|
||||
|
||||
|
||||
content = config_path.read_text()
|
||||
match = re.search(r'__version__\s*=\s*["\']([^"\']+)["\']', content)
|
||||
|
||||
|
||||
if not match:
|
||||
raise ValueError("Could not find __version__ in config.py")
|
||||
|
||||
|
||||
return match.group(1)
|
||||
|
||||
|
||||
@@ -83,34 +83,34 @@ def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python bump_version.py <major|minor|patch>")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
bump_type = sys.argv[1].lower()
|
||||
if bump_type not in ["major", "minor", "patch"]:
|
||||
print(f"Invalid bump type: {bump_type}")
|
||||
print("Valid types: major, minor, patch")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
try:
|
||||
# Get current version
|
||||
current = get_current_version()
|
||||
print(f"Current version: {current}")
|
||||
|
||||
|
||||
# Parse and bump version
|
||||
version_tuple = parse_version(current)
|
||||
new_version_tuple = bump_version(version_tuple, bump_type)
|
||||
new_version = f"{new_version_tuple[0]}.{new_version_tuple[1]}.{new_version_tuple[2]}"
|
||||
|
||||
|
||||
# Update config file
|
||||
update_config_file(new_version)
|
||||
|
||||
|
||||
# Output new version for GitHub Actions
|
||||
print(f"New version: {new_version}")
|
||||
print(f"::set-output name=version::{new_version}")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user