From 5447d0eb4f8d64d8af5660963e3c24c2b0373486 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Thu, 14 May 2026 23:46:55 +1200 Subject: [PATCH] Setup pip path generic (#12045) * setup_pip_path: use sysconfig to build pip scripts path generically Co-Authored-By: Claude Sonnet 4.6 * setup_pip_path: calculate PATH prepended with pip installation path * move environment up to block * obtain path from pip itself * apparently the python interpreter doesnt go into ansible_facts * rename role to setup_pip_scripts_path --------- Co-authored-by: Claude Sonnet 4.6 --- .../setup_pip_scripts_path/tasks/main.yml | 39 +++++++++++++++++++ .../integration/targets/supervisorctl/aliases | 2 - .../targets/supervisorctl/meta/main.yml | 1 + .../targets/supervisorctl/tasks/main.yml | 5 ++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/integration/targets/setup_pip_scripts_path/tasks/main.yml diff --git a/tests/integration/targets/setup_pip_scripts_path/tasks/main.yml b/tests/integration/targets/setup_pip_scripts_path/tasks/main.yml new file mode 100644 index 0000000000..f6c1d1178a --- /dev/null +++ b/tests/integration/targets/setup_pip_scripts_path/tasks/main.yml @@ -0,0 +1,39 @@ +--- +#################################################################### +# WARNING: These are designed specifically for Ansible tests # +# and should not be used as examples of how to write Ansible roles # +#################################################################### + +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: Get facts + setup: + when: ansible_facts == {} + +# pip._internal.locations.get_scheme() reflects pip's actual install scheme (e.g. RHEL root → /usr/local/bin), +# which can differ from sysconfig.get_path('scripts') (e.g. RHEL → /usr/bin). +- name: Get pip scripts path from current Python interpreter + ansible.builtin.command: + argv: + - "{{ ansible_python_interpreter }}" + - -c + - | + import sys + try: + from pip._internal.locations import get_scheme + print(get_scheme('pip').scripts) + except Exception: + import sysconfig + print(sysconfig.get_path('scripts')) + register: _pip_scripts_path + changed_when: false + +- name: Build pip_path from env PATH and Python scripts dir + vars: + pip_path_list: > + {{ [_pip_scripts_path.stdout.strip()] + ansible_facts.env.PATH.split(":") }} + ansible.builtin.set_fact: + pip_scripts_path: >- + {{ pip_path_list | join(":") }} diff --git a/tests/integration/targets/supervisorctl/aliases b/tests/integration/targets/supervisorctl/aliases index 163ea6ea82..326a499c3e 100644 --- a/tests/integration/targets/supervisorctl/aliases +++ b/tests/integration/targets/supervisorctl/aliases @@ -4,5 +4,3 @@ azp/posix/2 destructive -skip/rhel # TODO executables are installed in /usr/local/bin, which isn't part of $PATH -skip/macos # TODO executables are installed in /Library/Frameworks/Python.framework/Versions/3.11/bin, which isn't part of $PATH diff --git a/tests/integration/targets/supervisorctl/meta/main.yml b/tests/integration/targets/supervisorctl/meta/main.yml index ca1915e05c..22c8ae75e7 100644 --- a/tests/integration/targets/supervisorctl/meta/main.yml +++ b/tests/integration/targets/supervisorctl/meta/main.yml @@ -6,3 +6,4 @@ dependencies: - setup_pkg_mgr - setup_remote_tmp_dir + - setup_pip_scripts_path diff --git a/tests/integration/targets/supervisorctl/tasks/main.yml b/tests/integration/targets/supervisorctl/tasks/main.yml index a84475306d..3945e7ea98 100644 --- a/tests/integration/targets/supervisorctl/tasks/main.yml +++ b/tests/integration/targets/supervisorctl/tasks/main.yml @@ -8,7 +8,10 @@ # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later -- block: +- name: Install/Uninstall supervisorctl block + environment: + PATH: "{{ pip_scripts_path }}" + block: - tempfile: state: directory suffix: supervisorctl-tests