14
14
15
15
from __future__ import absolute_import
16
16
17
+ from functools import wraps
17
18
import pathlib
18
19
import os
19
20
import re
20
21
import shutil
21
22
import nox
23
+ import time
22
24
23
25
24
26
MYPY_VERSION = "mypy==1.6.1"
40
42
UNIT_TEST_PYTHON_VERSIONS = ["3.7" , "3.8" , "3.12" ]
41
43
CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
42
44
45
+
46
+ def _calculate_duration (func ):
47
+ """This decorator prints the execution time for the decorated function."""
48
+
49
+ @wraps (func )
50
+ def wrapper (* args , ** kwargs ):
51
+ start = time .monotonic ()
52
+ result = func (* args , ** kwargs )
53
+ end = time .monotonic ()
54
+ total_seconds = round (end - start )
55
+ hours = total_seconds // 3600 # Integer division to get hours
56
+ remaining_seconds = total_seconds % 3600 # Modulo to find remaining seconds
57
+ minutes = remaining_seconds // 60
58
+ seconds = remaining_seconds % 60
59
+ human_time = f"{ hours :} :{ minutes :0>2} :{ seconds :0>2} "
60
+ print (f"Session ran in { total_seconds } seconds ({ human_time } )" )
61
+ return result
62
+
63
+ return wrapper
64
+
65
+
43
66
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
44
67
nox .options .sessions = [
45
68
"unit_noextras" ,
@@ -105,13 +128,15 @@ def default(session, install_extras=True):
105
128
106
129
107
130
@nox .session (python = UNIT_TEST_PYTHON_VERSIONS )
131
+ @_calculate_duration
108
132
def unit (session ):
109
133
"""Run the unit test suite."""
110
134
111
135
default (session )
112
136
113
137
114
138
@nox .session (python = [UNIT_TEST_PYTHON_VERSIONS [0 ], UNIT_TEST_PYTHON_VERSIONS [- 1 ]])
139
+ @_calculate_duration
115
140
def unit_noextras (session ):
116
141
"""Run the unit test suite."""
117
142
@@ -129,6 +154,7 @@ def unit_noextras(session):
129
154
130
155
131
156
@nox .session (python = DEFAULT_PYTHON_VERSION )
157
+ @_calculate_duration
132
158
def mypy (session ):
133
159
"""Run type checks with mypy."""
134
160
@@ -147,6 +173,7 @@ def mypy(session):
147
173
148
174
149
175
@nox .session (python = DEFAULT_PYTHON_VERSION )
176
+ @_calculate_duration
150
177
def pytype (session ):
151
178
"""Run type checks with pytype."""
152
179
# An indirect dependecy attrs==21.1.0 breaks the check, and installing a less
@@ -161,6 +188,7 @@ def pytype(session):
161
188
162
189
163
190
@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
191
+ @_calculate_duration
164
192
def system (session ):
165
193
"""Run the system test suite."""
166
194
@@ -209,6 +237,7 @@ def system(session):
209
237
210
238
211
239
@nox .session (python = DEFAULT_PYTHON_VERSION )
240
+ @_calculate_duration
212
241
def mypy_samples (session ):
213
242
"""Run type checks with mypy."""
214
243
@@ -244,6 +273,7 @@ def mypy_samples(session):
244
273
245
274
246
275
@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
276
+ @_calculate_duration
247
277
def snippets (session ):
248
278
"""Run the snippets test suite."""
249
279
@@ -279,6 +309,7 @@ def snippets(session):
279
309
280
310
281
311
@nox .session (python = DEFAULT_PYTHON_VERSION )
312
+ @_calculate_duration
282
313
def cover (session ):
283
314
"""Run the final coverage report.
284
315
@@ -292,6 +323,7 @@ def cover(session):
292
323
293
324
294
325
@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
326
+ @_calculate_duration
295
327
def prerelease_deps (session ):
296
328
"""Run all tests with prerelease versions of dependencies installed.
297
329
@@ -382,6 +414,7 @@ def prerelease_deps(session):
382
414
383
415
384
416
@nox .session (python = DEFAULT_PYTHON_VERSION )
417
+ @_calculate_duration
385
418
def lint (session ):
386
419
"""Run linters.
387
420
@@ -400,6 +433,7 @@ def lint(session):
400
433
401
434
402
435
@nox .session (python = DEFAULT_PYTHON_VERSION )
436
+ @_calculate_duration
403
437
def lint_setup_py (session ):
404
438
"""Verify that setup.py is valid (including RST check)."""
405
439
@@ -408,6 +442,7 @@ def lint_setup_py(session):
408
442
409
443
410
444
@nox .session (python = DEFAULT_PYTHON_VERSION )
445
+ @_calculate_duration
411
446
def blacken (session ):
412
447
"""Run black.
413
448
Format code to uniform standard.
@@ -418,6 +453,7 @@ def blacken(session):
418
453
419
454
420
455
@nox .session (python = "3.9" )
456
+ @_calculate_duration
421
457
def docs (session ):
422
458
"""Build the docs."""
423
459
@@ -454,6 +490,7 @@ def docs(session):
454
490
455
491
456
492
@nox .session (python = "3.10" )
493
+ @_calculate_duration
457
494
def docfx (session ):
458
495
"""Build the docfx yaml files for this library."""
459
496
0 commit comments