Improved compatibility with both tox>3,<4 and tox>=4

Tox>3,<4 does not support dots in generative envlists and tox>=4 changed
its behaviour when it detects hyphens in env names [1].

[1] 0580121601/src/tox/tox_env/python/api.py (L130)

Change-Id: I63ad716415755d2a140a6ade97d22bd18236a0df
This commit is contained in:
Jakob Meng 2022-12-27 12:08:22 +01:00
parent 85fa2bb2b6
commit 7945d7f01a
2 changed files with 34 additions and 68 deletions

View File

@ -39,7 +39,7 @@
- .zuul.yaml - .zuul.yaml
vars: vars:
zuul_work_dir: src/opendev.org/openstack/ansible-collections-openstack zuul_work_dir: src/opendev.org/openstack/ansible-collections-openstack
tox_envlist: ansible tox_envlist: ansible_latest
tox_install_siblings: true tox_install_siblings: true
fetch_subunit: false fetch_subunit: false
devstack_plugins: devstack_plugins:
@ -125,7 +125,7 @@
- name: github.com/ansible/ansible - name: github.com/ansible/ansible
override-checkout: stable-2.9 override-checkout: stable-2.9
vars: vars:
tox_envlist: ansible-2.9 tox_envlist: ansible_2_9
- job: - job:
name: ansible-collections-openstack-functional-devstack-ansible-2.11 name: ansible-collections-openstack-functional-devstack-ansible-2.11
@ -138,7 +138,7 @@
- name: github.com/ansible/ansible - name: github.com/ansible/ansible
override-checkout: stable-2.11 override-checkout: stable-2.11
vars: vars:
tox_envlist: ansible-2.11 tox_envlist: ansible_2_11
- job: - job:
name: ansible-collections-openstack-functional-devstack-ansible-2.12 name: ansible-collections-openstack-functional-devstack-ansible-2.12
@ -151,7 +151,7 @@
- name: github.com/ansible/ansible - name: github.com/ansible/ansible
override-checkout: stable-2.12 override-checkout: stable-2.12
vars: vars:
tox_envlist: ansible-2.12 tox_envlist: ansible_2_12
- job: - job:
name: ansible-collections-openstack-functional-devstack-ansible-devel name: ansible-collections-openstack-functional-devstack-ansible-devel
@ -171,7 +171,6 @@
- job: - job:
name: openstack-tox-linters-ansible name: openstack-tox-linters-ansible
parent: openstack-tox-linters parent: openstack-tox-linters
nodeset: ubuntu-focal
description: | description: |
Run openstack collections linter tests using the devel branch of ansible Run openstack collections linter tests using the devel branch of ansible
required-projects: required-projects:
@ -180,7 +179,7 @@
vars: vars:
# override tox_constraints_file from parent job # override tox_constraints_file from parent job
tox_constraints_file: '{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/constraints-none.txt' tox_constraints_file: '{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/constraints-none.txt'
tox_envlist: linters tox_envlist: linters_latest
tox_install_siblings: true tox_install_siblings: true
- job: - job:
@ -198,13 +197,15 @@
- job: - job:
name: openstack-tox-linters-ansible-2.12 name: openstack-tox-linters-ansible-2.12
parent: openstack-tox-linters-ansible parent: openstack-tox-linters-ansible
nodeset: ubuntu-focal
description: | description: |
Run openstack collections linter tests using the 2.12 branch of ansible Run openstack collections linter tests using the 2.12 branch of ansible
required-projects: required-projects:
- name: github.com/ansible/ansible - name: github.com/ansible/ansible
override-checkout: stable-2.12 override-checkout: stable-2.12
vars: vars:
tox_envlist: linters-2.12 ensure_tox_version: '<4'
tox_envlist: linters_2_12
python_version: 3.8 python_version: 3.8
bindep_profile: test py38 bindep_profile: test py38

87
tox.ini
View File

