3
3
"""Development related tasks to be run with 'invoke'"""
4
4
5
5
import os
6
+ import re
6
7
import shutil
8
+ import sys
7
9
8
10
import invoke
9
11
@@ -135,6 +137,33 @@ def clean_all(context):
135
137
pass
136
138
namespace_clean .add_task (clean_all , 'all' )
137
139
140
+
141
+ @invoke .task
142
+ def tag (context , name , message = '' ):
143
+ "Add a Git tag and push it to origin"
144
+ # If a tag was provided on the command-line, then add a Git tag and push it to origin
145
+ if name :
146
+ context .run ('git tag -a {} -m {!r}' .format (name , message ))
147
+ context .run ('git push origin {}' .format (name ))
148
+ namespace .add_task (tag )
149
+
150
+ @invoke .task ()
151
+ def validatetag (context ):
152
+ "Check to make sure that a tag exists for the current HEAD and it looks like a valid version number"
153
+ # Validate that a Git tag exists for the current commit HEAD
154
+ result = context .run ("git describe --exact-match --tags $(git log -n1 --pretty='%h')" )
155
+ tag = result .stdout .rstrip ()
156
+
157
+ # Validate that the Git tag appears to be a valid version number
158
+ ver_regex = re .compile ('(\d+)\.(\d+)\.(\d+)' )
159
+ match = ver_regex .fullmatch (tag )
160
+ if match is None :
161
+ print ('Tag {!r} does not appear to be a valid version number' .format (tag ))
162
+ sys .exit (- 1 )
163
+ else :
164
+ print ('Tag {!r} appears to be a valid version number' .format (tag ))
165
+ namespace .add_task (validatetag )
166
+
138
167
@invoke .task (pre = [clean_all ])
139
168
def sdist (context ):
140
169
"Create a source distribution"
@@ -147,13 +176,13 @@ def wheel(context):
147
176
context .run ('python setup.py bdist_wheel' )
148
177
namespace .add_task (wheel )
149
178
150
- @invoke .task (pre = [sdist , wheel ])
179
+ @invoke .task (pre = [validatetag , sdist , wheel ])
151
180
def pypi (context ):
152
181
"Build and upload a distribution to pypi"
153
182
context .run ('twine upload dist/*' )
154
183
namespace .add_task (pypi )
155
184
156
- @invoke .task (pre = [sdist , wheel ])
185
+ @invoke .task (pre = [validatetag , sdist , wheel ])
157
186
def pypi_test (context ):
158
187
"Build and upload a distribution to https://test.pypi.org"
159
188
context .run ('twine upload --repository-url https://test.pypi.org/legacy/ dist/*' )
0 commit comments