Skip to content

Commit edd19d2

Browse files
bugfix for module templates: consistency of aliases and passed arguments (#486)
* module templates: protecting args with escaped quotes * Tcl module templates: no args for -exec and -run * module templates: (re)added args in help output * module templates, TCL: bash/csh if for -exec and -run args * module templates, Docker: fixed alias.args to be args.command * module templates, singularity: removed unnecessary ELSE (IF NOT ALIASES) in help output * Revert "module templates, Docker: fixed alias.args to be args.command" This reverts commit f1ee1d8. * tcl module templates: escape $ in $@ in help output
1 parent 0d4f634 commit edd19d2

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

shpc/main/modules/templates/docker.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Commands include:
2525
{{ command }} inspect <container>
2626
2727
{% if aliases %}{% for alias in aliases %} - {{ alias.name }}:
28-
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ alias.entrypoint }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options }} {% endif %} -v ${PWD} -w ${PWD} <container> "{{ alias.args }}"
28+
{{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ alias.entrypoint }} {% if envfile %}--env-file {{ module_dir }}/{{ envfile }}{% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options }} {% endif %} -v ${PWD} -w ${PWD} <container> "{{ alias.args }}" "$@"
2929
{% endfor %}{% endif %}
3030
3131
For each of the above, you can export:
@@ -60,7 +60,7 @@ conflict("{{ tool }}"{% if name != tool %},"{{ name }}"{% endif %}{% if aliases
6060

6161
-- exec functions to provide "alias" to module commands
6262
{% if aliases %}{% for alias in aliases %}
63-
set_shell_function("{{ alias.name }}", execCmd .. {% if alias.docker_options %} "{{ alias.docker_options }} " .. {% endif %} " --entrypoint {{ alias.entrypoint }} " .. containerPath .. " {{ alias.args }} $@", execCmd .. {% if alias.docker_options %} "{{ alias.docker_options }} " .. {% endif %} " --entrypoint {{ alias.entrypoint }} " .. containerPath .. " {{ alias.args }}")
63+
set_shell_function("{{ alias.name }}", execCmd .. {% if alias.docker_options %} "{{ alias.docker_options }} " .. {% endif %} " --entrypoint {{ alias.entrypoint }} " .. containerPath .. " {{ alias.args }} \"$@\"", execCmd .. {% if alias.docker_options %} "{{ alias.docker_options }} " .. {% endif %} " --entrypoint {{ alias.entrypoint }} " .. containerPath .. " {{ alias.args }}")
6464
{% endfor %}{% endif %}
6565

6666
{% if aliases %}
@@ -70,10 +70,10 @@ if (myShellName() == "bash") then
7070
end{% endif %}
7171

7272
-- A customizable exec function
73-
set_shell_function("{|module_name|}-exec", execCmd .. " --entrypoint \"\" " .. containerPath .. " $@", execCmd .. " --entrypoint \"\" " .. containerPath)
73+
set_shell_function("{|module_name|}-exec", execCmd .. " --entrypoint \"\" " .. containerPath .. " \"$@\"", execCmd .. " --entrypoint \"\" " .. containerPath)
7474

7575
-- Always provide a container run
76-
set_shell_function("{|module_name|}-run", runCmd .. " $@", runCmd)
76+
set_shell_function("{|module_name|}-run", runCmd .. " \"$@\"", runCmd)
7777

7878
-- Inspect runscript or deffile easily!
7979
set_shell_function("{|module_name|}-inspect", inspectCmd, inspectCmd)

shpc/main/modules/templates/docker.tcl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ proc ModulesHelp { } {
1515
puts stderr " - {{ image }}"
1616
puts stderr "Commands include:"
1717
puts stderr " - {|module_name|}-run:"
18-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container>"
18+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm {% if envfile %}--env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container> \"\$@\""
1919
puts stderr " - {|module_name|}-shell:"
2020
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint {{ shell }} {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container>"
2121
puts stderr " - {|module_name|}-exec:"
22-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint \"\" {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container> $*"
22+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} -u `id -u`:`id -g` --rm --entrypoint \"\" {% if envfile %} --env-file {{ module_dir }}/{{ envfile }} {% endif %} {% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %} -v . -w . <container> \"\$@\""
2323
puts stderr " - {|module_name|}-inspect:"
2424
puts stderr " {{ command }} inspect <container>"
25+
puts stderr ""
2526
{% if aliases %}{% for alias in aliases %} puts stderr " - {{ alias.name }}:"
26-
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} --rm -u `id -u`:`id -g` --entrypoint {{ alias.entrypoint | replace("$", "\$") }} {% if envfile %}--envfile {{ module_dir }}/{{ envfile }} {% endif %}{% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options | replace("$", "\$") }} {% endif %} -v . -w . <container> {{ alias.args | replace("$", "\$") }}"
27+
puts stderr " {{ command }} run -i{% if tty %}t{% endif %} --rm -u `id -u`:`id -g` --entrypoint {{ alias.entrypoint | replace("$", "\$") }} {% if envfile %}--envfile {{ module_dir }}/{{ envfile }} {% endif %}{% if bindpaths %}-v {{ bindpaths }} {% endif %}{% if features.home %}-v {{ features.home }} {% endif %}{% if alias.docker_options %}{{ alias.docker_options | replace("$", "\$") }} {% endif %} -v . -w . <container> {{ alias.args | replace("$", "\$") }} \"\$@\""
2728
{% endfor %}{% endif %}
28-
29+
puts stderr ""
2930
puts stderr "For each of the above, you can export:"
31+
puts stderr ""
3032
puts stderr " - PODMAN_OPTS: to define custom options for {{ command }}"
3133
puts stderr " - PODMAN_COMMAND_OPTS: to define custom options for the command"
3234

@@ -75,7 +77,7 @@ set-alias {|module_name|}-shell "${shellCmd}"
7577
{% if aliases %}
7678
if { [ module-info shell bash ] } {
7779
if { [ module-info mode load ] } {
78-
{% for alias in aliases %} puts stdout "function {{ alias.name }}() { ${execCmd} {% if alias.docker_options %} {{ alias.docker_options | replace("$", "\$") }} {% endif %} --entrypoint {{ alias.entrypoint | replace("$", "\$") }} ${containerPath} {{ alias.args | replace("$", "\$") }} \$@; }; export -f {{ alias.name }};"
80+
{% for alias in aliases %} puts stdout "function {{ alias.name }}() { ${execCmd} {% if alias.docker_options %} {{ alias.docker_options | replace("$", "\$") }} {% endif %} --entrypoint {{ alias.entrypoint | replace("$", "\$") }} ${containerPath} {{ alias.args | replace("$", "\$") }} \"\$@\"; }; export -f {{ alias.name }};"
7981
{% endfor %}
8082
}
8183
if { [ module-info mode remove ] } {
@@ -89,10 +91,18 @@ if { [ module-info shell bash ] } {
8991
{% endif %}
9092

9193
# A customizable exec function
92-
set-alias {|module_name|}-exec "${execCmd} --entrypoint \"\" ${containerPath}"
94+
if { [ module-info shell bash ] } {
95+
set-alias {|module_name|}-exec "${execCmd} --entrypoint \"\" ${containerPath} \"\$@\""
96+
} else {
97+
set-alias {|module_name|}-exec "${execCmd} --entrypoint \"\" ${containerPath}"
98+
}
9399

94100
# Always provide a container run
95-
set-alias {|module_name|}-run "${runCmd}"
101+
if { [ module-info shell bash ] } {
102+
set-alias {|module_name|}-run "${runCmd} \"\$@\""
103+
} else {
104+
set-alias {|module_name|}-run "${runCmd}"
105+
}
96106

97107
# Inspect runscript or deffile easily!
98108
set-alias {|module_name|}-inspect "${inspectCmd} ${containerPath}"

shpc/main/modules/templates/singularity.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Container:
1616
Commands include:
1717
1818
- {|module_name|}-run:
19-
singularity run {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home }} --home {{ features.home }} {% endif %}{% if features.x11 %}-B {{ features.x11 }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container>
19+
singularity run {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home }} --home {{ features.home }} {% endif %}{% if features.x11 %}-B {{ features.x11 }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container> "$@"
2020
- {|module_name|}-shell:
2121
singularity shell -s {{ singularity_shell }} {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home }} --home {{ features.home }} {% endif %}{% if features.x11 %}-B {{ features.x11 }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container>
2222
- {|module_name|}-exec:
@@ -27,8 +27,8 @@ Commands include:
2727
singularity inspect -d <container>
2828
2929
{% if aliases %}{% for alias in aliases %} - {{ alias.name }}:
30-
singularity exec {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home }} --home {{ features.home }} {% endif %}{% if features.x11 %}-B {{ features.x11 }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}{% if alias.singularity_options %}{{ alias.singularity_options }} {% endif %}<container> {{ alias.command }}
31-
{% endfor %}{% else %} - {|module_name|}: singularity run {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home }} --home {{ features.home }} {% endif %}{% if features.x11 %}-B {{ features.x11 }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }}{% endif %}<container>{% endif %}
30+
singularity exec {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home }} --home {{ features.home }} {% endif %}{% if features.x11 %}-B {{ features.x11 }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}{% if alias.singularity_options %}{{ alias.singularity_options }} {% endif %}<container> {{ alias.command }} "$@"
31+
{% endfor %}{% endif %}
3232
3333
For each of the above, you can export:
3434
@@ -63,7 +63,7 @@ conflict("{{ tool }}"{% if name != tool %},"{{ name }}"{% endif %}{% if aliases
6363

6464
-- exec functions to provide "alias" to module commands
6565
{% if aliases %}{% for alias in aliases %}
66-
set_shell_function("{{ alias.name }}", execCmd .. {% if alias.singularity_options %} "{{ alias.singularity_options }} " .. {% endif %} containerPath .. " {{ alias.command }} $@", execCmd .. {% if alias.singularity_options %} "{{ alias.singularity_options }} " .. {% endif %} containerPath .. " {{ alias.command }}")
66+
set_shell_function("{{ alias.name }}", execCmd .. {% if alias.singularity_options %} "{{ alias.singularity_options }} " .. {% endif %} containerPath .. " {{ alias.command }} \"$@\"", execCmd .. {% if alias.singularity_options %} "{{ alias.singularity_options }} " .. {% endif %} containerPath .. " {{ alias.command }}")
6767
{% endfor %}{% endif %}
6868

6969
{% if aliases %}
@@ -73,10 +73,10 @@ if (myShellName() == "bash") then
7373
end{% endif %}
7474

7575
-- A customizable exec function
76-
set_shell_function("{|module_name|}-exec", execCmd .. containerPath .. " $@", execCmd .. containerPath)
76+
set_shell_function("{|module_name|}-exec", execCmd .. containerPath .. " \"$@\"", execCmd .. containerPath)
7777

7878
-- Always provide a container run
79-
set_shell_function("{|module_name|}-run", runCmd .. " $@", runCmd)
79+
set_shell_function("{|module_name|}-run", runCmd .. " \"$@\"", runCmd)
8080

8181
-- Inspect runscript or deffile easily!
8282
set_shell_function("{|module_name|}-inspect-runscript", inspectCmd .. " -r " .. containerPath, inspectCmd .. containerPath)

shpc/main/modules/templates/singularity.tcl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ proc ModulesHelp { } {
1818
puts stderr "Commands include:"
1919
puts stderr ""
2020
puts stderr " - {|module_name|}-run:"
21-
puts stderr " singularity run {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container>"
21+
puts stderr " singularity run {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container> \"\$@\""
2222
puts stderr " - {|module_name|}-shell:"
2323
puts stderr " singularity shell -s {{ singularity_shell }} {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container>"
2424
puts stderr " - {|module_name|}-exec:"
25-
puts stderr " singularity exec {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container> $*"
25+
puts stderr " singularity exec {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}<container> \"\$@\""
2626
puts stderr " - {|module_name|}-inspect-runscript:"
2727
puts stderr " singularity inspect -r <container>"
2828
puts stderr " - {|module_name|}-inspect-deffile:"
2929
puts stderr " singularity inspect -d <container>"
30-
puts stderr ""
30+
puts stderr ""
3131
{% if aliases %}{% for alias in aliases %} puts stderr " - {{ alias.name }}:"
32-
puts stderr " singularity exec {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}{% if alias.singularity_options %}{{ alias.singularity_options | replace("$", "\$") }} {% endif %}<container> {{ alias.command | replace("$", "\$") }}"
33-
{% endfor %}{% else %} puts stderr " - {|module_name|}: singularity run {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }}{% endif %}<container>"{% endif %}
32+
puts stderr " singularity exec {% if features.gpu %}{{ features.gpu }} {% endif %}{% if features.home %}-B {{ features.home | replace("$", "\$") }} --home {{ features.home | replace("$", "\$") }} {% endif %}{% if features.x11 %}-B {{ features.x11 | replace("$", "\$") }} {% endif %}{% if envfile %}-B {{ module_dir }}/{{ envfile }}:/.singularity.d/env/{{ envfile }}{% endif %} {% if bindpaths %}-B {{ bindpaths }} {% endif %}{% if alias.singularity_options %}{{ alias.singularity_options | replace("$", "\$") }} {% endif %}<container> {{ alias.command | replace("$", "\$") }} \"\$@\""
33+
{% endfor %}{% endif %}
3434
puts stderr ""
3535
puts stderr "For each of the above, you can export:"
3636
puts stderr ""
@@ -82,7 +82,7 @@ set-alias {|module_name|}-shell "${shellCmd}"
8282
{% if aliases %}
8383
if { [ module-info shell bash ] } {
8484
if { [ module-info mode load ] } {
85-
{% for alias in aliases %} puts stdout "function {{ alias.name }}() { ${execCmd} {% if alias.singularity_options %} {{ alias.singularity_options | replace("$", "\$") }} {% endif %} ${containerPath} {{ alias.command | replace("$", "\$") }} \$@; }; export -f {{ alias.name }};"
85+
{% for alias in aliases %} puts stdout "function {{ alias.name }}() { ${execCmd} {% if alias.singularity_options %} {{ alias.singularity_options | replace("$", "\$") }} {% endif %} ${containerPath} {{ alias.command | replace("$", "\$") }} \"\$@\"; }; export -f {{ alias.name }};"
8686
{% endfor %}
8787
}
8888
if { [ module-info mode remove ] } {
@@ -96,10 +96,18 @@ if { [ module-info shell bash ] } {
9696
{% endif %}
9797

9898
# A customizable exec function
99-
set-alias {|module_name|}-exec "${execCmd} ${containerPath}"
99+
if { [ module-info shell bash ] } {
100+
set-alias {|module_name|}-exec "${execCmd} ${containerPath} \"\$@\""
101+
} else {
102+
set-alias {|module_name|}-exec "${execCmd} ${containerPath}"
103+
}
100104

101105
# Always provide a container run
102-
set-alias {|module_name|}-run "${runCmd}"
106+
if { [ module-info shell bash ] } {
107+
set-alias {|module_name|}-run "${runCmd} \"\$@\""
108+
} else {
109+
set-alias {|module_name|}-run "${runCmd}"
110+
}
103111

104112
# Inspect runscript or deffile easily!
105113
set-alias {|module_name|}-inspect-runscript "${inspectCmd} -r ${containerPath}"

0 commit comments

Comments
 (0)