#!/usr/bin/env python3
import os
import re
import subprocess
import sys

if os.environ.get('SKIP_VERSION_BUMP') == '1':
    print("Skipping version bump (SKIP_VERSION_BUMP=1)")
    sys.exit(0)

print("Version will be bumped. Use 'SKIP_VERSION_BUMP=1 git commit' to skip this prompt")

with open('pyproject.toml', 'r', encoding='utf-8') as f:
    content = f.read()

version = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE)
if not version:
    print("Error: Could not find version in pyproject.toml")
    sys.exit(1)

major, minor, patch = map(int, version.groups())
new_version = f'{major}.{minor}.{patch + 1}'
content = re.sub(r'^version = "\d+\.\d+\.\d+"', f'version = "{new_version}"', content, flags=re.MULTILINE)

with open('pyproject.toml', 'w', encoding='utf-8') as f:
    f.write(content)

print(f'Bumped version to {new_version}')
subprocess.run(['git', 'add', 'pyproject.toml'], check=True)
