Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 authored Dec 29, 2021
2 parents d70e561 + 18240a0 commit 360275f
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 33 deletions.
2 changes: 1 addition & 1 deletion constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def yamlize(data, directory, content_filter):
except ImportError as ex:
raise UnableToParseMissingJinja2(original=ex)
data = render_jinja(data, directory, content_filter)
return yaml.load(data)
return yaml.load(data, Loader=yaml.SafeLoader)


def parse(path, platform):
Expand Down
31 changes: 10 additions & 21 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# MD5: __MD5__

#if osx
unset DYLD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
#else
export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
unset LD_LIBRARY_PATH
Expand Down Expand Up @@ -43,12 +43,8 @@ Installs __NAME__ __VERSION__
#if batch_mode
-i run install in interactive mode
#else
#if has_license
-b run install in batch mode (without manual intervention),
it is expected the license terms are agreed upon
#else
-b run install in batch mode (without manual intervention)
#endif
it is expected the license terms (if any) are agreed upon
#endif
-f no error if install prefix already exists
-h print this help message and exit
Expand Down Expand Up @@ -435,12 +431,12 @@ printf "Unpacking payload ...\n"
extract_range $boundary1 $boundary2 | \
"$CONDA_EXEC" constructor --extract-tarball --prefix "$PREFIX"

"$CONDA_EXEC" constructor --prefix "$PREFIX" --extract-conda-pkgs || exit 1

PRECONDA="$PREFIX/preconda.tar.bz2"
"$CONDA_EXEC" constructor --prefix "$PREFIX" --extract-tarball < "$PRECONDA" || exit 1
rm -f "$PRECONDA"

"$CONDA_EXEC" constructor --prefix "$PREFIX" --extract-conda-pkgs || exit 1

#The templating doesn't support nested if statements
#if has_pre_install
if [ "$SKIP_SCRIPTS" = "1" ]; then
Expand Down Expand Up @@ -543,21 +539,14 @@ if [ "$PYTHONPATH" != "" ]; then
fi

if [ "$BATCH" = "0" ]; then
#if has_conda
# Interactive mode.
#if osx
BASH_RC="$HOME"/.bash_profile
#if initialize_by_default is True
DEFAULT=yes
#else
BASH_RC="$HOME"/.bashrc
DEFAULT=no
#endif
#if initialize_by_default is True
DEFAULT=yes
#endif
#if initialize_by_default is False
#else
DEFAULT=no
#endif
#endif

#if has_conda
# Interactive mode.

printf "Do you wish the installer to initialize __NAME__\\n"
printf "by running conda init? [yes|no]\\n"
Expand Down
17 changes: 17 additions & 0 deletions constructor/nsis/OptionsDialog.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ Var mui_AnaCustomOptions.AddToPath
Var mui_AnaCustomOptions.RegisterSystemPython
Var mui_AnaCustomOptions.PostInstall
Var mui_AnaCustomOptions.ClearPkgCache
Var mui_AnaCustomOptions.CreateShortcuts

# These are the checkbox states, to be used by the installer
Var Ana_AddToPath_State
Var Ana_RegisterSystemPython_State
Var Ana_PostInstall_State
Var Ana_ClearPkgCache_State
Var Ana_CreateShortcuts_State

Var Ana_AddToPath_Label
Var Ana_RegisterSystemPython_Label
Expand All @@ -37,6 +39,9 @@ Function mui_AnaCustomOptions_InitDefaults
${Else}
StrCpy $Ana_RegisterSystemPython_State ${BST_CHECKED}
${EndIf}
${If} $Ana_CreateShortcuts_State == ""
StrCpy $Ana_CreateShortcuts_State ${BST_CHECKED}
${EndIf}
${EndIf}
FunctionEnd

Expand All @@ -60,6 +65,12 @@ Function mui_AnaCustomOptions_Show
"Advanced Installation Options" \
"Customize how ${NAME} integrates with Windows"


${NSD_CreateCheckbox} 0 0u 100% 11u "Create start menu shortcuts (supported packages only)."
Pop $mui_AnaCustomOptions.CreateShortcuts
${NSD_SetState} $mui_AnaCustomOptions.CreateShortcuts $Ana_CreateShortcuts_State
${NSD_OnClick} $mui_AnaCustomOptions.CreateShortcuts CreateShortcuts_OnClick

