Merge "tox: empty envlist should behave like tox -e ALL"

This commit is contained in:
Zuul 2020-05-26 13:56:09 +00:00 committed by Gerrit Code Review
commit 8dbd1a79d5
4 changed files with 39 additions and 65 deletions

View File

@ -13,9 +13,6 @@ Runs tox for a project
``ALL`` runs all test environments while an empty string runs ``ALL`` runs all test environments while an empty string runs
all test environments configured with ``envlist`` in tox. all test environments configured with ``envlist`` in tox.
Internally this will always be expanded into a comma separated
list of test environments to run.
.. zuul:rolevar:: tox_executable .. zuul:rolevar:: tox_executable
:default: tox :default: tox

View File

@ -30,11 +30,6 @@ description:
requirements: requirements:
- "python >= 3.5" - "python >= 3.5"
options: options:
tox_envlist:
description:
- The tox test environments to act on.
required: true
type: str
tox_show_config: tox_show_config:
description: description:
- Path to a file containing the output from C(tox --showconfig). - Path to a file containing the output from C(tox --showconfig).
@ -59,6 +54,7 @@ except ImportError:
import pkg_resources as prAPI import pkg_resources as prAPI
import os import os
import ast
import subprocess import subprocess
import tempfile import tempfile
import traceback import traceback
@ -256,10 +252,28 @@ def install_siblings(envdir, projects, package_name, constraints):
return changed return changed
def get_envlist(tox_config):
envlist = []
if 'tox' in tox_config.sections():
envlist_default = ast.literal_eval(
tox_config.get('tox', 'envlist_default'))
tox_args = ast.literal_eval(tox_config.get('tox', 'args'))
if 'ALL' in tox_args or not envlist_default:
for section in tox_config.sections():
if section.startswith('testenv'):
envlist.append(section.split(':')[1])
else:
for testenv in envlist_default:
envlist.append(testenv)
else:
for section in tox_config.sections():
envlist.append(section.split(':')[1])
return envlist
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
tox_envlist=dict(required=True, type='str'),
tox_show_config=dict(required=True, type='path'), tox_show_config=dict(required=True, type='path'),
tox_constraints_file=dict(type='str'), tox_constraints_file=dict(type='str'),
project_dir=dict(required=True, type='str'), project_dir=dict(required=True, type='str'),
@ -269,14 +283,12 @@ def main():
constraints = module.params.get('tox_constraints_file') constraints = module.params.get('tox_constraints_file')
project_dir = module.params['project_dir'] project_dir = module.params['project_dir']
projects = module.params['projects'] projects = module.params['projects']
tox_envlist = module.params.get('tox_envlist', '')
tox_show_config = module.params.get('tox_show_config') tox_show_config = module.params.get('tox_show_config')
tox_config = configparser.RawConfigParser() tox_config = configparser.RawConfigParser()
tox_config.read(tox_show_config) tox_config.read(tox_show_config)
envlist = {testenv.strip() for testenv envlist = get_envlist(tox_config)
in tox_envlist.split(',')}
if not envlist: if not envlist:
module.exit_json( module.exit_json(
@ -306,7 +318,7 @@ def main():
changed = False changed = False
for testenv in envlist: for testenv in envlist:
testenv_config = tox_config['testenv:{}'.format(testenv)] testenv_config = tox_config["testenv:{}".format(testenv)]
envdir = testenv_config['envdir'] envdir = testenv_config['envdir']
envlogdir = testenv_config['envlogdir'] envlogdir = testenv_config['envlogdir']
try: try:

View File

@ -20,49 +20,6 @@
UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}" UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}"
when: tox_constraints_file is defined when: tox_constraints_file is defined
# Tox siblings cannot take 'ALL' and tox_parse_output expects
# an envlist to be supplied so always set _tox_envlist equal to
# the list of testenvs we're going to run
- name: Set _tox_envlist from supplied tox_envlist
set_fact:
_tox_envlist: "{{ tox_envlist }}"
when:
- tox_envlist is defined and tox_envlist
- tox_envlist != "ALL"
- name: Get tox default envlist
command: "{{ tox_executable }} -l"
args:
chdir: "{{ zuul_work_dir }}"
register: _tox_default_envlist
when: tox_envlist is not defined or not tox_envlist
- name: Set tox envlist fact
set_fact:
_tox_envlist: "{{ _tox_default_envlist.stdout_lines | join(',') }}"
when:
- _tox_default_envlist is defined
- _tox_default_envlist.stdout_lines is defined
- name: Get all tox testenvs
command: "{{ tox_executable }} -a"
args:
chdir: "{{ zuul_work_dir }}"
register: _tox_all_testenvs
when: tox_envlist is defined and tox_envlist == 'ALL'
- name: Set tox envlist fact
set_fact:
_tox_envlist: "{{ _tox_all_testenvs.stdout_lines | join(',') }}"
when:
- _tox_all_testenvs is defined
- _tox_all_testenvs.stdout_lines is defined
- name: Fail if tox_envlist is empty
fail:
msg: "No envlist configured in zuul or tox.ini"
when: _tox_envlist is not defined
- name: Install tox siblings - name: Install tox siblings
include_tasks: siblings.yaml include_tasks: siblings.yaml
when: tox_install_siblings when: tox_install_siblings
@ -71,7 +28,9 @@
debug: debug:
msg: >- msg: >-
{{ tox_executable }} {{ tox_executable }}
-e{{ _tox_envlist }} {% if tox_envlist is defined and tox_envlist %}
-e{{ tox_envlist }}
{% endif %}
{{ tox_extra_args }} {{ tox_extra_args }}
- block: - block:
@ -81,7 +40,9 @@
environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}" environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}"
command: >- command: >-
{{ tox_executable }} {{ tox_executable }}
-e{{ _tox_envlist }} {% if tox_envlist is defined and tox_envlist %}
-e{{ tox_envlist }}
{% endif %}
{{ tox_extra_args }} {{ tox_extra_args }}
register: tox_output register: tox_output
@ -91,7 +52,7 @@
- name: Look for output - name: Look for output
tox_parse_output: tox_parse_output:
tox_output: '{{ tox_output.stdout }}' tox_output: '{{ tox_output.stdout }}'
tox_envlist: '{{ _tox_envlist }}' tox_envlist: '{{ tox_envlist | default("default") }}'
workdir: '{{ zuul_work_dir }}' workdir: '{{ zuul_work_dir }}'
when: tox_inline_comments when: tox_inline_comments
register: file_comments register: file_comments

