openstack-ansible-repo_build/templates/requirements.txt.j2

106 lines
6.1 KiB
Django/Jinja

# This is a unique, sorted list of requirements compiled by the repo
# build process. The requirements are compiled from all the roles
# using their *_pip_packages lists, the global-requirements-pins,
# and the git sources provided.
# Where a package is found to be provided from a git source, the
# designated git repository SHA is added as a comment.
{# #}
{# To make it easier to add the comment for each git sourced package #}
{# when compiling the all_requirements list, we need to put together #}
{# a map of the package names to the version based on the git data #}
{# provided by the py_pkgs lookup. #}
{# #}
{% set git_packages = {} %}
{% for clone_item in local_packages.results.0.item.remote_package_parts %}
{% if 'ignorerequirements=true' not in clone_item['original'] %}
{% set name_normalized = clone_item['name'] | replace('-', '_') | lower %}
{% set _ = git_packages.update({name_normalized: clone_item['version']}) %}
{% endif %}
{% endfor %}
{# #}
{# The list provided by the py_pkgs lookup is a raw set which needs #}
{# some normalization. We also want to add the SHA/version as a #}
{# comment to anything provided from a git source to make it simple #}
{# for the git cloning and wheel building process to be idempotent. #}
{# #}
{% set all_requirements={} %}
{% for requirement_raw in local_packages.results.0.item.packages %}
{% set name = requirement_raw | regex_replace('(\[|>=|<=|>|<|==|~=|!=).*$','') %}
{% set data = requirement_raw | regex_replace(name,'') %}
{% set name_normalized = name | replace('-', '_') | lower %}
{% if name_normalized in git_packages %}
{% set requirement_normalized = name_normalized ~ data ~ ' # ' ~ git_packages[name_normalized] %}
{% else %}
{% set requirement_normalized = name_normalized ~ data %}
{% endif %}
{% set _ = all_requirements.update({name_normalized: requirement_normalized}) %}
{% endfor %}
{# #}
{# Now we have a complete, normalised and commented reference set #}
{# to work with. Now, for a non-selective wheel build, we simply #}
{# output the resulting list. #}
{# #}
{% if not repo_build_wheel_selective | bool %}
{% for requirement_name, requirement in all_requirements.items() | sort %}
{{ requirement }}
{% endfor %}
{% else %}
{# #}
{# For a selective wheel build, we now need to build a set of the #}
{# packages we actually want to build. This list of packages must #}
{# be a unique set (or pip wheel will fail). We will use a #}
{# key:value mechanism to compile the set. #}
{# #}
{% set selected_requirements={} %}
{# #}
{# These are files which are in the root repo requirements and must #}
{# always be built. #}
{# #}
{% for requirement_raw in local_packages.results.0.item.role_requirement_files.default.txt_file_packages %}
{% set name = requirement_raw | regex_replace('(\[|>=|<=|>|<|==|~=|!=).*$','') %}
{% set name_normalized = name | replace('-', '_') | lower %}
{% set requirement_normalized = all_requirements[name_normalized] %}
{% set _ = selected_requirements.update({name_normalized: requirement_normalized}) %}
{% endfor %}
{# #}
{# These are files which are in the roles. We only select them if #}
{# their project_groups are populated. #}
{# #}
{% for role_name, role_data in local_packages.results.0.item.role_requirements.items() %}
{% set _host_group = role_data['project_group'] %}
{% if ((groups[_host_group] is defined) and (groups[_host_group] | length > 0)) %}
{% set _build_wheel = True %}
{% else %}
{% set _build_wheel = False %}
{% endif %}
{% if (_build_wheel | bool) %}
{% for requirement_key, requirement_data in role_data.items() %}
{# #}
{# We only want to iterate through the '_pip_packages' lists #}
{# as there may be other data structures in the role_data. #}
{# We must also make sure we're skipping the properietary #}
{# packages as they're not available for the repo server to #}
{# download/build. #}
{# #}
{% if '_pip_packages' in requirement_key and 'proprietary' not in requirement_key %}
{% for requirement_raw in requirement_data %}
{% set name = requirement_raw | regex_replace('(\[|>=|<=|>|<|==|~=|!=).*$','') %}
{% set name_normalized = name | replace('-', '_') | lower %}
{% if name_normalized in all_requirements %}
{% set requirement_normalized = all_requirements[name_normalized] %}
{% set _ = selected_requirements.update({name_normalized: requirement_normalized}) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{# #}
{# Now that we have a complete set of requirements, we output them. #}
{# #}
{% for requirement_name, requirement in selected_requirements.items() | sort %}
{{ requirement }}
{% endfor %}
{% endif %}