Drop empty elements from constraint/requirement files

We should filter out empty elements from lists that are provided as
input to the role, to ensure idempotence of build constraints and
requirements file as a result.

Additionally to that we should ensure to control jinja whitespaces
not to add extra new lines to the end of files.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/872896
Change-Id: Ide47712f775c91d90b749bc8e4d8f87c5bd658f2
Closes-Bug: #2004546
This commit is contained in:
Dmitriy Rabotyagov 2023-02-08 21:48:38 +01:00
parent 7fd75008cf
commit 2a25337b98
2 changed files with 16 additions and 16 deletions

View File

@ -91,8 +91,8 @@
- name: Build requirements file for the venv
copy:
dest: "{{ venv_install_destination_path }}/requirements.txt"
content: |
{% for item in _venv_install_pip_packages %}
content: |-
{% for item in _venv_install_pip_packages | select() %}
{{ item }}
{% endfor %}
register: _requirement_file
@ -100,8 +100,8 @@
- name: Build global constraints file for the venv
copy:
dest: "{{ venv_install_destination_path }}/global-constraints.txt"
content: |
{% for item in venv_build_global_constraints %}
content: |-
{% for item in venv_build_global_constraints | select() %}
{{ item }}
{% endfor %}
register: _global_constraint_file
@ -109,16 +109,16 @@
- name: Build constraints file for the venv
copy:
dest: "{{ venv_install_destination_path }}/constraints.txt"
content: |
{% if (venv_wheel_build_enable | bool) and
content: |-
{%- if (venv_wheel_build_enable | bool) and
(_constraints_file_slurp is defined) and
(_constraints_file_slurp.content is defined) %}
{{ _constraints_file_slurp.content | b64decode }}
{% else %}
{% for item in venv_build_constraints %}
{%- else %}
{% for item in venv_build_constraints | select() %}
{{ item }}
{% endfor %}
{% endif %}
{%- endif %}
register: _constraint_file
- name: Upgrade pip/setuptools/wheel to the versions we want

View File

@ -69,8 +69,8 @@
- name: Build requirements file for the venv
copy:
dest: "{{ _venv_build_requirements_prefix }}-requirements.txt"
content: |
{% for item in _venv_pip_packages %}
content: |-
{% for item in _venv_pip_packages | select() %}
{{ item }}
{% endfor %}
owner: "{{ venv_build_host_user_name | default(omit) }}"
@ -80,8 +80,8 @@
- name: Build global constraints file for the venv
copy:
dest: "{{ _venv_build_requirements_prefix }}-global-constraints.txt"
content: |
{% for item in venv_build_global_constraints %}
content: |-
{% for item in venv_build_global_constraints | select() %}
{{ item }}
{% endfor %}
owner: "{{ venv_build_host_user_name | default(omit) }}"
@ -91,8 +91,8 @@
- name: Build constraints file for the venv
copy:
dest: "{{ _venv_build_requirements_prefix }}-source-constraints.txt"
content: |
{% for item in venv_build_constraints %}
content: |-
{% for item in venv_build_constraints | select() %}
{{ item }}
{% endfor %}
owner: "{{ venv_build_host_user_name | default(omit) }}"
@ -171,7 +171,7 @@
- name: Build constraints file for installation purposes
copy:
content: |
content: |-
{% for file_data in _built_wheels['files'] %}
{% set file_name = file_data['path'] | basename %}
{{ file_name.split('-')[0] | lower }}=={{ (file_name.split('-')[1].split('_')) | join('.post') | lower }}