diff --git a/CHANGES.md b/CHANGES.md index e865ca89c..400ab264b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,7 +15,41 @@ [Unreleased](https://github.com/bird-house/birdhouse-deploy/tree/master) (latest) ------------------------------------------------------------------------------------------------------------------ -[//]: # (list changes here, using '-' for each new entry, remove this when items are added) +## Changes +- Allow `env.local` to use delayed eval var immediately + + Before, `env.local` can not immediately use any of the delayed eval var + because their real values are only available after `env.local` is fully read. + + So something like this in `env.local` do not work because `JUPYTERHUB_USER_DATA_DIR` + is a delayed eval var: + ```sh + export JUPYTERHUB_README_FR="$JUPYTERHUB_USER_DATA_DIR/jupyter-readme/LISMOI.ipynb" + + # Error, file not found even if the file is actually on disk + # because JUPYTERHUB_README_FR resolve to "${BIRDHOUSE_DATA_PERSIST_ROOT}/jupyterhub_user_data/jupyter-readme/LISMOI.ipynb" + # because JUPYTERHUB_USER_DATA_DIR is a delayed eval var. + if [ -f "$JUPYTERHUB_README_FR" ]; then + (...) + ``` + + `env.local` could simply append `JUPYTERHUB_README_FR` to `DELAYED_EVAL` list + but since we need to use its value immediately in `env.local`, we need to + eval it immediately. + + With the new `eval_delayed_var`, we can do the following, because + `JUPYTERHUB_USER_DATA_DIR` is a delayed eval var, any vars that depend on it + should also be delayed eval'ed. + + ```sh + export JUPYTERHUB_README_FR="$JUPYTERHUB_USER_DATA_DIR/jupyter-readme/LISMOI.ipynb" + eval_delayed_var JUPYTERHUB_README_FR + + # Now this works because JUPYTERHUB_README_FR resolve properly to "/data/jupyterhub_user_data/jupyter-readme/LISMOI.ipynb" + if [ -f "$JUPYTERHUB_README_FR" ]; then + (...) + ``` + [2.21.2](https://github.com/bird-house/birdhouse-deploy/tree/2.21.2) (2026-02-05) ------------------------------------------------------------------------------------------------------------------ diff --git a/birdhouse/README.rst b/birdhouse/README.rst index 918f77ad9..0afe3b223 100644 --- a/birdhouse/README.rst +++ b/birdhouse/README.rst @@ -109,6 +109,14 @@ See `env.local.example `_ (:download:`download `_ (:download:`download `) because many scripts assume this location. If autodeploy scheduler job is enabled, the folder containing the `env.local` file needs to be added to `BIRDHOUSE_AUTODEPLOY_EXTRA_REPOS`. diff --git a/birdhouse/read-configs.include.sh b/birdhouse/read-configs.include.sh index 8e815f003..203304857 100644 --- a/birdhouse/read-configs.include.sh +++ b/birdhouse/read-configs.include.sh @@ -372,6 +372,16 @@ check_required_vars() { } +# env.local can call this function if it wishes to use a delayed eval var. +# Otherwise all delayed eval vars are only available after env.local is fully read. +eval_delayed_var() { + DELAYED_VAR_NAME="$1" + v="`eval "echo \\"\\$${DELAYED_VAR_NAME}\\""`" # should keep new lines and leading empty spaces + value=`eval "echo \"${v}\""` + eval 'export ${DELAYED_VAR_NAME}="${value}"' +} + + # All scripts sourcing default.env and env.local and needing to use any vars # in DELAYED_EVAL list need to call this function to actually resolve the # value of each var in DELAYED_EVAL list. @@ -382,9 +392,7 @@ process_delayed_eval() { # only eval each variable once (in case it was added to the list multiple times) continue fi - v="`eval "echo \\"\\$${i}\\""`" # should keep new lines and leading empty spaces - value=`eval "echo \"${v}\""` - eval 'export ${i}="${value}"' + eval_delayed_var ${i} log DEBUG "delayed eval '$(env | grep -e "^${i}=")'" ALREADY_EVALED=" ${ALREADY_EVALED}