ansible-test - Clean up venv code.

pull/77058/head
Matt Clay 3 years ago
parent f2612ce169
commit addb9baec2

@ -209,11 +209,7 @@ class PosixProfile(HostProfile[TPosixConfig], metaclass=abc.ABCMeta):
python = self.config.python
if isinstance(python, VirtualPythonConfig):
python = VirtualPythonConfig(
version=python.version,
system_site_packages=python.system_site_packages,
path=os.path.join(get_virtual_python(self.args, python), 'bin', 'python'),
)
python = get_virtual_python(self.args, python)
self.state['python'] = python

@ -41,7 +41,7 @@ from .python_requirements import (
def get_virtual_python(
args, # type: EnvironmentConfig
python, # type: VirtualPythonConfig
):
): # type: (...) -> VirtualPythonConfig
"""Create a virtual environment for the given Python and return the path to its root."""
if python.system_site_packages:
suffix = '-ssp'
@ -51,6 +51,12 @@ def get_virtual_python(
virtual_environment_path = os.path.join(ResultType.TMP.path, 'delegation', f'python{python.version}{suffix}')
virtual_environment_marker = os.path.join(virtual_environment_path, 'marker.txt')
virtual_environment_python = VirtualPythonConfig(
version=python.version,
path=os.path.join(virtual_environment_path, 'bin', 'python'),
system_site_packages=python.system_site_packages,
)
if os.path.exists(virtual_environment_marker):
display.info('Using existing Python %s virtual environment: %s' % (python.version, virtual_environment_path), verbosity=1)
else:
@ -60,11 +66,6 @@ def get_virtual_python(
if not create_virtual_environment(args, python, virtual_environment_path, python.system_site_packages):
raise ApplicationError(f'Python {python.version} does not provide virtual environment support.')
virtual_environment_python = VirtualPythonConfig(
version=python.version,
path=os.path.join(virtual_environment_path, 'bin', 'python'),
)
commands = collect_bootstrap(virtual_environment_python)
run_pip(args, virtual_environment_python, commands, None) # get_virtual_python()
@ -72,7 +73,7 @@ def get_virtual_python(
# touch the marker to keep track of when the virtualenv was last used
pathlib.Path(virtual_environment_marker).touch()
return virtual_environment_path
return virtual_environment_python
def create_virtual_environment(args, # type: EnvironmentConfig

Loading…
Cancel
Save