1010"""
1111import os
1212import shutil
13+ import re
14+ import sys
1315
1416import invoke
1517
@@ -141,6 +143,7 @@ def clean_all(context):
141143 pass
142144namespace_clean .add_task (clean_all , 'all' )
143145
146+
144147@invoke .task (pre = [clean_all ])
145148def sdist (context ):
146149 "Create a source distribution"
@@ -153,18 +156,45 @@ def wheel(context):
153156 context .run ('python setup.py bdist_wheel' )
154157namespace .add_task (wheel )
155158
156- @invoke .task (pre = [sdist , wheel ])
159+ @invoke .task
160+ def tag (context , name , message = '' ):
161+ "Add a Git tag and push it to origin"
162+ # If a tag was provided on the command-line, then add a Git tag and push it to origin
163+ if name :
164+ context .run ('git tag -a {} -m {!r}' .format (name , message ))
165+ context .run ('git push origin {}' .format (name ))
166+ namespace .add_task (tag )
167+
168+ @invoke .task ()
169+ def validatetag (context ):
170+ "Check to make sure that a tag exists for the current HEAD and it looks like a valid version number"
171+ # Validate that a Git tag exists for the current commit HEAD
172+ result = context .run ("git describe --exact-match --tags $(git log -n1 --pretty='%h')" )
173+ tag = result .stdout .rstrip ()
174+
175+ # Validate that the Git tag appears to be a valid version number
176+ ver_regex = re .compile (r'(\d+)\.(\d+)\.(\d+)' )
177+ match = ver_regex .fullmatch (tag )
178+ if match is None :
179+ print ('Tag {!r} does not appear to be a valid version number' .format (tag ))
180+ sys .exit (- 1 )
181+ else :
182+ print ('Tag {!r} appears to be a valid version number' .format (tag ))
183+ namespace .add_task (validatetag )
184+
185+ @invoke .task (pre = [validatetag , sdist , wheel ])
157186def pypi (context ):
158187 "Build and upload a distribution to pypi"
159188 context .run ('twine upload dist/*' )
160189namespace .add_task (pypi )
161190
162- @invoke .task (pre = [sdist , wheel ])
191+ @invoke .task (pre = [validatetag , sdist , wheel ])
163192def pypi_test (context ):
164193 "Build and upload a distribution to https://test.pypi.org"
165194 context .run ('twine upload --repository-url https://test.pypi.org/legacy/ dist/*' )
166195namespace .add_task (pypi_test )
167196
197+
168198# Flake8 - linter and tool for style guide enforcement and linting
169199@invoke .task
170200def flake8 (context ):
0 commit comments