55
66- update version numbers in _version.py and setup.py
77- purge the "Unreleased" section of CHANGELOG.md and rename it to the new version number
8- - copy the README.md file to doc/misc/README.md,
8+ - copy the README.md file to doc/misc/README.md,
99 but without the badges as they interfere with the sphinx doc builder
1010
1111All changes are immediately commited to the repository.
@@ -38,28 +38,28 @@ def bump_version_number(version_number: str, level: str) -> str:
3838 """Return a copy of `version_number` with one level number incremented."""
3939 major , minor , patch = version_number .split ("." )
4040 if level == "major" :
41- major = str (int (major )+ 1 )
41+ major = str (int (major ) + 1 )
4242 minor = "0"
4343 patch = "0"
4444 elif level == "minor" :
45- minor = str (int (minor )+ 1 )
45+ minor = str (int (minor ) + 1 )
4646 patch = "0"
4747 elif level == "patch" :
48- patch = str (int (patch )+ 1 )
48+ patch = str (int (patch ) + 1 )
4949 else :
5050 raise ValueError (f"level should be 'major', 'minor' or 'patch', not { level } " )
5151 return "." .join ([major , minor , patch ])
5252
5353
5454def update_readme (_nvn ):
55- """align doc/misc/README.md with ./README.md but remove the non-markdown header lines from """
56- with open ("README.md" , 'r' , encoding = "UTF-8" ) as rmin :
57- lines = [line for line in rmin .readlines () if not line .startswith (' [![' )]
55+ """align doc/misc/README.md with ./README.md but remove the non-markdown header lines from"""
56+ with open ("README.md" , "r" , encoding = "UTF-8" ) as rmin :
57+ lines = [line for line in rmin .readlines () if not line .startswith (" [![" )]
5858 while not lines [0 ].strip ():
5959 lines = lines [1 :]
60- with open ("doc/misc/README.md" , 'w' , encoding = "UTF-8" ) as rmout :
60+ with open ("doc/misc/README.md" , "w" , encoding = "UTF-8" ) as rmout :
6161 rmout .writelines (lines )
62- return GitFile (' doc/misc/README.md' )
62+ return GitFile (" doc/misc/README.md" )
6363
6464
6565def update_changelog (nvn ):
@@ -70,16 +70,16 @@ def update_changelog(nvn):
7070 release = []
7171 section_name = None
7272 section = []
73- with open ("CHANGELOG.md" , 'r' , encoding = "UTF-8" ) as changelog :
73+ with open ("CHANGELOG.md" , "r" , encoding = "UTF-8" ) as changelog :
7474 for line in changelog .readlines ():
75- if line .startswith ('#' ):
76- if line .startswith (' ### ' ):
75+ if line .startswith ("#" ):
76+ if line .startswith (" ### " ):
7777 if section :
7878 release .append ((section_name , section ))
7979 section_name = line [4 :].strip ()
8080 section = []
81- #print("tag:", section_name)
82- elif line .startswith (' ## ' ):
81+ # print("tag:", section_name)
82+ elif line .startswith (" ## " ):
8383 if section :
8484 release .append ((section_name , section ))
8585 if release :
@@ -88,15 +88,15 @@ def update_changelog(nvn):
8888 release = []
8989 section_name = None
9090 section = []
91- #print("release:", release_name)
91+ # print("release:", release_name)
9292 else :
9393 section .append (line )
9494 if section :
9595 release .append ((section_name , section ))
9696 if release :
9797 releases .append ((release_name , release ))
9898
99- with open ("CHANGELOG.md" , 'w' , encoding = "UTF-8" ) as changelog :
99+ with open ("CHANGELOG.md" , "w" , encoding = "UTF-8" ) as changelog :
100100 changelog .write ("# Changelog\n \n " )
101101 for release_name , release in releases :
102102 if release_name :
@@ -107,7 +107,11 @@ def update_changelog(nvn):
107107 if any (ln .strip () for ln in section ):
108108 if section_name :
109109 changelog .write (f"### { section_name } \n " )
110- lines = [ln .strip () for ln in section if "code freeze date: " not in ln .lower ()]
110+ lines = [
111+ ln .strip ()
112+ for ln in section
113+ if "code freeze date: " not in ln .lower ()
114+ ]
111115 if not section_name and release_name .lower () == nvn :
112116 print ("setting date" )
113117 for i , line in enumerate (lines ):
@@ -116,26 +120,26 @@ def update_changelog(nvn):
116120 lines [i ] = f"Release date: { today } "
117121 changelog .write (re .sub ("\n +$" , "\n " , "\n " .join (lines )))
118122 changelog .write ("\n " )
119- return GitFile (' CHANGELOG.md' )
123+ return GitFile (" CHANGELOG.md" )
120124
121125
122126def update_version (nvn ):
123127 """Update the _version.py file"""
124128 [file_with_version ] = glob .glob ("climada*/_version.py" )
125- regex = r' (^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)'
129+ regex = r" (^__version__\s*=\s*[\'\"]).*([\'\"]\s*$)"
126130 return update_file (file_with_version , regex , nvn )
127131
128132
129133def update_setup (new_version_number ):
130134 """Update the setup.py file"""
131135 file_with_version = "setup.py"
132- regex = r' (^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)'
136+ regex = r" (^\s+version\s*=\s*[\'\"]).*([\'\"]\s*,\s*$)"
133137 return update_file (file_with_version , regex , new_version_number )
134138
135139
136140def update_file (file_with_version , regex , new_version_number ):
137141 """Replace the version number(s) in a file, based on a rgular expression."""
138- with open (file_with_version , 'r' , encoding = "UTF-8" ) as curf :
142+ with open (file_with_version , "r" , encoding = "UTF-8" ) as curf :
139143 lines = curf .readlines ()
140144 successfully_updated = False
141145 for i , line in enumerate (lines ):
@@ -145,14 +149,15 @@ def update_file(file_with_version, regex, new_version_number):
145149 successfully_updated = True
146150 if not successfully_updated :
147151 raise RuntimeError (f"cannot determine version of { file_with_version } " )
148- with open (file_with_version , 'w' , encoding = "UTF-8" ) as newf :
152+ with open (file_with_version , "w" , encoding = "UTF-8" ) as newf :
149153 for line in lines :
150154 newf .write (line )
151155 return GitFile (file_with_version )
152156
153157
154- class GitFile () :
158+ class GitFile :
155159 """Helper class for `git add`."""
160+
156161 def __init__ (self , path ):
157162 self .path = path
158163
@@ -166,8 +171,9 @@ def gitadd(self):
166171 ).stdout .decode ("utf8" )
167172
168173
169- class Git () :
174+ class Git :
170175 """Helper class for `git commit`."""
176+
171177 def __init__ (self ):
172178 _gitname = subprocess .run (
173179 ["git" , "config" , "--global" , "user.name" , "'climada'" ],
@@ -228,6 +234,7 @@ def prepare_new_release(level):
228234
229235if __name__ == "__main__" :
230236 from sys import argv
237+
231238 try :
232239 LEVEL = argv [1 ]
233240 except IndexError :
0 commit comments