1818
1919from __future__ import absolute_import
2020
21- from functools import wraps
2221import os
2322import pathlib
2423import re
2524import shutil
26- import time
2725from typing import Dict , List
2826import warnings
2927
102100
103101CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
104102
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-
126103nox .options .sessions = [
127104 "unit" ,
128105 "system" ,
@@ -141,15 +118,13 @@ def wrapper(*args, **kwargs):
141118
142119
143120@nox .session (python = DEFAULT_PYTHON_VERSION )
144- @_calculate_duration
145121def lint (session ):
146122 """Run linters.
147123
148124 Returns a failure if the linters find linting errors or sufficiently
149125 serious code quality issues.
150126 """
151127 session .install (FLAKE8_VERSION , BLACK_VERSION )
152- session .run ("python" , "-m" , "pip" , "freeze" )
153128 session .run (
154129 "black" ,
155130 "--check" ,
@@ -159,19 +134,16 @@ def lint(session):
159134
160135
161136@nox .session (python = DEFAULT_PYTHON_VERSION )
162- @_calculate_duration
163137def blacken (session ):
164138 """Run black. Format code to uniform standard."""
165139 session .install (BLACK_VERSION )
166- session .run ("python" , "-m" , "pip" , "freeze" )
167140 session .run (
168141 "black" ,
169142 * LINT_PATHS ,
170143 )
171144
172145
173146@nox .session (python = DEFAULT_PYTHON_VERSION )
174- @_calculate_duration
175147def format (session ):
176148 """
177149 Run isort to sort imports. Then run black
@@ -180,7 +152,6 @@ def format(session):
180152 session .install (BLACK_VERSION , ISORT_VERSION )
181153 # Use the --fss option to sort imports using strict alphabetical order.
182154 # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
183- session .run ("python" , "-m" , "pip" , "freeze" )
184155 session .run (
185156 "isort" ,
186157 "--fss" ,
@@ -193,11 +164,9 @@ def format(session):
193164
194165
195166@nox .session (python = DEFAULT_PYTHON_VERSION )
196- @_calculate_duration
197167def lint_setup_py (session ):
198168 """Verify that setup.py is valid (including RST check)."""
199169 session .install ("docutils" , "pygments" )
200- session .run ("python" , "-m" , "pip" , "freeze" )
201170 session .run ("python" , "setup.py" , "check" , "--restructuredtext" , "--strict" )
202171
203172
@@ -234,7 +203,6 @@ def install_unittest_dependencies(session, *constraints):
234203 "protobuf_implementation" ,
235204 ["python" , "upb" , "cpp" ],
236205)
237- @_calculate_duration
238206def unit (session , protobuf_implementation , install_extras = True ):
239207 # Install all test dependencies, then install this package in-place.
240208
@@ -261,7 +229,6 @@ def unit(session, protobuf_implementation, install_extras=True):
261229 session .install ("protobuf<4" )
262230
263231 # Run py.test against the unit tests.
264- session .run ("python" , "-m" , "pip" , "freeze" )
265232 session .run (
266233 "py.test" ,
267234 "--quiet" ,
@@ -311,7 +278,6 @@ def install_systemtest_dependencies(session, *constraints):
311278
312279
313280@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
314- @_calculate_duration
315281def system (session ):
316282 """Run the system test suite."""
317283 constraints_path = str (
@@ -334,7 +300,6 @@ def system(session):
334300 session .skip ("System tests were not found" )
335301
336302 install_systemtest_dependencies (session , "-c" , constraints_path )
337- session .run ("python" , "-m" , "pip" , "freeze" )
338303
339304 # Run py.test against the system tests.
340305 if system_test_exists :
@@ -356,7 +321,6 @@ def system(session):
356321
357322
358323@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
359- @_calculate_duration
360324def system_noextras (session ):
361325 """Run the system test suite."""
362326 constraints_path = str (
@@ -381,7 +345,6 @@ def system_noextras(session):
381345 global SYSTEM_TEST_EXTRAS_BY_PYTHON
382346 SYSTEM_TEST_EXTRAS_BY_PYTHON = False
383347 install_systemtest_dependencies (session , "-c" , constraints_path )
384- session .run ("python" , "-m" , "pip" , "freeze" )
385348
386349 # Run py.test against the system tests.
387350 if system_test_exists :
@@ -403,7 +366,6 @@ def system_noextras(session):
403366
404367
405368@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS [- 1 ])
406- @_calculate_duration
407369def compliance (session ):
408370 """Run the SQLAlchemy dialect-compliance system tests"""
409371 constraints_path = str (
@@ -456,22 +418,19 @@ def compliance(session):
456418
457419
458420@nox .session (python = DEFAULT_PYTHON_VERSION )
459- @_calculate_duration
460421def cover (session ):
461422 """Run the final coverage report.
462423
463424 This outputs the coverage report aggregating coverage from the unit
464425 test runs (not system test runs), and then erases coverage data.
465426 """
466427 session .install ("coverage" , "pytest-cov" )
467- session .run ("python" , "-m" , "pip" , "freeze" )
468428 session .run ("coverage" , "report" , "--show-missing" , "--fail-under=100" )
469429
470430 session .run ("coverage" , "erase" )
471431
472432
473433@nox .session (python = "3.10" )
474- @_calculate_duration
475434def docs (session ):
476435 """Build the docs for this library."""
477436
@@ -494,7 +453,6 @@ def docs(session):
494453 )
495454
496455 shutil .rmtree (os .path .join ("docs" , "_build" ), ignore_errors = True )
497- session .run ("python" , "-m" , "pip" , "freeze" )
498456 session .run (
499457 "sphinx-build" ,
500458 "-W" , # warnings as errors
@@ -510,7 +468,6 @@ def docs(session):
510468
511469
512470@nox .session (python = "3.10" )
513- @_calculate_duration
514471def docfx (session ):
515472 """Build the docfx yaml files for this library."""
516473
@@ -533,7 +490,6 @@ def docfx(session):
533490 )
534491
535492 shutil .rmtree (os .path .join ("docs" , "_build" ), ignore_errors = True )
536- session .run ("python" , "-m" , "pip" , "freeze" )
537493 session .run (
538494 "sphinx-build" ,
539495 "-T" , # show full traceback on exception
@@ -564,7 +520,6 @@ def docfx(session):
564520 "protobuf_implementation" ,
565521 ["python" , "upb" , "cpp" ],
566522)
567- @_calculate_duration
568523def prerelease_deps (session , protobuf_implementation ):
569524 """Run all tests with prerelease versions of dependencies installed."""
570525
@@ -626,7 +581,6 @@ def prerelease_deps(session, protobuf_implementation):
626581 "requests" ,
627582 ]
628583 session .install (* other_deps )
629- session .run ("python" , "-m" , "pip" , "freeze" )
630584
631585 # Print out prerelease package versions
632586 session .run (
0 commit comments