11# A script for running pyperformance out of the repo in dev-mode.
22
33import os .path
4+ import shutil
5+ import subprocess
46import sys
57
68REPO_ROOT = os .path .dirname (os .path .abspath (__file__ ))
@@ -29,20 +31,35 @@ def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
2931 readyfile = os .path .join (sys .prefix , "READY" )
3032 isready = os .path .exists (readyfile )
3133 else :
32- import venv
33-
3434 if not venvroot :
3535 venvroot = resolve_venv_root (kind , venvsdir )
3636 # Make sure the venv exists.
3737 readyfile = os .path .join (venvroot , "READY" )
3838 isready = os .path .exists (readyfile )
3939 if not isready :
4040 relroot = os .path .relpath (venvroot )
41- if not os .path .exists (venvroot ):
42- print (f"creating venv at { relroot } ..." )
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+ )
47+ if os .path .exists (venvroot ):
48+ print (f"uv env { relroot } not ready, re-creating..." )
49+ shutil .rmtree (venvroot )
4350 else :
44- print (f"venv { relroot } not ready, re-creating..." )
45- venv .create (venvroot , with_pip = True , clear = True )
51+ print (f"creating uv env at { relroot } ..." )
52+ result = subprocess .run (
53+ [
54+ uv ,
55+ "venv" ,
56+ "--python" ,
57+ sys .executable ,
58+ venvroot ,
59+ ]
60+ )
61+ if result .returncode != 0 :
62+ sys .exit ("ERROR: uv venv creation failed" )
4663 else :
4764 assert os .path .exists (os .path .join (venvroot , "pyvenv.cfg" ))
4865 # Return the venv's Python executable.
@@ -52,18 +69,31 @@ def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
5269
5370 # Now make sure the venv has pyperformance installed.
5471 if not isready :
55- import subprocess
56-
5772 relroot = os .path .relpath (venvroot )
58- print (f"venv { relroot } not ready, installing dependencies..." )
73+ 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+ )
5980 proc = subprocess .run (
60- [python , "-m" , "pip" , "install" , "--upgrade" , "--editable" , REPO_ROOT ],
81+ [
82+ uv ,
83+ "pip" ,
84+ "install" ,
85+ "--python" ,
86+ python ,
87+ "--upgrade" ,
88+ "--editable" ,
89+ f"{ REPO_ROOT } [dev]" ,
90+ ],
6191 )
6292 if proc .returncode != 0 :
63- sys .exit ("ERROR: install failed" )
93+ sys .exit ("ERROR: uv pip install failed" )
6494 with open (readyfile , "w" ):
6595 pass
66- print ("...venv {relroot} ready!" )
96+ print (f "...uv env { relroot } ready!" )
6797
6898 return venvroot , python
6999
0 commit comments