Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user-specified module paths by a new option --modulepathadd #33

Open
chenyuetian opened this issue Aug 10, 2024 · 2 comments
Open

Comments

@chenyuetian
Copy link

Allow user to use their own module files that are added to MODULEPATH. The option --modulepathadd can allow one or multiple paths users specified to be added to MODULEPATH by inserting a command line export MODULEPATH=<specified_path(s)>:$MODULEPATH after module reset to the galyleo script.

@chenyuetian
Copy link
Author

$ git diff  7e11bce 6152cbc
diff --git a/galyleo.sh b/galyleo.sh
index da5f1c8..b5da86f 100755
--- a/galyleo.sh
+++ b/galyleo.sh
@@ -105,6 +105,7 @@ fi
 #   -d | --notebook-dir <jupyter_notebook_dir>
 #      | --scratch-dir <local_scratch_dir>
 #   -e | --env-modules <env_modules>
+#      | --modulepathadd <modulepathadd>
 #   -s | --sif <singularity_image_file>
 #   -B | --bind <singularity_bind_mounts>
 #      | --nv
@@ -154,6 +155,10 @@ function galyleo_launch() {
   # Declare input variables associated with environment modules.
   local env_modules=''

+   # Declare input variables associated with customized module paths.
+  local modulepathadd=''
+
+
   # Declare input variables associated with Singularity containers.
   local singularity_image_file=''
   local singularity_bind_mounts=''
@@ -256,6 +261,10 @@ function galyleo_launch() {
         env_modules="${2}"
         shift 2
         ;;
+      --modulepathadd )
+        modulepathadd="${2}"
+        shift 2
+        ;;
       -s | --sif )
         singularity_image_file="${2}"
         shift 2
@@ -337,6 +346,7 @@ function galyleo_launch() {
   slog output -m "    -d | --notebook-dir      : ${jupyter_notebook_dir}"
   slog output -m "       | --scratch-dir       : ${local_scratch_dir}"
   slog output -m "    -e | --env-modules       : ${env_modules}"
+  slog output -m "       | --modulepathadd     : ${modulepathadd}"
   slog output -m "    -s | --sif               : ${singularity_image_file}"
   slog output -m "    -B | --bind              : ${singularity_bind_mounts}"
   slog output -m "       | --nv                : ${singularity_gpu_type}"
@@ -414,6 +424,22 @@ function galyleo_launch() {
         fi
       done
     fi
+
+     # Check if the module paths specified by the user, if any, exist.
+    # If not, then halt the launch
+    if [[ -n "${modulepathadd}" ]]; then
+      IFS=','
+      read -r -a modulepaths <<< "${modulepathadd}"
+      IFS=$' \t\n'
+      for modulepath in "${modulepaths[@]}"; do
+        ls "${modulepath}"
+        if [[ $? -ne 0 ]]; then
+          slog error -m "No such file or directory: ${modulepath}"
+          return 1
+        fi
+      done
+    fi
+

     # Check if the conda environment specified by the user, if any, can be
     # initialized and activated successfully. If not, then halt the launch.
@@ -576,6 +602,18 @@ function galyleo_launch() {
       done
     fi

+     # Add module path specified by the user.
+    if [[ -n "${modulepathadd}" ]]; then
+      IFS=','
+      read -r -a modulepaths <<< "${modulepathadd}"
+      unset IFS
+      for modulepath in "${modulepaths[@]}"; do
+      joinedpath="$joinedpath$delim$modulepath"
+      delim=":"
+      done
+       slog append -f "${job_name}.sh" -m  "export MODULEPATH=${joinedpath}:${MODULEPATH}"
+    fi
+
     # Activate a pre-installed conda environment specified by the user.
     if [[ -n "${conda_env}" ]] && [[ -z "${conda_yml}" ]]; then
       if [[ -n "${conda_init}" ]]; then
@@ -995,6 +1033,7 @@ function galyleo_help() {
   slog output -m "    -d | --notebook-dir      : ${jupyter_notebook_dir}"
   slog output -m "       | --scratch-dir       : ${local_scratch_dir}"
   slog output -m "    -e | --env-modules       : ${env_modules}"
+  slog output -m "       | --modulepathadd     : ${modulepathadd}"
   slog output -m "    -s | --sif               : ${singularity_image_file}"
   slog output -m "    -B | --bind              : ${singularity_bind_mounts}"
   slog output -m "       | --nv                : ${singularity_gpu_type}"
(END)

@mkandes
Copy link
Owner

mkandes commented Sep 10, 2024

Thanks for the suggestion @chenyuetian! I'll look at incorporating this functionaility the next time I have some time to put in some development and testing work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants