zuul-jobs/roles/ensure-tox/tasks/main.yaml
Clark Boylan 41153f0653 Update zuul-jobs to handle tox3 and tox4
Tox 4 released today and is a complete rewrite with many backward
incompatible changes. We need to update a number of things to support
that in the zuul-jobs tox role and elsewhere. A possibly incomplete
list of what was changed in this commit to make this work:

  * Don't run tox --showconfig with {{ tox_extra_args }} as -vv is
    in tox_extra_args by default and results in interleaved debug
    output in the ini output making it invalid ini content.
  * Update the tox siblings tox config parser to look for renamed
    environment dir locations.
  * Stop using whitelist_externals and use allowlist_exteranls
    because whitelist_externals is removed and external commands that
    are not explicitly allowed produce errors.
  * Make the tox version configurable in ensure-tox as some users
    may not be able to easily upgrade to tox v4.
  * Escape literal # chars in tox.ini as they are treated as comments
    when in the command strings now.
    https://github.com/tox-dev/tox/issues/2617

Change-Id: I38e13b4f13bb1b2d6fb7e5c70b708e9bb016a455
2022-12-07 15:14:16 -08:00

49 lines
1.3 KiB
YAML

- name: Install pip
include_role:
name: ensure-pip
vars:
ensure_pip_from_packages_with_python2: '{{ tox_prefer_python2 }}'
- name: Check if tox is installed
shell: |
command -v {{ tox_executable }} {{ tox_venv_path }}/bin/tox || exit 1
args:
executable: /bin/bash
register: tox_preinstalled
failed_when: false
- name: Export preinstalled tox_exectuable
set_fact:
tox_executable: '{{ tox_preinstalled.stdout_lines[0] }}'
cacheable: true
when: tox_preinstalled.rc == 0
- name: Install tox to local env
when: tox_preinstalled.rc != 0
block:
- name: Create local venv
command: '{{ ensure_pip_virtualenv_command }} {{ tox_venv_path }}'
- name: Install tox to local venv
# We pin tox to version <4 as v4 is not currently compatible with
# zuul's tox siblings processing.
command: '{{ tox_venv_path }}/bin/pip install tox{{ ensure_tox_version }}'
- name: Export installed tox_executable path
set_fact:
tox_executable: '{{ tox_venv_path }}/bin/tox'
cacheable: true
- name: Output tox version
command: "{{ tox_executable }} --version"
- name: Make global symlink
when:
- ensure_global_symlinks
- tox_executable != '/usr/local/bin/tox'
file:
state: link
src: "{{ tox_executable }}"
dest: /usr/local/bin/tox
become: yes