From b4cbe1adcf628981eb2b67f51c9af09e46a39d8a Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 21 Oct 2021 14:55:01 -0700 Subject: [PATCH] ansible-test - Fix Python real prefix detection. --- .../fragments/ansible-test-venv-real-prefix.yaml | 2 ++ .../_util/controller/tools/virtualenvcheck.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-venv-real-prefix.yaml diff --git a/changelogs/fragments/ansible-test-venv-real-prefix.yaml b/changelogs/fragments/ansible-test-venv-real-prefix.yaml new file mode 100644 index 00000000000..c74fb047e99 --- /dev/null +++ b/changelogs/fragments/ansible-test-venv-real-prefix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix Python real prefix detection when running in a ``venv`` virtual environment. diff --git a/test/lib/ansible_test/_util/controller/tools/virtualenvcheck.py b/test/lib/ansible_test/_util/controller/tools/virtualenvcheck.py index 90dfa39410e..4c542a23fde 100644 --- a/test/lib/ansible_test/_util/controller/tools/virtualenvcheck.py +++ b/test/lib/ansible_test/_util/controller/tools/virtualenvcheck.py @@ -5,10 +5,22 @@ __metaclass__ = type import json try: + # virtualenv <20 from sys import real_prefix except ImportError: real_prefix = None +try: + # venv and virtualenv >= 20 + from sys import base_exec_prefix +except ImportError: + base_exec_prefix = None + +try: + from sys import base_exec_prefix +except ImportError: + base_exec_prefix = None + print(json.dumps(dict( - real_prefix=real_prefix, + real_prefix=real_prefix or base_exec_prefix, )))