${If} $InstMode = ${JUST_ME}
StrCpy $1 "my"
${Else}
Expand Down Expand Up @@ -188,3 +199,9 @@ Function ClearPkgCache_OnClick
${EndIf}
ShowWindow $Ana_ClearPkgCache_Label ${SW_SHOW}
FunctionEnd

Function CreateShortcuts_OnClick
Pop $0
${NSD_GetState} $0 $Ana_CreateShortcuts_State

FunctionEnd
16 changes: 11 additions & 5 deletions constructor/nsis/_nsis.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,30 @@ def get(self, name):
return None


def mk_menus(remove=False, prefix=None, pkg_names=[]):
def mk_menus(remove=False, prefix=None, pkg_names=None, root_prefix=None):
try:
import menuinst
except (ImportError, OSError):
return
if prefix is None:
prefix = sys.prefix
if root_prefix is None:
root_prefix = sys.prefix
menu_dir = join(prefix, 'Menu')
if not os.path.isdir(menu_dir):
return
for fn in os.listdir(menu_dir):
if not fn.endswith('.json'):
continue
if pkg_names and fn[:-5] not in pkg_names:
if pkg_names is not None and len(pkg_names) > 0 and fn[:-5] not in pkg_names:
# skip when not in the list of menus to create
# when installing, the pkg_names list is specified, otherwise not
# and we don't skip to try to remove shortcuts
continue
shortcut = join(menu_dir, fn)
try:
menuinst.install(shortcut, remove, prefix=prefix)
menuinst.install(shortcut, remove, prefix=prefix,
root_prefix=root_prefix)
except Exception as e:
out("Failed to process %s...\n" % shortcut)
err("Error: %s\n" % str(e))
Expand Down Expand Up @@ -150,7 +156,7 @@ def get_conda_envs_from_python_api():
get_conda_envs = get_conda_envs_from_python_api


def rm_menus(prefix=None):
def rm_menus(prefix=None, root_prefix=None):
try:
import menuinst
from conda.base.context import context
Expand All @@ -175,7 +181,7 @@ def rm_menus(prefix=None):
# `envs_dirs` to avoid picking up environment from other
# distributions. Not perfect but better than no checking
if envs_dir in env:
mk_menus(remove=True, prefix=env)
mk_menus(remove=True, prefix=env, root_prefix=root_prefix)


def run_post_install():
Expand Down
31 changes: 25 additions & 6 deletions constructor/nsis/main.nsi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Unicode "true"
!define DEFAULT_PREFIX_DOMAIN_USER __DEFAULT_PREFIX_DOMAIN_USER__
!define DEFAULT_PREFIX_ALL_USERS __DEFAULT_PREFIX_ALL_USERS__
!define POST_INSTALL_DESC __POST_INSTALL_DESC__
!define MENU_PKGS "@MENU_PKGS@"
!define PRODUCT_NAME "${NAME} ${VERSION} (${ARCH})"
!define UNINSTALL_NAME "@UNINSTALL_NAME@"
!define UNINSTREG "SOFTWARE\Microsoft\Windows\CurrentVersion\
Expand All @@ -53,6 +54,7 @@ var /global ARGV_KeepPkgCache
var /global ARGV_RegisterPython
var /global ARGV_NoRegistry
var /global ARGV_NoScripts
var /global ARGV_NoShortcuts
var /global ARGV_CheckPathLength

var /global IsDomainUser
Expand Down Expand Up @@ -187,6 +189,7 @@ FunctionEnd
/RegisterPython=[0|1] [default: AllUsers: 1, JustMe: 0]$\n$\n\
/NoRegistry=[0|1] [default: AllUsers: 0, JustMe: 0]$\n$\n\
/NoScripts=[0|1] [default: 0]$\n$\n\
/NoShortcuts=[0|1] [default: 0]$\n$\n\
/CheckPathLength=[0|1] [default: 1]$\n$\n\
Examples:$\n\
Install for all users, but don't add to PATH env var:$\n\
Expand Down Expand Up @@ -250,6 +253,16 @@ FunctionEnd
${EndIf}
${EndIf}

ClearErrors
${GetOptions} $ARGV "/NoShortcuts=" $ARGV_NoShortcuts
${IfNot} ${Errors}
${If} $ARGV_NoShortcuts = "1"
StrCpy $Ana_CreateShortcuts_State ${BST_UNCHECKED}
${ElseIf} $ARGV_NoShortcuts = "0"
StrCpy $Ana_CreateShortcuts_State ${BST_CHECKED}
${EndIf}
${EndIf}

