1
1
#
2
- # -*- coding: utf-8 -*-
3
- """Development related tasks to be run with 'invoke'"""
4
-
2
+ # coding=utf-8
3
+ # flake8: noqa E302
4
+ """Development related tasks to be run with 'invoke'.
5
+
6
+ Make sure you satisfy the following Python module requirements if you are trying to publish a release to PyPI:
7
+ - twine >= 1.11.0
8
+ - wheel >= 0.31.0
9
+ - setuptools >= 39.1.0
10
+ """
5
11
import os
12
+ import re
6
13
import shutil
14
+ import sys
7
15
8
16
import invoke
9
17
@@ -135,6 +143,34 @@ def clean_all(context):
135
143
pass
136
144
namespace_clean .add_task (clean_all , 'all' )
137
145
146
+ @invoke .task
147
+ def tag (context , name , message = '' ):
148
+ "Add a Git tag and push it to origin"
149
+ # If a tag was provided on the command-line, then add a Git tag and push it to origin
150
+ if name :
151
+ context .run ('git tag -a {} -m {!r}' .format (name , message ))
152
+ context .run ('git push origin {}' .format (name ))
153
+ namespace .add_task (tag )
154
+
155
+ @invoke .task ()
156
+ def validatetag (context ):
157
+ "Check to make sure that a tag exists for the current HEAD and it looks like a valid version number"
158
+ # Validate that a Git tag exists for the current commit HEAD
159
+ result = context .run ("git describe --exact-match --tags $(git log -n1 --pretty='%h')" )
160
+ tag = result .stdout .rstrip ()
161
+
162
+ # Validate that the Git tag appears to be a valid version number
163
+ ver_regex = re .compile (r'(\d+)\.(\d+)\.(\d+)' )
164
+ match = ver_regex .fullmatch (tag )
165
+ if match is None :
166
+ print ('Tag {!r} does not appear to be a valid version number' .format (tag ))
167
+ sys .exit (- 1 )
168
+ else :
169
+ print ('Tag {!r} appears to be a valid version number' .format (tag ))
170
+
171
+
172
+ namespace .add_task (validatetag )
173
+
138
174
@invoke .task (pre = [clean_all ])
139
175
def sdist (context ):
140
176
"Create a source distribution"
@@ -158,3 +194,10 @@ def pypi_test(context):
158
194
"Build and upload a distribution to https://test.pypi.org"
159
195
context .run ('twine upload --repository-url https://test.pypi.org/legacy/ dist/*' )
160
196
namespace .add_task (pypi_test )
197
+
198
+ # Flake8 - linter and tool for style guide enforcement and linting
199
+ @invoke .task
200
+ def flake8 (context ):
201
+ "Run flake8 linter and tool for style guide enforcement"
202
+ context .run ("flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics --exclude=.git,__pycache__,.tox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov" )
203
+ namespace .add_task (flake8 )
0 commit comments