Improve ansible-test --venv error handling.
This allows it to fall back to virtualenv when venv is broken.
This commit is contained in:
parent
a6f828e2ab
commit
460b583dff
1 changed files with 23 additions and 6 deletions
|
@ -16,6 +16,7 @@ from .util import (
|
||||||
get_available_python_versions,
|
get_available_python_versions,
|
||||||
SUPPORTED_PYTHON_VERSIONS,
|
SUPPORTED_PYTHON_VERSIONS,
|
||||||
display,
|
display,
|
||||||
|
remove_tree,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .util_common import (
|
from .util_common import (
|
||||||
|
@ -47,8 +48,8 @@ def create_virtual_environment(args, # type: EnvironmentConfig
|
||||||
display.info('Created Python %s virtual environment using "venv": %s' % (version, path), verbosity=1)
|
display.info('Created Python %s virtual environment using "venv": %s' % (version, path), verbosity=1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# something went wrong, this shouldn't happen
|
# something went wrong, most likely the package maintainer for the Python installation removed ensurepip
|
||||||
return False
|
# which will prevent creation of a virtual environment without installation of other OS packages
|
||||||
|
|
||||||
# use the installed 'virtualenv' module on the Python requested version
|
# use the installed 'virtualenv' module on the Python requested version
|
||||||
if run_virtualenv(args, python, python, system_site_packages, pip, path):
|
if run_virtualenv(args, python, python, system_site_packages, pip, path):
|
||||||
|
@ -96,7 +97,12 @@ def run_venv(args, # type: EnvironmentConfig
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run_command(args, cmd, capture=True)
|
run_command(args, cmd, capture=True)
|
||||||
except SubprocessError:
|
except SubprocessError as ex:
|
||||||
|
remove_tree(path)
|
||||||
|
|
||||||
|
if args.verbosity > 1:
|
||||||
|
display.error(ex)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -110,7 +116,10 @@ def run_virtualenv(args, # type: EnvironmentConfig
|
||||||
path, # type: str
|
path, # type: str
|
||||||
): # type: (...) -> bool
|
): # type: (...) -> bool
|
||||||
"""Create a virtual environment using the 'virtualenv' module."""
|
"""Create a virtual environment using the 'virtualenv' module."""
|
||||||
cmd = [run_python, '-m', 'virtualenv', '--python', env_python]
|
cmd = [run_python, '-m', 'virtualenv']
|
||||||
|
|
||||||
|
if run_python != env_python:
|
||||||
|
cmd += ['--python', env_python]
|
||||||
|
|
||||||
if system_site_packages:
|
if system_site_packages:
|
||||||
cmd.append('--system-site-packages')
|
cmd.append('--system-site-packages')
|
||||||
|
@ -122,7 +131,12 @@ def run_virtualenv(args, # type: EnvironmentConfig
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run_command(args, cmd, capture=True)
|
run_command(args, cmd, capture=True)
|
||||||
except SubprocessError:
|
except SubprocessError as ex:
|
||||||
|
remove_tree(path)
|
||||||
|
|
||||||
|
if args.verbosity > 1:
|
||||||
|
display.error(ex)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -141,7 +155,10 @@ def get_virtualenv_version(args, python): # type: (EnvironmentConfig, str) -> t
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stdout = run_command(args, cmd, capture=True)[0]
|
stdout = run_command(args, cmd, capture=True)[0]
|
||||||
except SubprocessError:
|
except SubprocessError as ex:
|
||||||
|
if args.verbosity > 1:
|
||||||
|
display.error(ex)
|
||||||
|
|
||||||
stdout = ''
|
stdout = ''
|
||||||
|
|
||||||
if stdout:
|
if stdout:
|
||||||
|
|
Loading…
Reference in a new issue