From 4e1c22779e95a9c86c70640309482b4f5113a4d1 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Mon, 19 Nov 2018 11:47:14 -0800 Subject: [PATCH] Fix up environment variable use in venv creation scripts (#6518) This PR has the value of VENV_NAME override any value set in the tools/venv* scripts. I also removed the use of VENV_ARGS. This was used in _venv_common.sh as a means of passing arguments for virtualenv between the scripts, however, there is no other use of the variable in this repository and passing the arguments through a function call is much more natural in Python. * Respect VENV_NAME in tools/venv*. * Stop using VENV_ARGS * Remove VENV_NAME_ENV_VAR and add docstrings. --- tools/_venv_common.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/_venv_common.py b/tools/_venv_common.py index c44d05bf7..bddda6302 100755 --- a/tools/_venv_common.py +++ b/tools/_venv_common.py @@ -1,4 +1,14 @@ #!/usr/bin/env python +"""Aids in creating a developer virtual environment for Certbot. + +When this module is run as a script, it takes the arguments that should +be passed to pip to install the Certbot packages as command line +arguments. The virtual environment will be created with the name "venv" +in the current working directory and will use the default version of +Python for the virtualenv executable in your PATH. You can change the +name of the virtual environment by setting the environment variable +VENV_NAME. +""" from __future__ import print_function @@ -110,12 +120,27 @@ def get_venv_python(venv_path): def main(venv_name, venv_args, args): + """Creates a virtual environment and installs packages. + + :param str venv_name: The name or path at where the virtual + environment should be created. + :param str venv_args: Command line arguments for virtualenv + :param str args: Command line arguments that should be given to pip + to install packages + """ + for path in glob.glob('*.egg-info'): if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) + env_venv_name = os.environ.get('VENV_NAME') + if env_venv_name: + print('Creating venv at {0}' + ' as specified in VENV_NAME'.format(env_venv_name)) + venv_name = env_venv_name + if os.path.isdir(venv_name): os.rename(venv_name, '{0}.{1}.bak'.format(venv_name, int(time.time()))) @@ -150,6 +175,6 @@ def main(venv_name, venv_args, args): if __name__ == '__main__': - main(os.environ.get('VENV_NAME', 'venv'), - os.environ.get('VENV_ARGS', ''), + main('venv', + '', sys.argv[1:])