From 21247c828ea58c5900fef7f2e9277fe2183b6ce0 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 11 Jan 2024 12:02:57 -0800 Subject: [PATCH] ansible-test - Bypass PEP 668 checks When ansible-test installs requirements, it now instructs pip to allow installs on externally managed environments as defined by PEP 668. This only occurs in ephemeral environments managed by ansible-test, such as containers, or when the `--requirements` option is used. --- changelogs/fragments/ansible-test-pep-668.yml | 3 +++ test/lib/ansible_test/_util/target/setup/requirements.py | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/ansible-test-pep-668.yml diff --git a/changelogs/fragments/ansible-test-pep-668.yml b/changelogs/fragments/ansible-test-pep-668.yml new file mode 100644 index 00000000000..b17428c1463 --- /dev/null +++ b/changelogs/fragments/ansible-test-pep-668.yml @@ -0,0 +1,3 @@ +minor_changes: +- ansible-test - When ansible-test installs requirements, it now instructs pip to allow installs on externally managed environments as defined by PEP 668. + This only occurs in ephemeral environments managed by ansible-test, such as containers, or when the `--requirements` option is used. diff --git a/test/lib/ansible_test/_util/target/setup/requirements.py b/test/lib/ansible_test/_util/target/setup/requirements.py index 0bf52157d30..a320dfce19a 100644 --- a/test/lib/ansible_test/_util/target/setup/requirements.py +++ b/test/lib/ansible_test/_util/target/setup/requirements.py @@ -249,6 +249,14 @@ def common_pip_environment(): # type: () -> t.Dict[str, str] """Return common environment variables used to run pip.""" env = os.environ.copy() + # When ansible-test installs requirements outside a virtual environment, it does so under one of two conditions: + # 1) The environment is an ephemeral one provisioned by ansible-test. + # 2) The user has provided the `--requirements` option to force installation of requirements. + # It seems reasonable to bypass PEP 668 checks in both of these cases. + # Doing so with an environment variable allows it to work under any version of pip which supports it, without breaking older versions. + # NOTE: pip version 23.0 enforces PEP 668 but does not support the override, in which case upgrading pip is required. + env.update(PIP_BREAK_SYSTEM_PACKAGES='1') + return env