@ -1,16 +1,15 @@
[tox] [tox]
minversion = 3.18.0 minversion = 3.18.0
envlist = linters envlist = linters_latest,ansible_latest
skipsdist = True skipsdist = True
ignore_basepython_conflict = True ignore_basepython_conflict = True
[testenv] [testenv]
skip_install = True skip_install = True
install_command = python -m pip install {opts} {packages} install_command = python3 -m pip install {opts} {packages}
basepython = python3 basepython = python3
passenv = passenv =
OS_* OS_*
pip: PIP_INSTALL
setenv = setenv =
VIRTUAL_ENV={envdir} VIRTUAL_ENV={envdir}
LANG=en_US.UTF-8 LANG=en_US.UTF-8
@ -19,17 +18,16 @@ setenv =
OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true} OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true}
OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true} OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true}
OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true} OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true}
pip: PIP_INSTALL={env:PIP_INSTALL:true}
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements.txt
pip: {toxinidir}
commands = stestr run {posargs} commands = stestr run {posargs}
stestr slowest stestr slowest
[testenv:pep8] [testenv:pep8]
# for Zuul CI job tox-pep8
commands = commands =
flake8 flake8
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements.txt
[testenv:build] [testenv:build]
allowlist_externals = bash allowlist_externals = bash
@ -44,37 +42,21 @@ commands =
ansible-galaxy collection build --force {toxinidir} --output-path {toxinidir}/build_artifact ansible-galaxy collection build --force {toxinidir} --output-path {toxinidir}/build_artifact
bash {toxinidir}/tools/check-import.sh {toxinidir} bash {toxinidir}/tools/check-import.sh {toxinidir}
[testenv:linters] [testenv:linters_{2_9,2_11,2_12,latest}]
allowlist_externals = bash allowlist_externals = bash
passenv = *
deps =
{[testenv]deps}
commands = commands =
{[testenv:build]commands} {[testenv:build]commands}
{[testenv:pep8]commands} flake8
ansible --version ansible --version
bash {toxinidir}/tools/run-ansible-sanity.sh {toxinidir} bash {toxinidir}/tools/run-ansible-sanity.sh {toxinidir}
[testenv:linters-2.9]
passenv = {[testenv:linters]passenv}
commands = {[testenv:linters]commands}
deps = deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt} -c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements-ansible-2.9.txt {[testenv:build]deps}
linters_latest: -r{toxinidir}/tests/requirements.txt
[testenv:linters-2.11] linters_2_9: -r{toxinidir}/tests/requirements-ansible-2.9.txt
passenv = {[testenv:linters]passenv} linters_2_11: -r{toxinidir}/tests/requirements-ansible-2.11.txt
commands = {[testenv:linters]commands} linters_2_12: -r{toxinidir}/tests/requirements-ansible-2.12.txt
deps = passenv = *
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements-ansible-2.11.txt
[testenv:linters-2.12]
passenv = {[testenv:linters]passenv}
commands = {[testenv:linters]commands}
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements-ansible-2.12.txt
[flake8] [flake8]
# W503 Is supposed to be off by default but in the latest pycodestyle isn't. # W503 Is supposed to be off by default but in the latest pycodestyle isn't.
@ -87,46 +69,29 @@ ignore = W503,H4,E501,E402,H301
show-source = True show-source = True
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,ansible_collections exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,ansible_collections
[testenv:ansible] [testenv:ansible_{2_9,2_11,2_12,latest}]
allowlist_externals = bash allowlist_externals = bash
commands =
bash {toxinidir}/ci/run-ansible-tests-collection.sh -e {envdir} {posargs}
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
ansible_latest: -r{toxinidir}/tests/requirements.txt
ansible_2_9: -r{toxinidir}/tests/requirements-ansible-2.9.txt
ansible_2_11: -r{toxinidir}/tests/requirements-ansible-2.11.txt
ansible_2_12: -r{toxinidir}/tests/requirements-ansible-2.12.txt
# Need to pass some env vars for the Ansible playbooks # Need to pass some env vars for the Ansible playbooks
passenv = passenv =
HOME HOME
USER USER
ANSIBLE_* ANSIBLE_*
deps =
{[testenv]deps}
commands =
bash {toxinidir}/ci/run-ansible-tests-collection.sh -e {envdir} {posargs}
[testenv:ansible-2.9] [testenv:galaxy_release]
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements-ansible-2.9.txt
passenv = {[testenv:ansible]passenv}
commands = {[testenv:ansible]commands}
[testenv:ansible-2.11]
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements-ansible-2.11.txt
passenv = {[testenv:ansible]passenv}
commands = {[testenv:ansible]commands}
[testenv:ansible-2.12]
deps =
-c{env:TOX_CONSTRAINTS_FILE:{toxinidir}/tests/constraints-none.txt}
-r{toxinidir}/tests/requirements-ansible-2.12.txt
passenv = {[testenv:ansible]passenv}
commands = {[testenv:ansible]commands}
[testenv:galaxy-release]
allowlist_externals = mkdir rm sed allowlist_externals = mkdir rm sed
deps =
ansible-core
commands = commands =
rm -rf /tmp/collection_built/ rm -rf /tmp/collection_built/
mkdir -p /tmp/collection_built/ mkdir -p /tmp/collection_built/
sed -i "s/version:.*/version: {env:VERSION_TAG}/" {toxinidir}/galaxy.yml sed -i "s/version:.*/version: {env:VERSION_TAG}/" {toxinidir}/galaxy.yml
ansible-galaxy collection build {toxinidir} --output-path /tmp/collection_built/ --force ansible-galaxy collection build {toxinidir} --output-path /tmp/collection_built/ --force
ansible-galaxy collection publish /tmp/collection_built/openstack-cloud-{env:VERSION_TAG}.tar.gz --token {env:API_GALAXY_TOKEN} ansible-galaxy collection publish /tmp/collection_built/openstack-cloud-{env:VERSION_TAG}.tar.gz --token {env:API_GALAXY_TOKEN}
deps =
ansible-core