diff --git a/roles/tox/README.rst b/roles/tox/README.rst index c61498728..8ace6a443 100644 --- a/roles/tox/README.rst +++ b/roles/tox/README.rst @@ -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 }} diff --git a/roles/tox/library/tox_install_sibling_packages.py b/roles/tox/library/tox_install_sibling_packages.py index bb7319c6a..6f8981274 100644 --- a/roles/tox/library/tox_install_sibling_packages.py +++ b/roles/tox/library/tox_install_sibling_packages.py @@ -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( diff --git a/roles/tox/tasks/siblings.yaml b/roles/tox/tasks/siblings.yaml index 8a19642c9..74eb643fc 100644 --- a/roles/tox/tasks/siblings.yaml +++ b/roles/tox/tasks/siblings.yaml @@ -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 }}"