33from types import SimpleNamespace as sns
44import tomli , tomli_w
55
6- def parse_args ():
7- argp = argparse .ArgumentParser (description = 'Bump versions in pyproject.toml + README.md' )
8- argp .add_argument ('-M' , '--major' , action = 'store_true' , help = 'Bump the major (\033 [1mx\033 [0m.y.z) version' )
9- argp .add_argument ('-m' , '--minor' , action = 'store_true' , help = 'Bump the minor (x.\033 [1my\033 [0m.z) version' )
10- argp .add_argument ('-p' , '--patch' , action = 'store_true' , help = 'Bump the patch (x.y.\033 [1mz\033 [0m) version' )
11- return argp .parse_args ()
12-
13- # Init logger
146sys .path .insert (0 , path .join (path .dirname (__file__ ), '../src' ))
157from translate_messages .lib import log # type: ignore
16- msgs = sns (err_invalid_arg = 'You must pass --<major|minor|patch> as an argument.' )
8+
9+ # Parse args
10+ argp = argparse .ArgumentParser (
11+ description = 'Bump versions in pyproject.toml + README.md' ,
12+ add_help = False # disable default --help arg to re-create last
13+ )
14+ argp .add_argument ('-M' , '--major' , action = 'store_true' , help = 'Bump the major (\033 [1mx\033 [0m.y.z) version' )
15+ argp .add_argument ('-m' , '--minor' , action = 'store_true' , help = 'Bump the minor (x.\033 [1my\033 [0m.z) version' )
16+ argp .add_argument ('-p' , '--patch' , action = 'store_true' , help = 'Bump the patch (x.y.\033 [1mz\033 [0m) version' )
17+ argp .add_argument ('-h' , '--help' , action = 'help' , help = 'Show help screen' )
18+ args = argp .parse_args ()
19+
20+ # Init bump_type
21+ bump_type = 'major' if args .major else 'minor' if args .minor else 'patch' if args .patch else None
22+ if not bump_type :
23+ log .error ('You must pass --<major|minor|patch> as an argument.' )
24+ sys .exit (1 )
1725
1826# Init project data
1927pyproject_path = path .join (path .dirname (__file__ ), '../pyproject.toml' )
@@ -29,13 +37,11 @@ def bump_pyproject_versions(bump_type): # project.version + .urls['Changelog']
2937 if bump_type == 'major' : patch = 0 ; minor = 0 ; major += 1
3038 elif bump_type == 'minor' : patch = 0 ; minor += 1 ;
3139 elif bump_type == 'patch' : patch += 1
32- else : raise ValueError (msgs .err_invalid_arg )
33- new_ver = f'{ major } .{ minor } .{ patch } '
34- pyproject ['project' ]['version' ] = new_ver
40+ pyproject ['project' ]['version' ] = new_ver = f'{ major } .{ minor } .{ patch } '
3541 with open (pyproject_path , 'wb' ) as file : tomli_w .dump (pyproject , file )
3642 log .success (f'Bumped project.version in pyproject.toml from [{ current_ver } ] to [{ new_ver } ]' )
3743
38- # Bump version tag in Changelog URL
44+ # Bump version tag in project.urls[' Changelog']
3945 new_ver_tag = f'{ project .name } -{ new_ver } '
4046 new_changelog_url = f"{ project .urls ['Releases' ]} /tag/{ new_ver_tag } "
4147 log .data (f'Generated Changelog URL: { new_changelog_url } ' )
@@ -46,16 +52,12 @@ def bump_pyproject_versions(bump_type): # project.version + .urls['Changelog']
4652
4753 return new_ver
4854
49- def update_readme_versions (new_ver ): # in shield + supported_locales URLs
55+ def update_readme_versions (new_ver ): # in URLs
5056 readme_path = path .join (path .dirname (__file__ ), '../README.md' )
5157 log .info ('Updating versions in README.md...' )
5258 with open (readme_path , 'r' , encoding = 'utf-8' ) as file : readme_content = file .read ()
5359 updated_readme_content = re .sub (r'\d+\.\d+\.\d+' , new_ver , readme_content )
5460 with open (readme_path , 'w' , encoding = 'utf-8' ) as file : file .write (updated_readme_content )
5561 log .success (f'Updated versions in README URLs to [{ new_ver } ]!' )
5662
57- # Run MAIN routine
58- args = parse_args ()
59- bump_type = 'major' if args .major else 'minor' if args .minor else 'patch' if args .patch else None
60- if not bump_type : raise ValueError (msgs .err_invalid_arg )
6163update_readme_versions (bump_pyproject_versions (bump_type ))
0 commit comments