Skip to content

Commit

Permalink
Add script for updating version on different files
Browse files Browse the repository at this point in the history
  • Loading branch information
didix21 committed Feb 11, 2023
1 parent 7ac2d0f commit b507e69
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions scripts/update-release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python

import getopt, sys
import re

def usage():
print(
"""
You can use the scripts as follows
./update-release.py -v v1.5.0
"""
)

def replace_on(file, pattern, new_value):
with open(file, 'r+') as file:
content = file.read()
new_content = re.sub(pattern, new_value, content)
file.write(new_content)

def replace_version_on_config_py(version):
file_name = 'doc/source/conf.py'
replace_on(file_name, r"release = '(\d+).(\d+).(\d+)'", f"release = '{version}'")

def replace_version_on_setup_py(version):
file_name = 'setup.py'
replace_on(file_name, r"version='(\d+).(\d+).(\d+)'", f"version='{version}'")

def replace_version_on_changelog_gen(version):
file_name = '.github_changelog_generator'
replace_on(file_name, r"future-release=v(\d+).(\d+).(\d+)", f"future-release={version}")


def main():
version = None
try:
options, args = getopt.getopt(sys.argv[1:], "v:", ["version="])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)

for option, value in options:
if option in ("-v", "--version"):
version = value
else:
assert False, "Unhandled option"

version_number = version[1:] if 'v' in version else version
replace_version_on_setup_py(version_number)
replace_version_on_config_py(version_number)
replace_version_on_changelog_gen(version)

if __name__ == "__main__":
main()

0 comments on commit b507e69

Please sign in to comment.