44import shutil
55import subprocess
66import sys
7+ from pyperformance import _utils
78
89REPO_ROOT = os .path .dirname (os .path .abspath (__file__ ))
910VENVS = os .path .join (REPO_ROOT , ".venvs" )
@@ -38,27 +39,18 @@ def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
3839 isready = os .path .exists (readyfile )
3940 if not isready :
4041 relroot = os .path .relpath (venvroot )
41- uv = shutil .which ("uv" )
42- if not uv :
43- sys .exit (
44- "ERROR: uv executable not found. "
45- "Install uv from https://astral.sh/uv and retry."
46- )
4742 if os .path .exists (venvroot ):
4843 print (f"uv env { relroot } not ready, re-creating..." )
4944 shutil .rmtree (venvroot )
5045 else :
5146 print (f"creating uv env at { relroot } ..." )
52- result = subprocess .run (
53- [
54- uv ,
55- "venv" ,
56- "--python" ,
57- sys .executable ,
58- venvroot ,
59- ]
47+ ec , _ , _ = _utils .run_uv (
48+ "venv" ,
49+ "--python" ,
50+ sys .executable ,
51+ venvroot ,
6052 )
61- if result . returncode != 0 :
53+ if ec != 0 :
6254 sys .exit ("ERROR: uv venv creation failed" )
6355 else :
6456 assert os .path .exists (os .path .join (venvroot , "pyvenv.cfg" ))
@@ -71,25 +63,16 @@ def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
7163 if not isready :
7264 relroot = os .path .relpath (venvroot )
7365 print (f"uv env { relroot } not ready, installing dependencies..." )
74- uv = shutil .which ("uv" )
75- if not uv :
76- sys .exit (
77- "ERROR: uv executable not found. "
78- "Install uv from https://astral.sh/uv and retry."
79- )
80- proc = subprocess .run (
81- [
82- uv ,
83- "pip" ,
84- "install" ,
85- "--python" ,
86- python ,
87- "--upgrade" ,
88- "--editable" ,
89- f"{ REPO_ROOT } [dev]" ,
90- ],
66+ ec , _ , _ = _utils .run_uv (
67+ "pip" ,
68+ "install" ,
69+ "--python" ,
70+ python ,
71+ "--upgrade" ,
72+ "--editable" ,
73+ f"{ REPO_ROOT } [dev]" ,
9174 )
92- if proc . returncode != 0 :
75+ if ec != 0 :
9376 sys .exit ("ERROR: uv pip install failed" )
9477 with open (readyfile , "w" ):
9578 pass
0 commit comments