From c0b358fedbbe522c19d0e072885aeaf9165d12c3 Mon Sep 17 00:00:00 2001 From: vass Date: Wed, 1 Apr 2020 20:03:52 +0200 Subject: [PATCH] Rename install-if-python to ensure-if-python for consistency The old role will be kept and include ensure-if-python for backwards-compatability. Change-Id: Ief86799bcd91358d3ce8b6badda272a26ee04002 --- doc/source/python-roles.rst | 1 + playbooks/releasenotes/run.yaml | 2 +- playbooks/sphinx/run.yaml | 2 +- roles/ensure-if-python/README.rst | 30 ++++++++ .../defaults/main.yaml | 0 roles/ensure-if-python/tasks/main.yaml | 74 ++++++++++++++++++ roles/install-if-python/README.rst | 31 +------- roles/install-if-python/tasks/main.yaml | 75 +------------------ 8 files changed, 110 insertions(+), 105 deletions(-) create mode 100644 roles/ensure-if-python/README.rst rename roles/{install-if-python => ensure-if-python}/defaults/main.yaml (100%) create mode 100644 roles/ensure-if-python/tasks/main.yaml diff --git a/doc/source/python-roles.rst b/doc/source/python-roles.rst index f7c8aacfc..f8fb8450c 100644 --- a/doc/source/python-roles.rst +++ b/doc/source/python-roles.rst @@ -4,6 +4,7 @@ Python Roles .. zuul:autorole:: build-python-release .. zuul:autorole:: build-releasenotes .. zuul:autorole:: ensure-babel +.. zuul:autorole:: ensure-if-python .. zuul:autorole:: ensure-python .. zuul:autorole:: ensure-sphinx .. zuul:autorole:: ensure-tox diff --git a/playbooks/releasenotes/run.yaml b/playbooks/releasenotes/run.yaml index 7f08a38c0..17d9a3111 100644 --- a/playbooks/releasenotes/run.yaml +++ b/playbooks/releasenotes/run.yaml @@ -1,6 +1,6 @@ - hosts: all roles: - - role: install-if-python + - role: ensure-if-python # Releasenotes do not need the package itself to be installed install_package: false - build-releasenotes diff --git a/playbooks/sphinx/run.yaml b/playbooks/sphinx/run.yaml index f831207de..1588e9df3 100644 --- a/playbooks/sphinx/run.yaml +++ b/playbooks/sphinx/run.yaml @@ -1,4 +1,4 @@ - hosts: all roles: - - install-if-python + - ensure-if-python - sphinx diff --git a/roles/ensure-if-python/README.rst b/roles/ensure-if-python/README.rst new file mode 100644 index 000000000..8b9fc5b96 --- /dev/null +++ b/roles/ensure-if-python/README.rst @@ -0,0 +1,30 @@ +Install the contents of a directory if they contain a python project. + +Installs into a virtualenv. + +**Role Variables** + +.. zuul:rolevar:: install_package + :default: true + + Flag indicating whether or not the software in the ``zuul_work_dir`` should + be installed. + +.. zuul:rolevar:: error_on_failure + + Flag that indicates installation errors should result in failure. Failures + in installing the target directory are ignored by default. + +.. zuul:rolevar:: constraints_file + + Optional path to a pip constraints file to use when installing. + +.. zuul:rolevar:: zuul_work_virtualenv + :default: ~/.venv + + Virtualenv location in which to install things. + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory to operate in. diff --git a/roles/install-if-python/defaults/main.yaml b/roles/ensure-if-python/defaults/main.yaml similarity index 100% rename from roles/install-if-python/defaults/main.yaml rename to roles/ensure-if-python/defaults/main.yaml diff --git a/roles/ensure-if-python/tasks/main.yaml b/roles/ensure-if-python/tasks/main.yaml new file mode 100644 index 000000000..9719d8aad --- /dev/null +++ b/roles/ensure-if-python/tasks/main.yaml @@ -0,0 +1,74 @@ +# TODO(mordred) rework tox-siblings so it can be used here - probably by +# making it take a parameter as to what path to python/pip to use. + +- name: Find Constraints File + include_role: + name: find-constraints + +- name: Check to see if the project is a python project + find: + paths: "{{ zuul_work_dir }}" + patterns: + - setup.cfg + - setup.py + register: found_python_files + when: install_package + +# Installing the directory with the constraints flag can hit into problems +# with conflicting values between constraints and current project. So look +# for a requirements.txt file so we can install it directly. +- name: Check to see if the project has a requirements.txt file + stat: + get_checksum: false + get_mime: false + get_md5: false + path: "{{ zuul_work_dir }}/requirements.txt" + register: requirements_file + +- name: Install requirements if they exist + pip: + chdir: "{{ zuul_work_dir }}" + virtualenv: "{{ zuul_work_virtualenv }}" + requirements: requirements.txt + extra_args: "{{ upper_constraints|default(omit) }}" + register: requirements_install + when: + - install_package + - found_python_files.matched + - requirements_file.stat.exists + failed_when: + - error_on_failure is defined + - error_on_failure + - requirements_install is failed + +# Build an sdist. This is needed for pbr projects that may expect +# the ChangeLog to have been generated. +- name: Make sdist to generate ChangeLog + command: + cmd: "{{ zuul_work_virtualenv }}/bin/python setup.py sdist" + chdir: "{{ zuul_work_dir }}" + when: + - install_package + - found_python_files.matched + register: sdist_results + failed_when: + - error_on_failure is defined + - error_on_failure + - sdist_results is failed + +# Try installing current repo in case it needs to be available for +# example for version number calculation. Ignore any failures here. +- name: Install the project if it is a Python project + pip: + chdir: "{{ zuul_work_dir }}" + virtualenv: "{{ zuul_work_virtualenv }}" + name: . + extra_args: --no-deps + when: + - install_package + - found_python_files.matched + register: install_package_results + failed_when: + - error_on_failure is defined + - error_on_failure + - install_package_results is failed diff --git a/roles/install-if-python/README.rst b/roles/install-if-python/README.rst index 8b9fc5b96..93db1ffe4 100644 --- a/roles/install-if-python/README.rst +++ b/roles/install-if-python/README.rst @@ -1,30 +1 @@ -Install the contents of a directory if they contain a python project. - -Installs into a virtualenv. - -**Role Variables** - -.. zuul:rolevar:: install_package - :default: true - - Flag indicating whether or not the software in the ``zuul_work_dir`` should - be installed. - -.. zuul:rolevar:: error_on_failure - - Flag that indicates installation errors should result in failure. Failures - in installing the target directory are ignored by default. - -.. zuul:rolevar:: constraints_file - - Optional path to a pip constraints file to use when installing. - -.. zuul:rolevar:: zuul_work_virtualenv - :default: ~/.venv - - Virtualenv location in which to install things. - -.. zuul:rolevar:: zuul_work_dir - :default: {{ zuul.project.src_dir }} - - Directory to operate in. +.. warning:: Deprecated, use ensure-if-python instead. diff --git a/roles/install-if-python/tasks/main.yaml b/roles/install-if-python/tasks/main.yaml index 9719d8aad..41252f2f2 100644 --- a/roles/install-if-python/tasks/main.yaml +++ b/roles/install-if-python/tasks/main.yaml @@ -1,74 +1,3 @@ -# TODO(mordred) rework tox-siblings so it can be used here - probably by -# making it take a parameter as to what path to python/pip to use. - -- name: Find Constraints File +- name: Include ensure-if-python. include_role: - name: find-constraints - -- name: Check to see if the project is a python project - find: - paths: "{{ zuul_work_dir }}" - patterns: - - setup.cfg - - setup.py - register: found_python_files - when: install_package - -# Installing the directory with the constraints flag can hit into problems -# with conflicting values between constraints and current project. So look -# for a requirements.txt file so we can install it directly. -- name: Check to see if the project has a requirements.txt file - stat: - get_checksum: false - get_mime: false - get_md5: false - path: "{{ zuul_work_dir }}/requirements.txt" - register: requirements_file - -- name: Install requirements if they exist - pip: - chdir: "{{ zuul_work_dir }}" - virtualenv: "{{ zuul_work_virtualenv }}" - requirements: requirements.txt - extra_args: "{{ upper_constraints|default(omit) }}" - register: requirements_install - when: - - install_package - - found_python_files.matched - - requirements_file.stat.exists - failed_when: - - error_on_failure is defined - - error_on_failure - - requirements_install is failed - -# Build an sdist. This is needed for pbr projects that may expect -# the ChangeLog to have been generated. -- name: Make sdist to generate ChangeLog - command: - cmd: "{{ zuul_work_virtualenv }}/bin/python setup.py sdist" - chdir: "{{ zuul_work_dir }}" - when: - - install_package - - found_python_files.matched - register: sdist_results - failed_when: - - error_on_failure is defined - - error_on_failure - - sdist_results is failed - -# Try installing current repo in case it needs to be available for -# example for version number calculation. Ignore any failures here. -- name: Install the project if it is a Python project - pip: - chdir: "{{ zuul_work_dir }}" - virtualenv: "{{ zuul_work_virtualenv }}" - name: . - extra_args: --no-deps - when: - - install_package - - found_python_files.matched - register: install_package_results - failed_when: - - error_on_failure is defined - - error_on_failure - - install_package_results is failed + name: ensure-if-python