This commit is contained in:
Paul Gauthier 2023-06-20 16:59:55 -07:00
parent 02c9a30c45
commit f1350f169f
5 changed files with 167 additions and 154 deletions

View file

@ -1,18 +1,21 @@
import argparse
import os
import re
import subprocess
from packaging import version
def main():
parser = argparse.ArgumentParser(description="Bump version")
parser.add_argument("new_version", help="New version in x.y.z format")
parser.add_argument("--dry-run", action="store_true", help="Print each step without actually executing them")
parser.add_argument(
"--dry-run", action="store_true", help="Print each step without actually executing them"
)
args = parser.parse_args()
dry_run = args.dry_run
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):
raise ValueError(f"Invalid version format, must be x.y.z: {new_version_str}")
new_version = version.parse(new_version_str)
@ -22,7 +25,9 @@ def main():
current_version = re.search(r'__version__ = "(.+?)"', content).group(1)
if new_version <= version.parse(current_version):
raise ValueError(f"New version {new_version} must be greater than the current version {current_version}")
raise ValueError(
f"New version {new_version} must be greater than the current version {current_version}"
)
updated_content = re.sub(r'__version__ = ".+?"', f'__version__ = "{new_version}"', content)
@ -47,5 +52,6 @@ def main():
else:
subprocess.run(cmd, check=True)
if __name__ == "__main__":
main()