From 21bc4778b07cb9387553430cff9f9ceca35ce539 Mon Sep 17 00:00:00 2001 From: Alena Volkova Date: Tue, 26 Sep 2017 20:35:21 -0400 Subject: [PATCH] provision: Give a clear error message when virtualenv is missing. Without this tweak, running the script results in a vague "No such file or directory" error if the virtualenv package is not installed. --- tools/provision | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/provision b/tools/provision index e391790..ef43ade 100755 --- a/tools/provision +++ b/tools/provision @@ -24,10 +24,18 @@ the Python version this command is executed with.""" venv_dir = os.path.join(base_dir, venv_name) if not os.path.isdir(venv_dir): - if subprocess.call(['virtualenv', '-p', python_interpreter, venv_dir]): - raise OSError("The command `virtualenv -p {} {}` failed. Virtualenv not created!" - .format(python_interpreter, venv_dir)) + try: + return_code = subprocess.call(['virtualenv', '-p', python_interpreter, venv_dir]) + except OSError: + if subprocess.call(['which', 'virtualenv']): + print("{red}Please install the virtualenv package and try again.{end_format}" + .format(red='\033[91m', end_format='\033[0m')) + sys.exit(1) + raise else: + if return_code: + raise OSError("The command `virtualenv -p {} {}` failed. Virtualenv not created!" + .format(python_interpreter, venv_dir)) print("New virtualenv created.") else: print("Virtualenv already exists.")