Skip to content

Commit c912c25

Browse files
authored
only use modules.yaml from recipe (#275)
Do not use modules.yaml from the Spack installation if no modules.yaml file is provided. Fix #274
1 parent 312b11b commit c912c25

6 files changed

Lines changed: 33 additions & 28 deletions

File tree

docs/recipes.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ version: 2
3434
* `name`: a plain text name for the environment
3535
* `store`: the location where the environment will be mounted.
3636
* `spack`: which spack and package repositories to use for installation.
37-
* `modules`: _optional_ enable/diasble module file generation (default `true`).
37+
* `modules`: (_deprecated_) _optional_ enable/disable module file generation.
3838
* `description`: _optional_ a string that describes the environment (default empty).
3939
* `version`: _default = 1_ the version of the uenv recipe (see below)
4040

@@ -440,11 +440,12 @@ The `append_path` field is the same as `prepend_path`, except it appends instead
440440

441441
## Modules
442442

443-
Modules are generated for the installed compilers and packages by spack. The default module generation rules set by the version of spack specified in `config.yaml` will be used if no `modules.yaml` file is provided.
443+
The presence of a `modules.yaml` file in the recipe is a necessary and sufficient condition to enable module generation.
444444

445-
To set rules for module generation, provide a `modules.yaml` file as per the [spack documentation](https://spack.readthedocs.io/en/latest/module_file_support.html).
445+
!!! warning
446+
`config:modules` field has been deprecated. It can still be specified, but it has to be consistent with the presence of `modules.yaml` file.
446447

447-
To disable module generation, set the field `config:modules:False` in `config.yaml`.
448+
Modules are generated for the installed compilers and packages by spack. Rules for module generation in `modules.yaml` file should be provided as per the [spack documentation](https://spack.readthedocs.io/en/latest/module_file_support.html).
448449

449450
## Custom Spack Packages
450451

stackinator/builder.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def environment_meta(self, recipe):
158158
meta["views"] = recipe.environment_view_meta
159159
meta["mount"] = str(recipe.mount)
160160
modules = None
161-
if conf["modules"]:
161+
if recipe.with_modules:
162162
modules = {"root": str(recipe.mount / "modules")}
163163
meta["modules"] = modules
164164
self._environment_meta = meta
@@ -227,7 +227,7 @@ def generate(self, recipe):
227227
f.write(
228228
makefile_template.render(
229229
cache=recipe.mirror,
230-
modules=recipe.config["modules"],
230+
modules=recipe.with_modules,
231231
post_install_hook=recipe.post_install_hook,
232232
pre_install_hook=recipe.pre_install_hook,
233233
spack_version=spack_version,
@@ -463,6 +463,7 @@ def generate(self, recipe):
463463
with (generate_config_path / "Makefile").open("w") as f:
464464
f.write(
465465
make_config_template.render(
466+
modules=recipe.with_modules,
466467
build_path=self.path.as_posix(),
467468
all_compilers=all_compilers,
468469
release_compilers=all_compilers,
@@ -471,11 +472,11 @@ def generate(self, recipe):
471472
)
472473

473474
# write modules/modules.yaml
474-
modules_yaml = recipe.modules_yaml
475-
generate_modules_path = self.path / "modules"
476-
generate_modules_path.mkdir(exist_ok=True)
477-
with (generate_modules_path / "modules.yaml").open("w") as f:
478-
f.write(modules_yaml)
475+
if recipe.with_modules:
476+
generate_modules_path = self.path / "modules"
477+
generate_modules_path.mkdir(exist_ok=True)
478+
with (generate_modules_path / "modules.yaml").open("w") as f:
479+
yaml.dump(recipe.modules, f)
479480

480481
# write the meta data
481482
meta_path = store_path / "meta"

stackinator/recipe.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,23 @@ def __init__(self, args):
6363
self.generate_compiler_specs(raw)
6464

6565
# optional modules.yaml file
66+
self.modules = None
6667
modules_path = self.path / "modules.yaml"
6768
self._logger.debug(f"opening {modules_path}")
68-
if not modules_path.is_file():
69-
modules_path = pathlib.Path(args.build) / "spack/etc/spack/defaults/modules.yaml"
70-
self._logger.debug(f"no modules.yaml provided - using the {modules_path}")
69+
if modules_path.is_file():
70+
with modules_path.open() as fid:
71+
self.modules = yaml.load(fid, Loader=yaml.Loader)
72+
# Note: it should match MODULEPATH set by envvars and used by uenv view "modules"
73+
self.modules["modules"]["default"]["roots"]["tcl"] = (pathlib.Path(self.mount) / "modules").as_posix()
7174

72-
self.modules = modules_path
75+
# DEPRECATED field `config:modules`
76+
if "modules" in self.config:
77+
self._logger.warning("boolean field config.yaml:modules has been deprecated")
78+
79+
if self.with_modules != self.config["modules"]:
80+
self._logger.error(f"config.yaml:modules:{self.config['modules']}")
81+
self._logger.error(f"modules.yaml:{self.with_modules}")
82+
raise RuntimeError("conflicting modules configuration detected")
7383

7484
# optional packages.yaml file
7585
packages_path = self.path / "packages.yaml"
@@ -261,6 +271,10 @@ def config(self, config_path):
261271
schema.ConfigValidator.validate(raw)
262272
self._config = raw
263273

274+
@property
275+
def with_modules(self) -> bool:
276+
return self.modules is not None
277+
264278
# In Stackinator 6 we replaced logic required to determine the
265279
# pre 1.0 Spack version.
266280
def find_spack_version(self, develop):
@@ -313,13 +327,6 @@ def environment_view_meta(self):
313327

314328
return view_meta
315329

316-
@property
317-
def modules_yaml(self):
318-
with self.modules.open() as fid:
319-
raw = yaml.load(fid, Loader=yaml.Loader)
320-
raw["modules"]["default"]["roots"]["tcl"] = (pathlib.Path(self.mount) / "modules").as_posix()
321-
return yaml.dump(raw)
322-
323330
# creates the self.environments field that describes the full specifications
324331
# for all of the environments sets, grouped in environments, from the raw
325332
# environments.yaml input.

stackinator/schema/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
}
6666
},
6767
"modules" : {
68-
"type": "boolean",
69-
"default": true
68+
"type": "boolean"
7069
},
7170
"description" : {
7271
"oneOf": [

stackinator/templates/Makefile.generate-config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ALL_COMPILER_PREFIXES ={% for compiler in all_compilers %} $$($(SPACK_HELPER) -e
1010
COMPILER_PREFIXES ={% for compiler in release_compilers %} $$($(SPACK_HELPER) -e ../compilers/{{ compiler }} find --explicit --format='{prefix}' gcc llvm llvm-amdgpu nvhpc){% endfor %}
1111

1212

13-
all: $(CONFIG_DIR)/upstreams.yaml $(CONFIG_DIR)/packages.yaml $(CONFIG_DIR)/repos.yaml $(MODULE_DIR)/upstreams.yaml $(MODULE_DIR)/compilers.yaml
13+
all: $(CONFIG_DIR)/upstreams.yaml $(CONFIG_DIR)/packages.yaml $(CONFIG_DIR)/repos.yaml{% if modules %} $(MODULE_DIR)/upstreams.yaml $(MODULE_DIR)/compilers.yaml{% endif %}
1414

1515
# Generate the upstream configuration that will be provided by the mounted image
1616
$(CONFIG_DIR)/upstreams.yaml:

unittests/test_schema.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def test_config_yaml(yaml_path):
4343
assert raw["store"] == "/user-environment"
4444
assert raw["spack"]["commit"] is None
4545
assert raw["spack"]["packages"]["commit"] is None
46-
assert raw["modules"] == True # noqa: E712
4746
assert raw["mirror"] == {"enable": True, "key": None}
4847
assert raw["description"] is None
4948

@@ -64,7 +63,6 @@ def test_config_yaml(yaml_path):
6463
schema.ConfigValidator.validate(raw)
6564
assert raw["spack"]["commit"] is None
6665
assert raw["spack"]["packages"]["commit"] is not None
67-
assert raw["modules"] == True # noqa: E712
6866
assert raw["mirror"] == {"enable": True, "key": None}
6967
assert raw["description"] is None
7068

@@ -85,7 +83,6 @@ def test_config_yaml(yaml_path):
8583
schema.ConfigValidator.validate(raw)
8684
assert raw["spack"]["commit"] == "develop"
8785
assert raw["spack"]["packages"]["commit"] is None
88-
assert raw["modules"] == True # noqa: E712
8986
assert raw["mirror"] == {"enable": True, "key": None}
9087
assert raw["description"] is None
9188

0 commit comments

Comments
 (0)