-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for updating version on different files
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |