From addb9baec20fcede2a2494069c01c73b3d2e4fc9 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 17 Feb 2022 09:39:11 -0800 Subject: [PATCH] ansible-test - Clean up venv code. --- test/lib/ansible_test/_internal/host_profiles.py | 6 +----- test/lib/ansible_test/_internal/venv.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/test/lib/ansible_test/_internal/host_profiles.py b/test/lib/ansible_test/_internal/host_profiles.py index 0a08d68f18d..e3aeeeebbc8 100644 --- a/test/lib/ansible_test/_internal/host_profiles.py +++ b/test/lib/ansible_test/_internal/host_profiles.py @@ -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 diff --git a/test/lib/ansible_test/_internal/venv.py b/test/lib/ansible_test/_internal/venv.py index fb8638f2fa4..9c48633d21f 100644 --- a/test/lib/ansible_test/_internal/venv.py +++ b/test/lib/ansible_test/_internal/venv.py @@ -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