12
12
import re
13
13
import shutil
14
14
import sys
15
+ from typing import Union
15
16
16
17
import invoke
18
+ from invoke .context import Context
17
19
18
20
from plugins import (
19
21
tasks as plugin_tasks ,
24
26
25
27
26
28
# shared function
27
- def rmrf (items , verbose = True ) -> None :
29
+ def rmrf (items : Union [ str , list [ str ], set [ str ]], verbose : bool = True ) -> None :
28
30
"""Silently remove a list of directories or files."""
29
31
if isinstance (items , str ):
30
32
items = [items ]
@@ -51,7 +53,7 @@ def rmrf(items, verbose=True) -> None:
51
53
52
54
53
55
@invoke .task ()
54
- def pytest (context , junit = False , pty = True , base = False , isolated = False ) -> None :
56
+ def pytest (context : Context , junit : bool = False , pty : bool = True , base : bool = False , isolated : bool = False ) -> None :
55
57
"""Run tests and code coverage using pytest."""
56
58
with context .cd (TASK_ROOT_STR ):
57
59
command_str = 'pytest '
@@ -79,7 +81,7 @@ def pytest(context, junit=False, pty=True, base=False, isolated=False) -> None:
79
81
80
82
81
83
@invoke .task (post = [plugin_tasks .pytest_clean ])
82
- def pytest_clean (context ) -> None :
84
+ def pytest_clean (context : Context ) -> None :
83
85
"""Remove pytest cache and code coverage files and directories."""
84
86
# pylint: disable=unused-argument
85
87
with context .cd (str (TASK_ROOT / 'tests' )):
@@ -92,7 +94,7 @@ def pytest_clean(context) -> None:
92
94
93
95
94
96
@invoke .task ()
95
- def mypy (context ) -> None :
97
+ def mypy (context : Context ) -> None :
96
98
"""Run mypy optional static type checker."""
97
99
with context .cd (TASK_ROOT_STR ):
98
100
context .run ("mypy ." )
@@ -102,7 +104,7 @@ def mypy(context) -> None:
102
104
103
105
104
106
@invoke .task ()
105
- def mypy_clean (context ) -> None :
107
+ def mypy_clean (context : Context ) -> None :
106
108
"""Remove mypy cache directory."""
107
109
# pylint: disable=unused-argument
108
110
with context .cd (TASK_ROOT_STR ):
@@ -123,7 +125,7 @@ def mypy_clean(context) -> None:
123
125
124
126
125
127
@invoke .task ()
126
- def docs (context , builder = 'html' ) -> None :
128
+ def docs (context : Context , builder : str = 'html' ) -> None :
127
129
"""Build documentation using MkDocs."""
128
130
with context .cd (TASK_ROOT_STR ):
129
131
context .run ('mkdocs build' , pty = True )
@@ -133,7 +135,7 @@ def docs(context, builder='html') -> None:
133
135
134
136
135
137
@invoke .task
136
- def docs_clean (context ) -> None :
138
+ def docs_clean (context : Context ) -> None :
137
139
"""Remove rendered documentation."""
138
140
# pylint: disable=unused-argument
139
141
with context .cd (TASK_ROOT_STR ):
@@ -144,7 +146,7 @@ def docs_clean(context) -> None:
144
146
145
147
146
148
@invoke .task
147
- def livehtml (context ) -> None :
149
+ def livehtml (context : Context ) -> None :
148
150
"""Launch webserver on http://localhost:8000 with rendered documentation."""
149
151
with context .cd (TASK_ROOT_STR ):
150
152
context .run ('mkdocs serve' , pty = True )
@@ -163,7 +165,7 @@ def livehtml(context) -> None:
163
165
164
166
165
167
@invoke .task (post = [plugin_tasks .build_clean ])
166
- def build_clean (context ) -> None :
168
+ def build_clean (context : Context ) -> None :
167
169
"""Remove the build directory."""
168
170
# pylint: disable=unused-argument
169
171
with context .cd (TASK_ROOT_STR ):
@@ -174,7 +176,7 @@ def build_clean(context) -> None:
174
176
175
177
176
178
@invoke .task (post = [plugin_tasks .dist_clean ])
177
- def dist_clean (context ) -> None :
179
+ def dist_clean (context : Context ) -> None :
178
180
"""Remove the dist directory."""
179
181
# pylint: disable=unused-argument
180
182
with context .cd (TASK_ROOT_STR ):
@@ -185,7 +187,7 @@ def dist_clean(context) -> None:
185
187
186
188
187
189
@invoke .task ()
188
- def eggs_clean (context ) -> None :
190
+ def eggs_clean (context : Context ) -> None :
189
191
"""Remove egg directories."""
190
192
# pylint: disable=unused-argument
191
193
with context .cd (TASK_ROOT_STR ):
@@ -203,7 +205,7 @@ def eggs_clean(context) -> None:
203
205
204
206
205
207
@invoke .task ()
206
- def pycache_clean (context ) -> None :
208
+ def pycache_clean (context : Context ) -> None :
207
209
"""Remove __pycache__ directories."""
208
210
# pylint: disable=unused-argument
209
211
with context .cd (TASK_ROOT_STR ):
@@ -220,7 +222,7 @@ def pycache_clean(context) -> None:
220
222
221
223
# ruff fast linter
222
224
@invoke .task ()
223
- def lint (context ) -> None :
225
+ def lint (context : Context ) -> None :
224
226
"""Run ruff fast linter."""
225
227
with context .cd (TASK_ROOT_STR ):
226
228
context .run ("ruff check" )
@@ -231,7 +233,7 @@ def lint(context) -> None:
231
233
232
234
# ruff fast formatter
233
235
@invoke .task ()
234
- def format (context ) -> None : # noqa: A001
236
+ def format (context : Context ) -> None : # noqa: A001
235
237
"""Run ruff format --check."""
236
238
with context .cd (TASK_ROOT_STR ):
237
239
context .run ("ruff format --check" )
@@ -241,7 +243,7 @@ def format(context) -> None: # noqa: A001
241
243
242
244
243
245
@invoke .task ()
244
- def ruff_clean (context ) -> None :
246
+ def ruff_clean (context : Context ) -> None :
245
247
"""Remove .ruff_cache directory."""
246
248
with context .cd (TASK_ROOT_STR ):
247
249
context .run ("ruff clean" )
@@ -256,7 +258,7 @@ def ruff_clean(context) -> None:
256
258
257
259
258
260
@invoke .task (pre = clean_tasks , default = True )
259
- def clean_all (_ ) -> None :
261
+ def clean_all (_ : Context ) -> None :
260
262
"""Run all clean tasks."""
261
263
# pylint: disable=unused-argument
262
264
@@ -265,7 +267,7 @@ def clean_all(_) -> None:
265
267
266
268
267
269
@invoke .task
268
- def tag (context , name , message = '' ) -> None :
270
+ def tag (context : Context , name : str , message : str = '' ) -> None :
269
271
"""Add a Git tag and push it to origin."""
270
272
# If a tag was provided on the command-line, then add a Git tag and push it to origin
271
273
if name :
@@ -277,7 +279,7 @@ def tag(context, name, message='') -> None:
277
279
278
280
279
281
@invoke .task ()
280
- def validatetag (context ) -> None :
282
+ def validatetag (context : Context ) -> None :
281
283
"""Check to make sure that a tag exists for the current HEAD and it looks like a valid version number."""
282
284
# Validate that a Git tag exists for the current commit HEAD
283
285
result = context .run ("git describe --exact-match --tags $(git log -n1 --pretty='%h')" )
@@ -297,7 +299,7 @@ def validatetag(context) -> None:
297
299
298
300
299
301
@invoke .task (pre = [clean_all ], post = [plugin_tasks .sdist ])
300
- def sdist (context ) -> None :
302
+ def sdist (context : Context ) -> None :
301
303
"""Create a source distribution."""
302
304
with context .cd (TASK_ROOT_STR ):
303
305
context .run ('python -m build --sdist' )
@@ -307,7 +309,7 @@ def sdist(context) -> None:
307
309
308
310
309
311
@invoke .task (pre = [clean_all ], post = [plugin_tasks .wheel ])
310
- def wheel (context ) -> None :
312
+ def wheel (context : Context ) -> None :
311
313
"""Build a wheel distribution."""
312
314
with context .cd (TASK_ROOT_STR ):
313
315
context .run ('python -m build --wheel' )
@@ -317,7 +319,7 @@ def wheel(context) -> None:
317
319
318
320
319
321
@invoke .task (pre = [validatetag , sdist , wheel ])
320
- def pypi (context ) -> None :
322
+ def pypi (context : Context ) -> None :
321
323
"""Build and upload a distribution to pypi."""
322
324
with context .cd (TASK_ROOT_STR ):
323
325
context .run ('twine upload dist/*' )
@@ -327,7 +329,7 @@ def pypi(context) -> None:
327
329
328
330
329
331
@invoke .task (pre = [validatetag , sdist , wheel ])
330
- def pypi_test (context ) -> None :
332
+ def pypi_test (context : Context ) -> None :
331
333
"""Build and upload a distribution to https://test.pypi.org."""
332
334
with context .cd (TASK_ROOT_STR ):
333
335
context .run ('twine upload --repository testpypi dist/*' )
0 commit comments