Create tox_package_name for tox role

This allows projects, that use tox but may not have a setup.cfg file
still use tox siblings. We do this to allow non-python project, to use
tox as an entry point for testing, and still have depends-on
requirements work in zuul.

Change-Id: I9b37117b27ff6b7e436d456b6cbae39ccb9b968c
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2020-12-16 11:11:46 -05:00
parent 77833088f2
commit c6bf69e60b
3 changed files with 20 additions and 8 deletions

View File

@ -35,6 +35,11 @@ Runs tox for a project
Flag controlling whether to attempt to install python packages from any
other source code repos zuul has checked out. Defaults to True.
.. zuul:rolevar:: tox_package_name
Allows a user to setup the package name to be used by tox, over reading
a setup.cfg file in the project.
.. zuul:rolevar:: zuul_work_dir
:default: {{ zuul.project.src_dir }}

View File

@ -287,11 +287,13 @@ def main():
argument_spec=dict(
tox_show_config=dict(required=True, type='path'),
tox_constraints_file=dict(type='str'),
tox_package_name=dict(type='str'),
project_dir=dict(required=True, type='str'),
projects=dict(required=True, type='list'),
)
)
constraints = module.params.get('tox_constraints_file')
tox_package_name = module.params.get('tox_package_name')
project_dir = module.params['project_dir']
projects = module.params['projects']
tox_show_config = module.params.get('tox_show_config')
@ -308,19 +310,23 @@ def main():
log.append('Using envlist: {}'.format(envlist))
if not os.path.exists(os.path.join(project_dir, 'setup.cfg')):
if (not tox_package_name
and not os.path.exists(os.path.join(project_dir, 'setup.cfg'))
):
module.exit_json(changed=False, msg="No setup.cfg, no action needed")
if constraints and not os.path.exists(constraints):
module.fail_json(msg="Constraints file {constraints} was not found")
# Who are we?
try:
c = configparser.ConfigParser()
c.read(os.path.join(project_dir, 'setup.cfg'))
package_name = c.get('metadata', 'name')
except Exception:
module.exit_json(
changed=False, msg="No name in setup.cfg, skipping siblings")
package_name = tox_package_name
if not package_name:
try:
c = configparser.ConfigParser()
c.read(os.path.join(project_dir, 'setup.cfg'))
package_name = c.get('metadata', 'name')
except Exception:
module.exit_json(
changed=False, msg="No name in setup.cfg, skipping siblings")
log.append(
"Processing siblings for {name} from {project_dir}".format(

View File

@ -30,6 +30,7 @@
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 }}"