ClearErrors
${GetOptions} $ARGV "/CheckPathLength=" $ARGV_CheckPathLength
${IfNot} ${Errors}
Expand Down Expand Up @@ -881,7 +894,9 @@ Section "Install"

SetDetailsPrint TextOnly
DetailPrint "Setting up the base environment ..."
nsExec::ExecToLog '"$INSTDIR\_conda.exe" install --offline -yp "$INSTDIR" --file "$INSTDIR\pkgs\env.txt"'
# Need to use `--no-shortcuts` because the shortcuts are created in the following steps. The reason is that `conda install`
# doesn't support `menu_packages` entry of `construct.yaml` and will therefore create possible shorcuts
nsExec::ExecToLog '"$INSTDIR\_conda.exe" install --offline -yp "$INSTDIR" --file "$INSTDIR\pkgs\env.txt" --no-shortcuts'
Pop $0
SetDetailsPrint both

Expand All @@ -898,10 +913,12 @@ Section "Install"
SetOutPath "$INSTDIR\conda-meta"
File __CONDA_HISTORY__

DetailPrint "Creating @NAME@ menus..."
push '"$INSTDIR\_conda.exe" constructor --prefix "$INSTDIR" --make-menus @MENU_PKGS@'
push 'Failed to create menus'
call AbortRetryNSExecWait
${If} $Ana_CreateShortcuts_State = ${BST_CHECKED}
DetailPrint "Creating @NAME@ menus..."
push '"$INSTDIR\_conda.exe" constructor --prefix "$INSTDIR" --make-menus @MENU_PKGS@'
push 'Failed to create menus'
call AbortRetryNSExecWait
${EndIf}

push '"$INSTDIR\pythonw.exe" -E -s "$INSTDIR\Lib\_nsis.py" mkdirs'
push 'Failed to initialize Anaconda directories'
Expand Down Expand Up @@ -991,8 +1008,10 @@ Section "Uninstall"
!insertmacro ExecWaitLibNsisCmd "pre_uninstall"
!insertmacro ExecWaitLibNsisCmd "rmpath"
!insertmacro ExecWaitLibNsisCmd "rmreg"
!insertmacro ExecWaitLibNsisCmd 'del "$INSTDIR"'
DetailPrint "Removing files and folders..."
nsExec::Exec 'cmd.exe /k RMDIR /Q/S "$INSTDIR"'

# In case the last command fails, run the slow method to remove leftover
RMDir /r /REBOOTOK "$INSTDIR"

DeleteRegKey SHCTX "${UNINSTREG}"
Expand Down
41 changes: 41 additions & 0 deletions tests/test_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from constructor.shar import read_header_template, preprocess
import pytest


@pytest.mark.parametrize('osx', [False, True])
@pytest.mark.parametrize('direct_execute_post_install', [False, True])
@pytest.mark.parametrize('direct_execute_pre_install', [False, True])
@pytest.mark.parametrize('batch_mode', [False, True])
@pytest.mark.parametrize('keep_pkgs', [False, True])
@pytest.mark.parametrize('has_conda', [False, True])
@pytest.mark.parametrize('has_license', [False, True])
@pytest.mark.parametrize('initialize_by_default', [False, True])
@pytest.mark.parametrize('has_post_install', [False, True])
@pytest.mark.parametrize('has_pre_install', [False, True])
@pytest.mark.parametrize('arch', ['x86', 'x86_64', ' ppc64le', 's390x', 'aarch64'])
def test_linux_template_processing(
osx, arch, has_pre_install, has_post_install,
initialize_by_default, has_license, has_conda, keep_pkgs, batch_mode,
direct_execute_pre_install, direct_execute_post_install):
template = read_header_template()
processed = preprocess(template, {
'has_license': has_license,
'osx': osx,
'batch_mode': batch_mode,
'keep_pkgs': keep_pkgs,
'has_conda': has_conda,
'x86': arch == 'x86',
'x86_64': arch == 'x86_64',
'ppc64le': arch == 'ppc64le',
's390x': arch == 's390x',
'aarch64': arch == 'aarch64',
'linux': not osx,
'has_pre_install': has_pre_install,
'direct_execute_pre_install': direct_execute_pre_install,
'has_post_install': has_post_install,
'direct_execute_post_install': direct_execute_post_install,
'initialize_by_default': initialize_by_default,
})
assert '#if' not in processed
assert '#else' not in processed
assert '#endif' not in processed

0 comments on commit 360275f

Please sign in to comment.