tools/provision: Support specifying path to Python interpreter.

This commit is contained in:
Eeshan Garg 2017-11-10 17:41:54 -03:30
parent bad8dccef7
commit 0590671fc6

View file

@ -20,16 +20,19 @@ def main():
Creates a Python virtualenv. Its Python version is equal to Creates a Python virtualenv. Its Python version is equal to
the Python version this command is executed with.""" the Python version this command is executed with."""
parser = argparse.ArgumentParser(usage=usage) parser = argparse.ArgumentParser(usage=usage)
parser.parse_args() parser.add_argument('--python-interpreter', '-p',
metavar='PATH_TO_PYTHON_INTERPRETER',
default=os.path.abspath(sys.executable),
help='Path to the Python interpreter to use when provisioning.')
options = parser.parse_args()
base_dir = os.path.abspath(os.path.join(__file__, '..', '..')) base_dir = os.path.abspath(os.path.join(__file__, '..', '..'))
python_interpreter = os.path.abspath(sys.executable)
venv_name = 'zulip-api-py{}-venv'.format(sys.version_info.major) venv_name = 'zulip-api-py{}-venv'.format(sys.version_info.major)
venv_dir = os.path.join(base_dir, venv_name) venv_dir = os.path.join(base_dir, venv_name)
if not os.path.isdir(venv_dir): if not os.path.isdir(venv_dir):
try: try:
return_code = subprocess.call(['virtualenv', '-p', python_interpreter, venv_dir]) return_code = subprocess.call(['virtualenv', '-p', options.python_interpreter, venv_dir])
except OSError: except OSError:
if subprocess.call(['which', 'virtualenv']): if subprocess.call(['which', 'virtualenv']):
print("{red}Please install the virtualenv package and try again.{end_format}" print("{red}Please install the virtualenv package and try again.{end_format}"
@ -39,7 +42,7 @@ the Python version this command is executed with."""
else: else:
if return_code: if return_code:
raise OSError("The command `virtualenv -p {} {}` failed. Virtualenv not created!" raise OSError("The command `virtualenv -p {} {}` failed. Virtualenv not created!"
.format(python_interpreter, venv_dir)) .format(options.python_interpreter, venv_dir))
print("New virtualenv created.") print("New virtualenv created.")
else: else:
print("Virtualenv already exists.") print("Virtualenv already exists.")