Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+modules-optional.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `[modules]` table and its `init` key are optional; absent, no module is loaded and no module wrapper starts, as with `init = []`.
4 changes: 2 additions & 2 deletions docs/orgmode/reference/site-file.org
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ So every job that a run or =watch= starts needs the directory, whatever its phas
| =resume= | table | none | Recording an input identity and resuming a run from a prior result. |
| =attest= | table | none | Attesting the exact inputs of a finalized plan in an RFC 9162 sidecar log. |
| =sources= | table | none | Fetching the sources of every line before the first build. |
| =modules= | table | required | The environment modules each command loads. |
| =modules= | table | ={}= | The environment modules each command loads; absent, none. |
| =caches= | table | none | The command that writes module caches after a clean build. |
| =checks= | table | none | A test command run after a clean build and before caches. |
| =logs= | table | none | Keeping the logs of a failed line, and rotating the log tree. |
Expand Down Expand Up @@ -435,7 +435,7 @@ earlier valid bundle.

| Key | Type | Default | Meaning |
|---------------+-----------------+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| =init= | array of string | required | The modules to load, in order, after =module purge=, before the shard, prefetch, build, =eb-keep-logs failed= and cache commands; may be empty. An entry is one module name, so =module load A B= is =["A", "B"]=; =check= refuses an entry with white space. |
| =init= | array of string | =[]= | The modules to load, in order, after =module purge=, before the shard, prefetch, build, =eb-keep-logs failed= and cache commands; may be empty. An entry is one module name, so =module load A B= is =["A", "B"]=; =check= refuses an entry with white space. |
| =unuse_path= | boolean | =false= | =true= empties =MODULEPATH= after =shell_init= and before =init= loads, so that the first module of =init= needs an absolute path; =check= warns when it has none. |
| =shell= | string | =bash= | The shell that runs the module wrapper, a script for a POSIX shell, by name or by path: =sh=, =bash=, =dash=, =ash=, =ksh=, =ksh93=, =mksh= or =yash=. =check= refuses any other, such as =zsh=, which does not split the names of =init=. |
| =shell_init= | string | none | A file to source before =module= is called, for a shell that does not define it. It is sourced without =set -e= and =set -u=; a =module= call that fails still stops the command. |
Expand Down
39 changes: 36 additions & 3 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ doc_struct! {
doc_struct! {
/// Environment modules.
Modules {
init: Vec<String> => ("array of string", "", true,
#[serde(default)]
init: Vec<String> => ("array of string", "[]", false,
"Modules loaded, in order, after `module purge` in every EasyBuild phase and around `stack shard`, one name per entry, without white space. May be empty."),
#[serde(default)]
unuse_path: bool => ("boolean", "false", false, "Clears MODULEPATH after `shell_init` and before loading `init`, so the first `init` module needs an absolute path."),
Expand All @@ -492,6 +493,20 @@ doc_struct! {
}
}

impl Default for Modules {
/// An absent `[modules]` table: no module loaded, no wrapper.
fn default() -> Self {
Modules {
init: Vec::new(),
unuse_path: false,
shell: d_shell(),
shell_init: None,
eessi: None,
package_env: BTreeMap::new(),
}
}
}

doc_struct! {
/// One module cache entry.
CacheTarget {
Expand Down Expand Up @@ -758,7 +773,9 @@ doc_struct! {
attest: Option<Attest> => ("table", "none", false,
"When enabled, `plan` and `run` append a hash of the exact inputs to an RFC 9162 sidecar log. Absent, they record nothing."),
sources: Option<Sources> => ("table", "none", false, "Source prefetch."),
modules: Modules => ("table", "", true, "Environment modules."),
#[serde(default)]
modules: Modules => ("table", "{}", false,
"Environment modules; absent, no module is loaded and no wrapper starts."),
caches: Option<Caches> => ("table", "none", false, "Module caches."),
checks: Option<Checks> => ("table", "none", false,
"A test command run after a clean build and before caches."),
Expand Down Expand Up @@ -944,10 +961,11 @@ mod tests {
.filter(|f| f.required)
.map(|f| f.key)
.collect();
for k in ["site", "scheduler", "targets", "filesystems", "modules"] {
for k in ["site", "scheduler", "targets", "filesystems"] {
assert!(req.contains(&k), "{k} must be required");
}
for k in [
"modules",
"admission",
"shards",
"sources",
Expand All @@ -971,4 +989,19 @@ mod tests {
assert!(caches.enabled);
assert!(caches.targets.is_empty());
}

#[test]
fn site_without_modules_table_loads_nothing() {
let text = "schema_version = 1\nkind = \"site\"\n[site]\nname = \"w\"\n\
[scheduler]\nkind = \"local\"\n[[targets]]\nname = \"cpu\"\n\
build_lists = [\"software.list\"]\ndefault = true\n[filesystems]\n\
scratch = \"/srv/s\"\ntmp = \"/srv/s/tmp\"\nbuild_path = \"/srv/s/b\"\n\
install_root = \"/srv/sw\"\nlog_root = \"/srv/logs\"\n";
let s: Site = toml::from_str(text).expect("a site without [modules] parses");
assert_eq!(s.modules, Modules::default());
assert!(s.modules.init.is_empty());
assert_eq!(s.modules.shell, "bash");
let m: Modules = toml::from_str("shell = \"sh\"").expect("[modules] without init parses");
assert!(m.init.is_empty());
}
}
10 changes: 4 additions & 6 deletions templates/workstation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ source_paths = ["/srv/eb/sources"]
install_root = "/srv/eb/software"
log_root = "/srv/eb/logs"

# `eb` comes from PATH, for example a pip install of EasyBuild, so no module
# is loaded before a build. EasyBuild still needs a module tool: source
# EESSI's init for its Lmod, or install Lmod, and set
# EASYBUILD_MODULES_TOOL=Lmod.
[modules]
init = []
# No [modules] table: `eb` comes from PATH, for example a pip install of
# EasyBuild, so no module is loaded before a build and no wrapper starts.
# EasyBuild still needs a module tool: source EESSI's init for its Lmod, or
# install Lmod, and set EASYBUILD_MODULES_TOOL=Lmod.
17 changes: 13 additions & 4 deletions tests/schema_and_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,19 @@ fn unknown_keys_are_rejected() {

#[test]
fn missing_required_sections_are_rejected() {
for cut in ["[scheduler]\nkind = \"slurm\"\n", "[modules]\ninit = []\n"] {
let text = MINIMAL.replace(cut, "");
assert!(site::parse(&text).is_err(), "{cut}");
}
let cut = "[scheduler]\nkind = \"slurm\"\n";
assert!(MINIMAL.contains(cut));
assert!(site::parse(&MINIMAL.replace(cut, "")).is_err(), "{cut}");
}

#[test]
fn a_site_without_modules_loads_nothing() {
let cut = "[modules]\ninit = []\n";
assert!(MINIMAL.contains(cut));
let s = site::parse(&MINIMAL.replace(cut, "")).expect("[modules] is optional");
assert!(s.modules.init.is_empty());
assert!(s.modules.shell_init.is_none());
assert!(site::validate(&s, None).is_empty());
}

#[test]
Expand Down
Loading