feat: add check_cog_pyproject function to run cog -r on pyproject.toml and abort if it has changed the file

This commit is contained in:
Paul Gauthier (aider) 2024-08-13 09:39:44 -07:00
parent 5d14d93594
commit 211ab28253

View file

@ -5,10 +5,28 @@ import datetime
import re import re
import subprocess import subprocess
import sys import sys
import tempfile
import filecmp
from packaging import version from packaging import version
def check_cog_pyproject():
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file:
with open('pyproject.toml', 'r') as original_file:
temp_file.write(original_file.read())
result = subprocess.run(["cog", "-r", "pyproject.toml"], capture_output=True, text=True)
if result.returncode != 0:
print("Error: cog -r pyproject.toml failed with the following output:")
print(result.stderr)
sys.exit(1)
if not filecmp.cmp('pyproject.toml', temp_file.name):
print("Error: cog -r pyproject.toml has changed the file. Please run cog -r pyproject.toml and commit the changes.")
sys.exit(1)
def main(): def main():
parser = argparse.ArgumentParser(description="Bump version") parser = argparse.ArgumentParser(description="Bump version")
parser.add_argument("new_version", help="New version in x.y.z format") parser.add_argument("new_version", help="New version in x.y.z format")
@ -56,6 +74,7 @@ def main():
check_branch() check_branch()
check_working_directory_clean() check_working_directory_clean()
check_main_branch_up_to_date() check_main_branch_up_to_date()
check_cog_pyproject()
new_version_str = args.new_version new_version_str = args.new_version
if not re.match(r"^\d+\.\d+\.\d+$", new_version_str): if not re.match(r"^\d+\.\d+\.\d+$", new_version_str):