67f223b53a
This partially reverts commit
3f961ce202
.
This alternative installs wheel with the ensure-pip role instead of in
a separate role. wheel is very closely linked with pip install
operations so this isn't a large overreach of the role.
I suggest this for several reasons; firstly the python-wheel role
doesn't try to install packages, so we end up with mixed system pip
and upstream versions of wheel most of the time. This is the type of
thing that has proven problematic in the past. It also installs via
pip --user; something we've already had problems with tox when for
various reasons roles want to run this as non-zuul user. Using
ensure-pip we keep the packaged versions together.
[1] did try to install wheel with root, but during runtime which
didn't work due to sudo being revoked. This should work for the
existing build-python-release job, because it already includes
ensure-pip in pre-run via playbooks/python/pre.yaml
I believe our conclusion on the ensure-* roles was that requiring
root/become: for installation is OK, but we should have a no-op path
if the tools are found. This is consistent with that approach
(i.e. if you want wheel and can't do sudo, you should pre-install it
on your image using whatever you build that with).
This adds a check to the existing "is pip installed" check to also
check if wheel packages are available. If not we trigger the install
path.
This revealed some issues with RedHat.yaml -- we can always install
Python 3 (packages available for CentOS 7) so remove that check, and
if Ansible is running under Python 2; ensure we install the
dependencies too (not only if it is forced).
Update the documentation to describe that it will enable support for
bdist_wheel, and add a basic sanity test that wheels are produced by
pip. The existing build-python-release job is kept; although it is
modified to use the playbooks/python/pre.yaml playbook as the build
job does.
Change-Id: I2ab11bb45b6b2a49d54db39195228ab40141185c
[1] https://review.opendev.org/#/c/736001/5/roles/build-python-release/tasks/main.yaml
81 lines
2.4 KiB
YAML
81 lines
2.4 KiB
YAML
- name: Check if pip is installed
|
|
shell: |
|
|
PYTHON2=0
|
|
PYTHON3=1
|
|
{% if ensure_pip_from_packages and ensure_pip_from_packages_with_python2 %}
|
|
PYTHON2=1
|
|
{% elif ensure_pip_from_upstream and 'python2' in ensure_pip_from_upstream_interpreters %}
|
|
PYTHON2=1
|
|
{% endif %}
|
|
{% if ensure_pip_from_upstream and 'python3' not in ensure_pip_from_upstream_interpreters %}
|
|
PYTHON3=0
|
|
{% endif %}
|
|
|
|
# Not all platforms install a `pip` when installing python
|
|
# specific pip packages. We first check if pip$VERSION is
|
|
# available and if not fallback to checking if just `pip`
|
|
# is present.
|
|
if [ "$PYTHON2" -eq "1" ] ; then
|
|
command -v pip2 || command -v pip || exit 1
|
|
python2 -m wheel --help || exit 1
|
|
fi
|
|
if [ "$PYTHON3" -eq "1" ] ; then
|
|
command -v pip3 || command -v pip || exit 1
|
|
python3 -m wheel --help || exit 1
|
|
fi
|
|
args:
|
|
executable: /bin/bash
|
|
register: pip_preinstalled
|
|
failed_when: false
|
|
|
|
- name: Install pip from packages
|
|
include_tasks: "{{ zj_distro_os }}"
|
|
with_first_found:
|
|
- "{{ ansible_distribution_release }}.yaml"
|
|
- "{{ ansible_distribution }}.yaml"
|
|
- "{{ ansible_os_family }}.yaml"
|
|
- "default.yaml"
|
|
when:
|
|
- ensure_pip_from_packages
|
|
- pip_preinstalled.rc != 0
|
|
loop_control:
|
|
loop_var: zj_distro_os
|
|
|
|
- name: Include workarounds
|
|
import_tasks: workarounds.yaml
|
|
|
|
- name: Install pip from source
|
|
include_tasks: source.yaml
|
|
when:
|
|
- ensure_pip_from_upstream
|
|
- pip_preinstalled.rc != 0
|
|
|
|
#
|
|
# Export a working virtualenv_command
|
|
#
|
|
|
|
# Ansible's "pip:" module looks at the virtualenv_command and, if it
|
|
# isn't fully qualified, tries to find the command and add the leading
|
|
# path for you. However, it doesn't split it up; it will actually
|
|
# look for a command "python3 -m venv" (not, as you'd want, just
|
|
# "python") and everything fails. Thus we find the full path to
|
|
# python3 and build our default command for output.
|
|
- name: Probe for venv python full path
|
|
shell: |
|
|
command -v python3
|
|
args:
|
|
executable: /bin/bash
|
|
tags:
|
|
- skip_ansible_lint # command is a bash built-in
|
|
failed_when: false
|
|
register: _venv_probe
|
|
|
|
- name: Set host default
|
|
set_fact:
|
|
_host_virtualenv: '{{ (_venv_probe.rc == 0) | ternary(_venv_probe.stdout + " -m venv", "virtualenv") }}'
|
|
|
|
- name: Set ensure_pip_virtualenv_cmd
|
|
set_fact:
|
|
ensure_pip_virtualenv_command: '{{ ensure_pip_virtualenv_command | default(_host_virtualenv) }}'
|
|
cacheable: true
|