2020REQUIREMENTS_FILE = os .path .join (pyperformance .DATA_DIR , 'requirements.txt' )
2121
2222
23+ # XXX Use pyperformance.is_installed() instead?
2324def is_build_dir ():
2425 root_dir = os .path .join (PERFORMANCE_ROOT , '..' )
2526 if not os .path .exists (os .path .join (root_dir , 'pyperformance' )):
@@ -113,10 +114,12 @@ def get(self, name):
113114
114115def safe_rmtree (path ):
115116 if not os .path .exists (path ):
116- return
117+ return False
117118
118119 print ("Remove directory %s" % path )
120+ # XXX Pass onerror to report on any files that could not be deleted?
119121 shutil .rmtree (path )
122+ return True
120123
121124
122125def python_implementation ():
@@ -548,10 +551,6 @@ def exec_in_virtualenv(options):
548551
549552
550553def cmd_venv (options , benchmarks = None ):
551- action = options .venv_action
552-
553- requirements = Requirements .from_benchmarks (benchmarks )
554-
555554 venv = VirtualEnvironment (
556555 options .python ,
557556 options .venv ,
@@ -560,7 +559,9 @@ def cmd_venv(options, benchmarks=None):
560559 venv_path = venv .get_path ()
561560 exists = venv .exists ()
562561
562+ action = options .venv_action
563563 if action == 'create' :
564+ requirements = Requirements .from_benchmarks (benchmarks )
564565 if exists :
565566 print ("The virtual environment %s already exists" % venv_path )
566567 venv .ensure ()
@@ -569,6 +570,7 @@ def cmd_venv(options, benchmarks=None):
569570 print ("The virtual environment %s has been created" % venv_path )
570571
571572 elif action == 'recreate' :
573+ requirements = Requirements .from_benchmarks (benchmarks )
572574 if exists :
573575 if venv .get_python_program () == sys .executable :
574576 print ("The virtual environment %s already exists" % venv_path )
@@ -577,7 +579,7 @@ def cmd_venv(options, benchmarks=None):
577579 venv .install_reqs (requirements , exitonerror = True )
578580 else :
579581 print ("The virtual environment %s already exists" % venv_path )
580- shutil . rmtree (venv_path )
582+ safe_rmtree (venv_path )
581583 print ("The old virtual environment %s has been removed" % venv_path )
582584 print ()
583585 venv .ensure ()
@@ -589,23 +591,21 @@ def cmd_venv(options, benchmarks=None):
589591 print ("The virtual environment %s has been created" % venv_path )
590592
591593 elif action == 'remove' :
592- if os .path .exists (venv_path ):
593- shutil .rmtree (venv_path )
594+ if safe_rmtree (venv_path ):
594595 print ("The virtual environment %s has been removed" % venv_path )
595596 else :
596597 print ("The virtual environment %s does not exist" % venv_path )
597598
598599 else :
599600 # show command
600601 text = "Virtual environment path: %s" % venv_path
601- created = venv .exists ()
602- if created :
602+ if exists :
603603 text += " (already created)"
604604 else :
605605 text += " (not created yet)"
606606 print (text )
607607
608- if not created :
608+ if not exists :
609609 print ()
610610 print ("Command to create it:" )
611611 cmd = "%s -m pyperformance venv create" % options .python
0 commit comments