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.
This commit is contained in:
Brad Warren 2018-11-19 11:47:14 -08:00 committed by GitHub
parent 5073090a20
commit 4e1c22779e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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:])