zuul-jobs/roles/tox/tasks/siblings.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.6 KiB
YAML

# Install sibling with tox so we can replace them later
- name: Run tox without tests
command: >-
{{ tox_executable }}
{% if tox_config_file is defined and tox_config_file %}
-c{{ tox_config_file }}
{% endif %}
--notest
{% if tox_envlist is defined and tox_envlist %}
-e{{ tox_envlist }}
{% endif %}
{{ tox_extra_args }}
args:
chdir: "{{ zuul_work_dir }}"
environment: "{{ tox_environment | combine(tox_constraints_env | default({})) }}"
# This is needed since python < 3.2 can't parse ini files from strings
- name: Create a tempfile to save tox showconfig
tempfile:
register: _tox_show_config_tempfile
- name: Get tox envlist config
shell: >-
{{ tox_executable }}
{% if tox_config_file is defined and tox_config_file %}
-c{{ tox_config_file }}
{% endif %}
--showconfig
{% if tox_envlist is defined and tox_envlist %}
-e{{ tox_envlist }}
{% endif %}
> {{ _tox_show_config_tempfile.path }}
args:
chdir: "{{ zuul_work_dir }}"
environment: "{{ tox_environment | combine(tox_constraints_env | default({})) }}"
- name: Install any sibling python packages
tox_install_sibling_packages:
tox_show_config: "{{ _tox_show_config_tempfile.path }}"
tox_constraints_file: "{{ tox_constraints_file | default(omit) }}"
tox_package_name: "{{ tox_package_name | default(omit) }}"
project_dir: "{{ zuul_work_dir }}"
projects: "{{ zuul.projects.values() | selectattr('required') | list }}"
- name: Remove tempfile
file:
state: absent
path: "{{ _tox_show_config_tempfile.path }}"