33import os .path
44import sys
55
6-
76REPO_ROOT = os .path .dirname (os .path .abspath (__file__ ))
8- VENVS = os .path .join (REPO_ROOT , ' .venvs' )
7+ VENVS = os .path .join (REPO_ROOT , " .venvs" )
98
109
11- def resolve_venv_root (kind = ' dev' , venvsdir = VENVS ):
10+ def resolve_venv_root (kind = " dev" , venvsdir = VENVS ):
1211 import sysconfig
12+
1313 if sysconfig .is_python_build ():
14- sys .exit (' please install your built Python first (or pass it using --python)' )
14+ sys .exit (" please install your built Python first (or pass it using --python)" )
1515 # XXX Handle other implementations too?
16- base = os .path .join (venvsdir , kind or ' dev' )
16+ base = os .path .join (venvsdir , kind or " dev" )
1717 major , minor = sys .version_info [:2 ]
18- pyloc = (( os . path . abspath ( sys . executable )
19- ).partition (os .path .sep )[2 ].lstrip (os .path .sep )
20- ).replace (os .path .sep , '-' )
21- return f' { base } -{ major } .{ minor } -{ pyloc } '
18+ pyloc = (
19+ ( os . path . abspath ( sys . executable ) ).partition (os .path .sep )[2 ].lstrip (os .path .sep )
20+ ).replace (os .path .sep , "-" )
21+ return f" { base } -{ major } .{ minor } -{ pyloc } "
2222
2323
24- def ensure_venv_ready (venvroot = None , kind = ' dev' , venvsdir = VENVS ):
24+ def ensure_venv_ready (venvroot = None , kind = " dev" , venvsdir = VENVS ):
2525 if sys .prefix != sys .base_prefix :
26- assert os .path .exists (os .path .join (sys .prefix , ' pyvenv.cfg' ))
26+ assert os .path .exists (os .path .join (sys .prefix , " pyvenv.cfg" ))
2727 venvroot = sys .prefix
2828 python = sys .executable
29- readyfile = os .path .join (sys .prefix , ' READY' )
29+ readyfile = os .path .join (sys .prefix , " READY" )
3030 isready = os .path .exists (readyfile )
3131 else :
3232 import venv
33+
3334 if not venvroot :
3435 venvroot = resolve_venv_root (kind , venvsdir )
3536 # Make sure the venv exists.
36- readyfile = os .path .join (venvroot , ' READY' )
37+ readyfile = os .path .join (venvroot , " READY" )
3738 isready = os .path .exists (readyfile )
3839 if not isready :
3940 relroot = os .path .relpath (venvroot )
4041 if not os .path .exists (venvroot ):
41- print (f' creating venv at { relroot } ...' )
42+ print (f" creating venv at { relroot } ..." )
4243 else :
43- print (f' venv { relroot } not ready, re-creating...' )
44+ print (f" venv { relroot } not ready, re-creating..." )
4445 venv .create (venvroot , with_pip = True , clear = True )
4546 else :
46- assert os .path .exists (os .path .join (venvroot , ' pyvenv.cfg' ))
47+ assert os .path .exists (os .path .join (venvroot , " pyvenv.cfg" ))
4748 # Return the venv's Python executable.
48- binname = ' Scripts' if os .name == 'nt' else ' bin'
49+ binname = " Scripts" if os .name == "nt" else " bin"
4950 exename = os .path .basename (sys .executable )
5051 python = os .path .join (venvroot , binname , exename )
5152
5253 # Now make sure the venv has pyperformance installed.
5354 if not isready :
5455 import subprocess
56+
5557 relroot = os .path .relpath (venvroot )
56- print (f' venv { relroot } not ready, installing dependencies...' )
58+ print (f" venv { relroot } not ready, installing dependencies..." )
5759 proc = subprocess .run (
58- [python , '-m' , 'pip' , 'install' ,
59- '--upgrade' ,
60- '--editable' , REPO_ROOT ],
60+ [python , "-m" , "pip" , "install" , "--upgrade" , "--editable" , REPO_ROOT ],
6161 )
6262 if proc .returncode != 0 :
63- sys .exit (' ERROR: install failed' )
64- with open (readyfile , 'w' ):
63+ sys .exit (" ERROR: install failed" )
64+ with open (readyfile , "w" ):
6565 pass
66- print (' ...venv {relroot} ready!' )
66+ print (" ...venv {relroot} ready!" )
6767
6868 return venvroot , python
6969
@@ -77,8 +77,9 @@ def main(venvroot=None):
7777
7878 # Now run pyperformance.
7979 import pyperformance .cli
80+
8081 pyperformance .cli .main ()
8182
8283
83- if __name__ == ' __main__' :
84+ if __name__ == " __main__" :
8485 main ()
0 commit comments