Skip to content

Commit

Permalink
Added support for extra_env_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Sep 13, 2023
1 parent 8e65a5d commit afbb55a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ is compulsory and the option to disable it will not be offered.

This option has no effect on `SH` installers.


### `extra_env_variables`

_required:_ no<br/>
_type:_ list<br/>

List of additional environment variables to be made available to the
pre_install and post_install scripts, in the form of VAR=VALUE
pairs. These environment variables are in addition to those in the
`post_install` section above and take precedence in the case of name
collisions. Unix only.

### `pre_uninstall`

_required:_ no<br/>
Expand Down
7 changes: 7 additions & 0 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@
('uninstall_name', False, str, '''
Application name in the Windows "Programs and Features" control panel.
Defaults to `${NAME} ${VERSION} (Python ${PYVERSION} ${ARCH})`.
'''),
('extra_env_variables', False, list, '''
List of additional environment variables to be made available to the
pre_install and post_install scripts, in the form of VAR=VALUE
pairs. These environment variables are in addition to those in the
`post_install` section above and take precedence in the case of name
collisions. Unix only.
'''),

('pre_install', False, str, '''
Expand Down
2 changes: 2 additions & 0 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fi

# Export variables to make installer metadata available to pre/post install scripts
# NOTE: If more vars are added, make sure to update the examples/scripts tests too

_EXTRA_ENV_VARIABLES_='' # Templated extra environment variable(s)
export INSTALLER_NAME='__NAME__'
export INSTALLER_VER='__VERSION__'
export INSTALLER_PLAT='__PLAT__'
Expand Down
2 changes: 2 additions & 0 deletions constructor/shar.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ def get_header(conda_exec, tarball, info):

data = read_header_template()
data = preprocess(data, ppd)
custom_variables = info.pop('extra_env_variables', [])
data = fill_template(data, replace)

data = data.replace("_EXTRA_ENV_VARIABLES_=''", '\n'.join([f'export {var}' for var in custom_variables]))
return data


Expand Down
5 changes: 5 additions & 0 deletions examples/scripts/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ channels:
- http://repo.anaconda.com/pkgs/main/
specs:
- python

extra_env_variables:
- CUSTOM_VARIABLE_1=CUSTOM1
- CUSTOM_VARIABLE_2=CUSTOM2

pre_install: pre_install.sh # [unix]
pre_install: pre_install.bat # [win]
pre_install_desc: "Adding this description makes the script selectable in the UI"
Expand Down
5 changes: 5 additions & 0 deletions examples/scripts/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ echo "INSTALLER_NAME=${INSTALLER_NAME}"
echo "INSTALLER_VER=${INSTALLER_VER}"
echo "INSTALLER_PLAT=${INSTALLER_PLAT}"
echo "INSTALLER_TYPE=${INSTALLER_TYPE}"
echo "CUSTOM_VARIABLE_1=${CUSTOM_VARIABLE_1}"
echo "CUSTOM_VARIABLE_2=${CUSTOM_VARIABLE_2}"
echo "PREFIX=${PREFIX}"

test "${INSTALLER_NAME}" = "Scripts"
test "${INSTALLER_VER}" = "X"
test "${CUSTOM_VARIABLE_1}" = "CUSTOM1"
test "${CUSTOM_VARIABLE_2}" = "CUSTOM2"

if [[ $(uname -s) == Linux ]]; then
if [[ ${INSTALLER_PLAT} != linux-* ]]; then
exit 1
Expand Down
5 changes: 5 additions & 0 deletions examples/scripts/pre_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ echo "INSTALLER_NAME=${INSTALLER_NAME}"
echo "INSTALLER_VER=${INSTALLER_VER}"
echo "INSTALLER_PLAT=${INSTALLER_PLAT}"
echo "INSTALLER_TYPE=${INSTALLER_TYPE}"
echo "CUSTOM_VARIABLE_1=${CUSTOM_VARIABLE_1}"
echo "CUSTOM_VARIABLE_2=${CUSTOM_VARIABLE_2}"
echo "PREFIX=${PREFIX}"

test "${INSTALLER_NAME}" = "Scripts"
test "${INSTALLER_VER}" = "X"
test "${CUSTOM_VARIABLE_1}" = "CUSTOM1"
test "${CUSTOM_VARIABLE_2}" = "CUSTOM2"

if [[ $(uname -s) == Linux ]]; then
if [[ ${INSTALLER_PLAT} != linux-* ]]; then
exit 1
Expand Down

0 comments on commit afbb55a

Please sign in to comment.