From 100564f8ad8ac60d425e7b7dc29b5c639d184bb0 Mon Sep 17 00:00:00 2001 From: Krishnan R Date: Tue, 17 May 2022 11:52:58 +0200 Subject: [PATCH] Configure kernel provisioner and default environment file --- systemuser.sh | 2 ++ userconfig.sh | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/systemuser.sh b/systemuser.sh index 6ad4ba4..7cf8270 100644 --- a/systemuser.sh +++ b/systemuser.sh @@ -153,6 +153,8 @@ fi chown -R $USER:$USER $JPY_DIR $JPY_LOCAL_DIR $IPYTHONDIR export SWAN_ENV_FILE=$SCRATCH_HOME/.bash_profile +# Used by swanprojects for the default folder environment +export SWAN_DEFAULT_ENV_FILE=$SCRATCH_HOME/.swan_default_env sudo -E -u $USER sh /srv/singleuser/userconfig.sh diff --git a/userconfig.sh b/userconfig.sh index fddfb95..cbbad9e 100644 --- a/userconfig.sh +++ b/userconfig.sh @@ -124,7 +124,14 @@ import json def addEnv(dtext): d=eval(dtext) - d["env"]=dict(os.environ) + + # Configure a provisioner in kernel.json, that will load the enviornment + # dynamically from a folder-specific file or the default enviornment file + d["metadata"] = { + "kernel_provisioner": { + "provisioner_name": "swan-provisioner" + } + } return d kdirs = os.listdir("$KERNEL_DIR") @@ -141,6 +148,15 @@ with open("$SWAN_ENV_FILE", "w") as termEnvFile: if key == "PYTHONPATH": val = re.sub('/usr/local/lib/swan/(extensions/)?:', '', val) termEnvFile.write("export %s=\"%s\"\n" % (key, val)) +# Write an enviornment file to be read by the provisioner +# for folders without a defined environment +with open("$SWAN_DEFAULT_ENV_FILE", "w") as defaultEnvFile: + for key, val in dict(os.environ).items(): + if key == "SUDO_COMMAND": + continue + if key == "PYTHONPATH": + val = re.sub('/usr/local/lib/swan/(extensions/)?:', '', val) + defaultEnvFile.write("%s=%s\n" % (key, val)) EOF # Make sure that `python` points to the correct python bin from CVMFS