1818
1919from __future__ import absolute_import
2020
21+ from functools import wraps
2122import os
2223import pathlib
2324import re
2425import shutil
26+ import time
2527from typing import Dict , List
2628import warnings
2729
100102
101103CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
102104
105+
106+ def _calculate_duration (func ):
107+ """This decorator prints the execution time for the decorated function."""
108+
109+ @wraps (func )
110+ def wrapper (* args , ** kwargs ):
111+ start = time .monotonic ()
112+ result = func (* args , ** kwargs )
113+ end = time .monotonic ()
114+ total_seconds = round (end - start )
115+ hours = total_seconds // 3600 # Integer division to get hours
116+ remaining_seconds = total_seconds % 3600 # Modulo to find remaining seconds
117+ minutes = remaining_seconds // 60
118+ seconds = remaining_seconds % 60
119+ human_time = f"{ hours :} :{ minutes :0>2} :{ seconds :0>2} "
120+ print (f"Session ran in { total_seconds } seconds ({ human_time } )" )
121+ return result
122+
123+ return wrapper
124+
125+
103126nox .options .sessions = [
104127 "unit" ,
105128 "system" ,
118141
119142
120143@nox .session (python = DEFAULT_PYTHON_VERSION )
144+ @_calculate_duration
121145def lint (session ):
122146 """Run linters.
123147
@@ -134,6 +158,7 @@ def lint(session):
134158
135159
136160@nox .session (python = DEFAULT_PYTHON_VERSION )
161+ @_calculate_duration
137162def blacken (session ):
138163 """Run black. Format code to uniform standard."""
139164 session .install (BLACK_VERSION )
@@ -144,6 +169,7 @@ def blacken(session):
144169
145170
146171@nox .session (python = DEFAULT_PYTHON_VERSION )
172+ @_calculate_duration
147173def format (session ):
148174 """
149175 Run isort to sort imports. Then run black
@@ -164,6 +190,7 @@ def format(session):
164190
165191
166192@nox .session (python = DEFAULT_PYTHON_VERSION )
193+ @_calculate_duration
167194def lint_setup_py (session ):
168195 """Verify that setup.py is valid (including RST check)."""
169196 session .install ("docutils" , "pygments" )
@@ -203,6 +230,7 @@ def install_unittest_dependencies(session, *constraints):
203230 "protobuf_implementation" ,
204231 ["python" , "upb" , "cpp" ],
205232)
233+ @_calculate_duration
206234def unit (session , protobuf_implementation , install_extras = True ):
207235 # Install all test dependencies, then install this package in-place.
208236
@@ -278,6 +306,7 @@ def install_systemtest_dependencies(session, *constraints):
278306
279307
280308@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
309+ @_calculate_duration
281310def system (session ):
282311 """Run the system test suite."""
283312 constraints_path = str (
@@ -321,6 +350,7 @@ def system(session):
321350
322351
323352@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
353+ @_calculate_duration
324354def system_noextras (session ):
325355 """Run the system test suite."""
326356 constraints_path = str (
@@ -366,6 +396,7 @@ def system_noextras(session):
366396
367397
368398@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS [- 1 ])
399+ @_calculate_duration
369400def compliance (session ):
370401 """Run the SQLAlchemy dialect-compliance system tests"""
371402 constraints_path = str (
@@ -418,6 +449,7 @@ def compliance(session):
418449
419450
420451@nox .session (python = DEFAULT_PYTHON_VERSION )
452+ @_calculate_duration
421453def cover (session ):
422454 """Run the final coverage report.
423455
@@ -431,6 +463,7 @@ def cover(session):
431463
432464
433465@nox .session (python = "3.10" )
466+ @_calculate_duration
434467def docs (session ):
435468 """Build the docs for this library."""
436469
@@ -468,6 +501,7 @@ def docs(session):
468501
469502
470503@nox .session (python = "3.10" )
504+ @_calculate_duration
471505def docfx (session ):
472506 """Build the docfx yaml files for this library."""
473507
@@ -520,6 +554,7 @@ def docfx(session):
520554 "protobuf_implementation" ,
521555 ["python" , "upb" , "cpp" ],
522556)
557+ @_calculate_duration
523558def prerelease_deps (session , protobuf_implementation ):
524559 """Run all tests with prerelease versions of dependencies installed."""
525560
0 commit comments