From b553f5ea217368f33319b863936fc4b3ddfffa7a Mon Sep 17 00:00:00 2001 From: jaimergp Date: Sat, 9 Nov 2024 14:11:43 +0100 Subject: [PATCH] Template PKG installers with Jinja too --- constructor/jinja.py | 3 +- constructor/osx/check_shortcuts.sh | 2 +- constructor/osx/checks_before_install.sh | 2 +- constructor/osx/clean_cache.sh | 2 +- constructor/osx/prepare_installation.sh | 18 ++++----- constructor/osx/run_installation.sh | 26 ++++++------- constructor/osx/run_user_script.sh | 16 ++++---- constructor/osx/update_path.sh | 2 +- constructor/osxpkg.py | 49 +++++++++++------------- tests/test_header.py | 22 ++++++++++- 10 files changed, 77 insertions(+), 65 deletions(-) diff --git a/constructor/jinja.py b/constructor/jinja.py index 3d8807fb9..3704cea26 100644 --- a/constructor/jinja.py +++ b/constructor/jinja.py @@ -40,9 +40,8 @@ def render_jinja_for_input_file(data, directory, content_filter): def render_template(text, **kwargs): - env = Environment(keep_trailing_newline=True) + env = Environment(keep_trailing_newline=True, undefined=StrictUndefined) env.globals["constructor_version"] = __version__ - env.undefined = StrictUndefined try: template = env.from_string(text) return template.render(**kwargs) diff --git a/constructor/osx/check_shortcuts.sh b/constructor/osx/check_shortcuts.sh index b592b2443..c15adceed 100644 --- a/constructor/osx/check_shortcuts.sh +++ b/constructor/osx/check_shortcuts.sh @@ -4,7 +4,7 @@ set -eux # $2 is the install location, which is ~ by default # but which the user can change. -PREFIX="$2/__NAME_LOWER__" +PREFIX="$2/{{ pkg_name_lower }}" PREFIX=$(cd "$PREFIX"; pwd) # If the UI selected the "Create shortcuts" option diff --git a/constructor/osx/checks_before_install.sh b/constructor/osx/checks_before_install.sh index 54fabc43d..51468c52e 100644 --- a/constructor/osx/checks_before_install.sh +++ b/constructor/osx/checks_before_install.sh @@ -9,7 +9,7 @@ # so the only way to prevent an action is to abort and start again from the beginning. set -euo pipefail -PREFIX="$2/__NAME_LOWER__" +PREFIX="$2/{{ pkg_name_lower }}" echo "PREFIX=$PREFIX" if [[ -e "$PREFIX" ]]; then diff --git a/constructor/osx/clean_cache.sh b/constructor/osx/clean_cache.sh index 23c8fc908..d056ce99b 100644 --- a/constructor/osx/clean_cache.sh +++ b/constructor/osx/clean_cache.sh @@ -6,6 +6,6 @@ # but which the user can change. set -eux -PREFIX="$2/__NAME_LOWER__" +PREFIX="$2/{{ pkg_name_lower }}" PREFIX=$(cd "$PREFIX"; pwd) rm -rf "$PREFIX/pkgs" diff --git a/constructor/osx/prepare_installation.sh b/constructor/osx/prepare_installation.sh index 17f13e4b4..ef63d059c 100644 --- a/constructor/osx/prepare_installation.sh +++ b/constructor/osx/prepare_installation.sh @@ -8,17 +8,17 @@ set -euo pipefail notify() { # shellcheck disable=SC2050 -if [ "__PROGRESS_NOTIFICATIONS__" = "True" ]; then +{%- if progress_notifications == "true" %} osascript </dev/null || : -__WRITE_CONDARC__ +{{ write_condarc }} if ! "$PREFIX/bin/python" -V; then echo "ERROR running Python" diff --git a/constructor/osx/run_user_script.sh b/constructor/osx/run_user_script.sh index ca325f9d5..6de59c489 100644 --- a/constructor/osx/run_user_script.sh +++ b/constructor/osx/run_user_script.sh @@ -8,17 +8,17 @@ set -euo pipefail notify() { # shellcheck disable=SC2050 -if [ "__PROGRESS_NOTIFICATIONS__" = "True" ]; then +{%- if progress_notifications == "true" %} osascript <