Skip to content

Commit

Permalink
Added support for extra_env_variables on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Sep 18, 2023
1 parent 509c470 commit 0707af8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions constructor/nsis/main.nsi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ Section "Install"
File /nonfatal /r __INDEX_CACHE__
File /r __REPODATA_RECORD__

@EXTRA_ENV_VARIABLES@
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_SAFETY_CHECKS", "disabled").r0'
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_EXTRA_SAFETY_CHECKS", "no").r0'
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_PKGS_DIRS", "$INSTDIR\pkgs")".r0'
Expand Down
18 changes: 18 additions & 0 deletions constructor/winexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ def insert_tempfiles_commands(paths: os.PathLike) -> List[str]:
lines.append(f"File {path}")
return lines

def setup_extra_env_variables(info) -> List[str]:
"""Helper function to insert extra environment variables into nsis template.
Args:
info: Dictionary of information parsed from construct.yaml
Returns:
List[str]: Commands to be inserted into nsi template
"""
lines = []
for variable in info.get('extra_env_variables',[]):
split = variable.split('=')
if len(split)==2:
(name, val) = split
lines.append(f"""System::Call 'kernel32::SetEnvironmentVariable(t,t)i("{name}", "{val}").r0'""")

return lines

def custom_nsi_insert_from_file(filepath: os.PathLike) -> str:
"""Insert NSI script commands from file.
Expand Down Expand Up @@ -332,6 +349,7 @@ def make_nsi(info, dir_path, extra_files=None, temp_extra_files=None):
'${NAME} ${VERSION} (Python ${PYVERSION} ${ARCH})'
)),
('@EXTRA_FILES@', '\n '.join(extra_files_commands(extra_files, dir_path))),
('@EXTRA_ENV_VARIABLES@', '\n '.join(setup_extra_env_variables(info))),
(
'@CUSTOM_WELCOME_FILE@',
custom_nsi_insert_from_file(info.get('welcome_file', ''))
Expand Down
2 changes: 2 additions & 0 deletions examples/scripts/post_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ if not "%INSTALLER_VER%" == "X" exit 1
if not "%INSTALLER_PLAT%" == "win-64" exit 1
if not "%INSTALLER_TYPE%" == "EXE" exit 1
if "%PREFIX%" == "" exit 1
if not "%CUSTOM_VARIABLE_1%" == "CUSTOM1" exit 1
if not "%CUSTOM_VARIABLE_2%" == "CUSTOM2" exit 1
if not exist "%PREFIX%\pre_install_sentinel.txt" exit 1
2 changes: 2 additions & 0 deletions examples/scripts/pre_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ if not "%INSTALLER_VER%" == "X" exit 1
if not "%INSTALLER_PLAT%" == "win-64" exit 1
if not "%INSTALLER_TYPE%" == "EXE" exit 1
if "%PREFIX%" == "" exit 1
if not "%CUSTOM_VARIABLE_1%" == "CUSTOM1" exit 1
if not "%CUSTOM_VARIABLE_2%" == "CUSTOM2" exit 1
echo Added by pre-install script > "%PREFIX%\pre_install_sentinel.txt"

0 comments on commit 0707af8

Please sign in to comment.