33from __future__ import annotations
44
55import hashlib
6- import io
76import json
87import platform
98import re
2423 PYPI_SIMPLE_JSON ,
2524 PYPI_SIMPLE_URL ,
2625 RELEASE_TAG_PREFIX ,
26+ SETUP_COMMAND_TIMEOUT_SECONDS ,
2727 STDERR_TAIL_CHARACTERS ,
2828 UNIVERSAL_WHEEL_MACHINE ,
2929 WHEEL_MACHINE_ALIASES ,
@@ -107,21 +107,33 @@ def release_source(*, version: str, repo_dir: Path, destination: Path) -> Path:
107107 """Extract the source tree of release tag v<version> from repo_dir into destination."""
108108
109109 tag : str = RELEASE_TAG_PREFIX + version
110- completed : subprocess .CompletedProcess [bytes ] = subprocess .run (
111- ["git" , "-C" , str (repo_dir ), "archive" , "--format=tar" , tag ],
112- capture_output = True ,
113- check = False ,
114- )
115- if completed .returncode != 0 :
116- raise ReleasePerformanceError (
117- f"Release tag { tag } is not available in { repo_dir } , so the baseline's own benchmark "
118- "generator cannot be used; fetch the release tags or pass --baseline-source: "
119- + _tail (completed .stderr .decode ("utf-8" , errors = "replace" ))
120- )
121110 shutil .rmtree (destination , ignore_errors = True )
122111 destination .mkdir (parents = True )
123- with tarfile .open (fileobj = io .BytesIO (completed .stdout )) as archive :
124- archive .extractall (destination , filter = "data" )
112+ tar : Path = destination .with_name (destination .name + ".tar" )
113+ try :
114+ completed : subprocess .CompletedProcess [str ] = run_setup_command (
115+ command = [
116+ "git" ,
117+ "-C" ,
118+ str (repo_dir ),
119+ "archive" ,
120+ "--format=tar" ,
121+ "--output" ,
122+ str (tar ),
123+ tag ,
124+ ],
125+ phase = f"Extracting release tag { tag } " ,
126+ )
127+ if completed .returncode != 0 :
128+ raise ReleasePerformanceError (
129+ f"Release tag { tag } is not available in { repo_dir } , so the baseline's own "
130+ "benchmark generator cannot be used; fetch the release tags or pass "
131+ "--baseline-source: " + _tail (completed .stderr )
132+ )
133+ with tarfile .open (tar ) as archive :
134+ archive .extractall (destination , filter = "data" )
135+ finally :
136+ tar .unlink (missing_ok = True )
125137 return destination
126138
127139
@@ -143,7 +155,9 @@ def install_published(*, version: str, venv_dir: Path, python: str, wait_seconds
143155 deadline : float = time .monotonic () + wait_seconds
144156 while True :
145157 attempt : subprocess .CompletedProcess [str ] = _uv_pip_install (
146- venv_dir = venv_dir , requirements = (f"{ PACKAGE_NAME } =={ version } " ,)
158+ venv_dir = venv_dir ,
159+ requirements = (f"{ PACKAGE_NAME } =={ version } " ,),
160+ phase = f"Installing { PACKAGE_NAME } { version } from the index" ,
147161 )
148162 if attempt .returncode == 0 :
149163 return _sqb (venv_dir = venv_dir )
@@ -174,6 +188,7 @@ def install_wheel(*, wheel: Path, venv_dir: Path, python: str) -> Path:
174188 completed : subprocess .CompletedProcess [str ] = _uv_pip_install (
175189 venv_dir = venv_dir ,
176190 requirements = ("--find-links" , str (wheel .resolve ().parent ), str (wheel .resolve ())),
191+ phase = f"Installing { wheel .name } " ,
177192 )
178193 if completed .returncode != 0 :
179194 raise ReleasePerformanceError (f"Installing { wheel } failed: { _tail (completed .stderr )} " )
@@ -183,8 +198,8 @@ def install_wheel(*, wheel: Path, venv_dir: Path, python: str) -> Path:
183198def installed_version (* , sqb : Path ) -> str :
184199 """Return the version an installed sqb reports."""
185200
186- completed : subprocess .CompletedProcess [str ] = subprocess . run (
187- [str (sqb ), "--version" ], capture_output = True , text = True , check = False
201+ completed : subprocess .CompletedProcess [str ] = run_setup_command (
202+ command = [str (sqb ), "--version" ], phase = f"Reading the version of { sqb } "
188203 )
189204 match : re .Match [str ] | None = _RELEASE_VERSION .search (completed .stdout )
190205 if completed .returncode != 0 or match is None :
@@ -195,8 +210,9 @@ def installed_version(*, sqb: Path) -> str:
195210def library_paths (* , python : Path ) -> tuple [Path , ...]:
196211 """Return the package directories of `python`'s environment, which must match this Python."""
197212
198- completed : subprocess .CompletedProcess [str ] = subprocess .run (
199- [str (python ), "-c" , _LIBRARY_PATHS_PROBE ], capture_output = True , text = True , check = False
213+ completed : subprocess .CompletedProcess [str ] = run_setup_command (
214+ command = [str (python ), "-c" , _LIBRARY_PATHS_PROBE ],
215+ phase = f"Reading the package directories of { python } " ,
200216 )
201217 if completed .returncode != 0 :
202218 raise ReleasePerformanceError (
@@ -213,6 +229,29 @@ def library_paths(*, python: Path) -> tuple[Path, ...]:
213229 return tuple (dict .fromkeys (Path (str (path )) for path in probe ["paths" ]))
214230
215231
232+ def run_setup_command (* , command : list [str ], phase : str ) -> subprocess .CompletedProcess [str ]:
233+ """Run a setup command; one that hangs is stopped and fails with the phase it blocked."""
234+
235+ try :
236+ return subprocess .run (
237+ command ,
238+ capture_output = True ,
239+ text = True ,
240+ check = False ,
241+ timeout = SETUP_COMMAND_TIMEOUT_SECONDS ,
242+ )
243+ except subprocess .TimeoutExpired :
244+ raise setup_timeout_error (phase = phase ) from None
245+
246+
247+ def setup_timeout_error (* , phase : str ) -> ReleasePerformanceError :
248+ """Return the error for a setup phase that exceeded SETUP_COMMAND_TIMEOUT_SECONDS."""
249+
250+ return ReleasePerformanceError (
251+ f"{ phase } did not finish within { SETUP_COMMAND_TIMEOUT_SECONDS :g} s and was stopped"
252+ )
253+
254+
216255def existing_sqb (* , venv_dir : Path ) -> Path :
217256 """Return the sqb entry point of an existing virtual environment."""
218257
@@ -247,6 +286,7 @@ def _install_from_wheel_urls(*, version: str, venv_dir: Path) -> bool:
247286 completed : subprocess .CompletedProcess [str ] = _uv_pip_install (
248287 venv_dir = venv_dir ,
249288 requirements = ("--find-links" , str (download_dir ), f"{ PACKAGE_NAME } =={ version } " ),
289+ phase = f"Installing { PACKAGE_NAME } { version } from its wheel URLs" ,
250290 )
251291 if completed .returncode != 0 :
252292 print (f"Wheel URL install failed: { _tail (completed .stderr )} " , file = sys .stderr )
@@ -280,11 +320,9 @@ def _platform_matches(*, platform_tag: str, machine: str, system: str) -> bool:
280320
281321def _create_venv (* , venv_dir : Path , python : str ) -> None :
282322 shutil .rmtree (venv_dir , ignore_errors = True )
283- completed : subprocess .CompletedProcess [str ] = subprocess .run (
284- [_uv (), "venv" , "--quiet" , "--python" , python , str (venv_dir )],
285- capture_output = True ,
286- text = True ,
287- check = False ,
323+ completed : subprocess .CompletedProcess [str ] = run_setup_command (
324+ command = [_uv (), "venv" , "--quiet" , "--python" , python , str (venv_dir )],
325+ phase = f"Creating the Python { python } environment { venv_dir } " ,
288326 )
289327 if completed .returncode != 0 :
290328 raise ReleasePerformanceError (
@@ -293,10 +331,10 @@ def _create_venv(*, venv_dir: Path, python: str) -> None:
293331
294332
295333def _uv_pip_install (
296- * , venv_dir : Path , requirements : tuple [str , ...]
334+ * , venv_dir : Path , requirements : tuple [str , ...], phase : str
297335) -> subprocess .CompletedProcess [str ]:
298- return subprocess . run (
299- [
336+ return run_setup_command (
337+ command = [
300338 _uv (),
301339 "pip" ,
302340 "install" ,
@@ -305,9 +343,7 @@ def _uv_pip_install(
305343 str (venv_dir / "bin" / "python" ),
306344 * requirements ,
307345 ],
308- capture_output = True ,
309- text = True ,
310- check = False ,
346+ phase = phase ,
311347 )
312348
313349
0 commit comments