From 7fd75008cf483027be72e3536da5cb61463d6eab Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Mon, 23 Jan 2023 14:17:47 +0100 Subject: [PATCH] Allow to set ENV vars for wheels build and venv install It's not always enough to provide extra arguments for pip installation. For usescases, like isolated installations, and some specific packages that still utilize deprecated setuptools.installer instead of PEP 517 installer, you might find impossible to provide some easyisntall options without having a configuration file that should be created by deployer as pre-step. However, these options might be covered with ENV variables. Change-Id: I9a060cbcdf9f5c54efd423a4b4fe32b418377f86 --- defaults/main.yml | 6 ++++++ .../notes/pip_build_install_env-464b66f471060442.yaml | 6 ++++++ tasks/python_venv_install.yml | 7 +++++-- tasks/python_venv_wheel_build.yml | 7 +++++-- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/pip_build_install_env-464b66f471060442.yaml diff --git a/defaults/main.yml b/defaults/main.yml index e06c94d..a91356b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -75,6 +75,9 @@ venv_build_global_constraints: [] # Arguments to pass to pip when building the wheels venv_pip_build_args: "" +# Environemnt to be set for building the wheels +venv_pip_build_env: {} + # Default arguments to pass to pip when installing into # the venv. venv_default_pip_install_args: >- @@ -86,6 +89,9 @@ venv_default_pip_install_args: >- # Arguments to pass to pip when installing into the venv venv_pip_install_args: "" +# Environemnt to be set for building the wheels +venv_pip_install_env: {} + # Some python packages have C bindings which tend to be very # particular about the version of their underlying shared libraries. # To ensure things run smoothly for stable releases, we opt to diff --git a/releasenotes/notes/pip_build_install_env-464b66f471060442.yaml b/releasenotes/notes/pip_build_install_env-464b66f471060442.yaml new file mode 100644 index 0000000..c555deb --- /dev/null +++ b/releasenotes/notes/pip_build_install_env-464b66f471060442.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Added variables ``venv_pip_build_env`` and ``venv_pip_install_env`` that + allows to set extra environment variables during wheels build or venv + installation. diff --git a/tasks/python_venv_install.yml b/tasks/python_venv_install.yml index 716acd3..5eb16b8 100644 --- a/tasks/python_venv_install.yml +++ b/tasks/python_venv_install.yml @@ -135,8 +135,10 @@ --log /var/log/python_venv_build.log {{ venv_default_pip_install_args }} {{ venv_pip_install_args }} - environment: - PIP_CONFIG_FILE: "{{ (venv_pip_upgrade_noconf | bool) | ternary('/dev/null', '') }}" + environment: "{{ venv_pip_install_env | combine(_pip_upgrade_noconf) }}" + vars: + _pip_upgrade_noconf: + PIP_CONFIG_FILE: "{{ (venv_pip_upgrade_noconf | bool) | ternary('/dev/null', '') }}" register: _update_virtualenv_packages until: _update_virtualenv_packages is success retries: 5 @@ -158,6 +160,7 @@ --log /var/log/python_venv_build.log {{ venv_default_pip_install_args }} {{ venv_pip_install_args }} + environment: "{{ venv_pip_install_env }}" when: (_requirement_file is changed) or (_global_constraint_file is changed) or (_constraint_file is changed) register: _install_venv_pip_packages until: _install_venv_pip_packages is success diff --git a/tasks/python_venv_wheel_build.yml b/tasks/python_venv_wheel_build.yml index f17e780..3ed5415 100644 --- a/tasks/python_venv_wheel_build.yml +++ b/tasks/python_venv_wheel_build.yml @@ -113,8 +113,10 @@ --find-links {{ venv_build_host_wheel_path }}/ --log /var/log/python_venv_build.log {{ venv_pip_build_args }} - environment: - PIP_CONFIG_FILE: "{{ (venv_pip_upgrade_noconf | bool) | ternary('/dev/null', '') }}" + environment: "{{ venv_pip_build_env | combine(_pip_upgrade_noconf) }}" + vars: + _pip_upgrade_noconf: + PIP_CONFIG_FILE: "{{ (venv_pip_upgrade_noconf | bool) | ternary('/dev/null', '') }}" register: _update_virtualenv_packages until: _update_virtualenv_packages is success retries: 5 @@ -138,6 +140,7 @@ --find-links {{ venv_build_host_wheel_path }}/ --log /var/log/python_wheel_build.log {{ venv_pip_build_args }} + environment: "{{ venv_pip_build_env }}" register: _build_python_wheels until: _build_python_wheels is success retries: 5