View File

@ -3,7 +3,9 @@
command: >- command: >-
{{ tox_executable }} {{ tox_executable }}
--notest --notest
-e{{ _tox_envlist }} {% if tox_envlist is defined and tox_envlist %}
-e{{ tox_envlist }}
{% endif %}
args: args:
chdir: "{{ zuul_work_dir }}" chdir: "{{ zuul_work_dir }}"
environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}" environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}"
@ -13,17 +15,19 @@
tempfile: tempfile:
register: _tox_show_config_tempfile register: _tox_show_config_tempfile
# py27, py35..py38 etc are generated on the fly if not
# explicitly added to tox.ini, so force tox to generate
# the config for the testenvs we're using.
- name: Get tox envlist config - name: Get tox envlist config
shell: "{{ tox_executable }} --showconfig -e {{ _tox_envlist }} > {{ _tox_show_config_tempfile.path }}" shell: >-
{{ tox_executable }}
--showconfig
{% if tox_envlist is defined and tox_envlist %}
-e{{ tox_envlist }}
{% endif %}
> {{ _tox_show_config_tempfile.path }}
args: args:
chdir: "{{ zuul_work_dir }}" chdir: "{{ zuul_work_dir }}"
- name: Install any sibling python packages - name: Install any sibling python packages
tox_install_sibling_packages: tox_install_sibling_packages:
tox_envlist: "{{ _tox_envlist }}"
tox_show_config: "{{ _tox_show_config_tempfile.path }}" tox_show_config: "{{ _tox_show_config_tempfile.path }}"
tox_constraints_file: "{{ tox_constraints_file | default(omit) }}" tox_constraints_file: "{{ tox_constraints_file | default(omit) }}"
project_dir: "{{ zuul_work_dir }}" project_dir: "{{ zuul_work_dir }}"