Skip to content

Commit

Permalink
simplify shortcut flags generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Mar 25, 2022
1 parent f882d79 commit 9fc8f95
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
6 changes: 0 additions & 6 deletions constructor/nsis/main.nsi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -911,12 +911,6 @@ Section "Install"
SetOutPath "$INSTDIR\conda-meta"
File __CONDA_HISTORY__

# Not needed anymore thanks to the new --shortcuts-only arg, set above in @SHORTCUTS@
# DetailPrint "Creating @NAME@ menus..."
# push '"$INSTDIR\_conda.exe" constructor --prefix "$INSTDIR" --make-menus @MENU_PKGS@'
# push 'Failed to create menus'
# call AbortRetryNSExecWait

push '"$INSTDIR\pythonw.exe" -E -s "$INSTDIR\Lib\_nsis.py" mkdirs'
push 'Failed to initialize Anaconda directories'
call AbortRetryNSExecWait
Expand Down
11 changes: 2 additions & 9 deletions constructor/osxpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import xml.etree.ElementTree as ET

import constructor.preconda as preconda
from constructor.utils import add_condarc, get_final_channels, rm_rf
from constructor.utils import add_condarc, get_final_channels, rm_rf, shortcuts_flags


OSX_DIR = join(dirname(__file__), "osx")
Expand Down Expand Up @@ -143,14 +143,7 @@ def move_script(src, dst, info):
data = data.replace('__NAME__', info['name'])
data = data.replace('__CHANNELS__', ','.join(get_final_channels(info)))
data = data.replace('__WRITE_CONDARC__', '\n'.join(add_condarc(info)))

if info.get("menu_packages"):
data = data.replace(
'__SHORTCUTS__',
" ".join([f"--shortcuts-only={pkg.strip()}" for pkg in info['menu_packages']])
)
else:
data = data.replace('__SHORTCUTS__', "")
data = data.replace('__SHORTCUTS__', shortcuts_flags(info))

with open(dst, 'w') as fo:
fo.write(data)
Expand Down
8 changes: 2 additions & 6 deletions constructor/shar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .construct import ns_platform
from .preconda import files as preconda_files, write_files as preconda_write_files
from .utils import add_condarc, filename_dist, fill_template, hash_files, preprocess, \
read_ascii_only, get_final_channels
read_ascii_only, get_final_channels, shortcuts_flags

THIS_DIR = dirname(__file__)

Expand Down Expand Up @@ -72,15 +72,11 @@ def get_header(conda_exec, tarball, info):
'INSTALL_COMMANDS': '\n'.join(install_lines),
'CHANNELS': ','.join(get_final_channels(info)),
'pycache': '__pycache__',
'SHORTCUTS': shortcuts_flags(info),
}
if has_license:
replace['LICENSE'] = read_ascii_only(info['license_file'])

if info.get("menu_packages"):
replace['SHORTCUTS'] = " ".join([f"--shortcuts-only={pkg.strip()}" for pkg in info['menu_packages']])
else:
replace['SHORTCUTS'] = ""

data = read_header_template()
data = preprocess(data, ppd)
data = fill_template(data, replace)
Expand Down
15 changes: 15 additions & 0 deletions constructor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,18 @@ def yield_lines(path):
if not line or line.startswith('#'):
continue
yield line


def shortcuts_flags(info):
menu_packages = info.get("menu_packages")
if menu_packages is None:
# not set: we create all shortcuts (default behaviour)
shortcuts = ""
elif menu_packages:
# set and populated: we only create shortcuts for some
shortcuts = ' '.join([f'--shortcuts-only="{pkg}"' for pkg in menu_packages])
else:
# set but empty: disable all shortcuts
shortcuts = "--no-shortcuts"

return shortcuts
15 changes: 2 additions & 13 deletions constructor/winexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .imaging import write_images
from .preconda import write_files as preconda_write_files
from .utils import (filename_dist, fill_template, make_VIProductVersion,
preprocess, add_condarc, get_final_channels)
preprocess, add_condarc, get_final_channels, shortcuts_flags)

THIS_DIR = abspath(dirname(__file__))
NSIS_DIR = join(THIS_DIR, 'nsis')
Expand Down Expand Up @@ -115,25 +115,14 @@ def make_nsi(info, dir_path):
approx_pkgs_size_kb = int(
math.ceil(info.get('_approx_pkgs_size', 0) / 1000))

menu_packages = info.get("menu_packages")
if menu_packages is None:
# not set: we create all shortcuts (default behaviour)
shortcuts = ""
elif menu_packages:
# set and populated: we only create shortcuts for some
shortcuts = ' '.join([f'--shortcuts-only="{pkg}"' for pkg in menu_packages])
else:
# set but empty: disable all shortcuts
shortcuts = "--no-shortcuts"

# these are unescaped (and unquoted)
for key, value in [
('@NAME@', name),
('@NSIS_DIR@', NSIS_DIR),
('@BITS@', str(arch)),
('@PKG_COMMANDS@', '\n '.join(pkg_commands(download_dir, dists))),
('@WRITE_CONDARC@', '\n '.join(add_condarc(info))),
('@SHORTCUTS@', shortcuts),
('@SHORTCUTS@', shortcuts_flags(info)),
('@SIZE@', str(approx_pkgs_size_kb)),
('@UNINSTALL_NAME@', info.get('uninstall_name',
'${NAME} ${VERSION} (Python ${PYVERSION} ${ARCH})'
Expand Down

0 comments on commit 9fc8f95

Please sign in to comment.