From 915a348bfa1f756ff78d0bc28bda569ebb7a1366 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 26 Feb 2025 21:44:10 +0100 Subject: [PATCH] Third party stubtest: Print time per distribution (#13547) --- lib/ts_utils/utils.py | 4 ++++ pyproject.toml | 2 ++ tests/stubtest_third_party.py | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/lib/ts_utils/utils.py b/lib/ts_utils/utils.py index 66d48bd78..522db807a 100644 --- a/lib/ts_utils/utils.py +++ b/lib/ts_utils/utils.py @@ -72,6 +72,10 @@ def print_divider() -> None: print() +def print_time(t: float) -> None: + print(f"({t:.2f} s) ", end="") + + # ==================================================================== # Dynamic venv creation # ==================================================================== diff --git a/pyproject.toml b/pyproject.toml index 39f196cdb..69eb3d129 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,6 +112,8 @@ ignore = [ ### # We're not a library, no need to document everything "D1", # Missing docstring in ... + # Sometimes, an extra blank line is more readable + "D202", # No blank lines allowed after function docstring # Doesn't support split "summary line" "D205", # 1 blank line required between summary line and description # Used for direct, non-subclass type comparison, for example: `type(val) is str` diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index cf6f213d9..bc1db5a41 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -12,6 +12,7 @@ import tempfile from pathlib import Path from shutil import rmtree from textwrap import dedent +from time import time from typing import NoReturn from ts_utils.metadata import NoSuchStubError, get_recursive_requirements, read_metadata @@ -25,6 +26,7 @@ from ts_utils.utils import ( print_error, print_info, print_success_msg, + print_time, ) @@ -36,6 +38,8 @@ def run_stubtest( specified_platforms_only: bool = False, keep_tmp_dir: bool = False, ) -> bool: + """Run stubtest for a single distribution.""" + dist_name = dist.name try: metadata = read_metadata(dist_name) @@ -43,6 +47,8 @@ def run_stubtest( parser.error(str(e)) print(f"{dist_name}... ", end="", flush=True) + t = time() + stubtest_settings = metadata.stubtest_settings if stubtest_settings.skip: print(colored("skipping", "yellow")) @@ -136,6 +142,7 @@ def run_stubtest( try: subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) except subprocess.CalledProcessError as e: + print_time(time() - t) print_error("fail") print_divider() @@ -175,6 +182,7 @@ def run_stubtest( return False else: + print_time(time() - t) print_success_msg() if keep_tmp_dir: print_info(f"Virtual environment kept at: {venv_dir}")