diff --git a/changelog.d/+modules-optional.feature.md b/changelog.d/+modules-optional.feature.md new file mode 100644 index 0000000..6e054d9 --- /dev/null +++ b/changelog.d/+modules-optional.feature.md @@ -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 = []`. diff --git a/docs/orgmode/reference/site-file.org b/docs/orgmode/reference/site-file.org index 0f6d948..9e508d7 100644 --- a/docs/orgmode/reference/site-file.org +++ b/docs/orgmode/reference/site-file.org @@ -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. | @@ -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. | diff --git a/src/schema.rs b/src/schema.rs index 0e107f9..44d479b 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -476,7 +476,8 @@ doc_struct! { doc_struct! { /// Environment modules. Modules { - init: Vec => ("array of string", "", true, + #[serde(default)] + init: Vec => ("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."), @@ -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 { @@ -758,7 +773,9 @@ doc_struct! { attest: Option => ("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 => ("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 => ("table", "none", false, "Module caches."), checks: Option => ("table", "none", false, "A test command run after a clean build and before caches."), @@ -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", @@ -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()); + } } diff --git a/templates/workstation.toml b/templates/workstation.toml index 871925e..0eb5d00 100644 --- a/templates/workstation.toml +++ b/templates/workstation.toml @@ -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. diff --git a/tests/schema_and_plan.rs b/tests/schema_and_plan.rs index 26520ef..6c50e11 100644 --- a/tests/schema_and_plan.rs +++ b/tests/schema_and_plan.rs @@ -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]