23
23
"common-wheels" : "tools/requirements/tests-common_wheels.txt" ,
24
24
}
25
25
26
+ AUTHORS_FILE = "AUTHORS.txt"
27
+ VERSION_FILE = "src/pip/__init__.py"
28
+
26
29
27
30
def get_author_list ():
28
31
"""Get the list of authors from Git commits.
@@ -78,6 +81,11 @@ def should_update_common_wheels():
78
81
return need_to_repopulate
79
82
80
83
84
+ def update_version_file (new_version ):
85
+ with open (VERSION_FILE , "w" , encoding = "utf-8" ) as f :
86
+ f .write ('__version__ = "{}"\n ' .format (new_version ))
87
+
88
+
81
89
# -----------------------------------------------------------------------------
82
90
# Development Commands
83
91
# These are currently prototypes to evaluate whether we want to switch over
@@ -174,7 +182,7 @@ def generate_authors(session):
174
182
175
183
# Write our authors to the AUTHORS file
176
184
session .log ("Writing AUTHORS" )
177
- with io .open ("AUTHORS.txt" , "w" , encoding = "utf-8" ) as fp :
185
+ with io .open (AUTHORS_FILE , "w" , encoding = "utf-8" ) as fp :
178
186
fp .write (u"\n " .join (authors ))
179
187
fp .write (u"\n " )
180
188
@@ -186,3 +194,50 @@ def generate_news(session):
186
194
187
195
# You can pass 2 possible arguments: --draft, --yes
188
196
session .run ("towncrier" , * session .posargs )
197
+
198
+
199
+ @nox .session
200
+ def release (session ):
201
+ assert len (session .posargs ) == 1 , "A version number is expected"
202
+ new_version = session .posargs [0 ]
203
+ parts = new_version .split ('.' )
204
+ # Expect YY.N or YY.N.P
205
+ assert 2 <= len (parts ) <= 3 , parts
206
+ # Only integers
207
+ parts = list (map (int , parts ))
208
+ session .log ("Generating commits for version {}" .format (new_version ))
209
+
210
+ session .log ("Checking that nothing is staged" )
211
+ # Non-zero exit code means that something is already staged
212
+ session .run ("git" , "diff" , "--staged" , "--exit-code" , external = True )
213
+
214
+ session .log (f"Updating { AUTHORS_FILE } " )
215
+ generate_authors (session )
216
+ if subprocess .run (["git" , "diff" , "--exit-code" ]).returncode :
217
+ session .run ("git" , "add" , AUTHORS_FILE , external = True )
218
+ session .run (
219
+ "git" , "commit" , "-m" , f"Updating { AUTHORS_FILE } " ,
220
+ external = True ,
221
+ )
222
+ else :
223
+ session .log (f"No update needed for { AUTHORS_FILE } " )
224
+
225
+ session .log ("Generating NEWS" )
226
+ session .install ("towncrier" )
227
+ session .run ("towncrier" , "--yes" , "--version" , new_version )
228
+
229
+ session .log ("Updating version" )
230
+ update_version_file (new_version )
231
+ session .run ("git" , "add" , VERSION_FILE , external = True )
232
+ session .run ("git" , "commit" , "-m" , f"Release { new_version } " , external = True )
233
+
234
+ session .log ("Tagging release" )
235
+ session .run (
236
+ "git" , "tag" , "-m" , f"Release { new_version } " , new_version ,
237
+ external = True ,
238
+ )
239
+
240
+ next_dev_version = f"{ parts [0 ]} .{ parts [1 ] + 1 } .dev0"
241
+ update_version_file (next_dev_version )
242
+ session .run ("git" , "add" , VERSION_FILE , external = True )
243
+ session .run ("git" , "commit" , "-m" , "Back to development" , external = True )
0 commit comments