Skip to content

Commit

Permalink
Make environment:mpi:gpu optional (#150)
Browse files Browse the repository at this point in the history
* add test for mpi without specifying gpu
* fix schema
* fix default management
  • Loading branch information
albestro authored Nov 20, 2023
1 parent e8219f5 commit a70e0a7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
8 changes: 5 additions & 3 deletions stackinator/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def extend_with_default(validator_class):
validate_properties = validator_class.VALIDATORS["properties"]

def set_defaults(validator, properties, instance, schema):
for property, subschema in properties.items():
if "default" in subschema:
instance.setdefault(property, subschema["default"])
# if instance is none, it's not possible to set any default for any sub-property
if instance is not None:
for property, subschema in properties.items():
if "default" in subschema:
instance.setdefault(property, subschema["default"])

for error in validate_properties(
validator,
Expand Down
5 changes: 4 additions & 1 deletion stackinator/schema/environments.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
"additionalProperties": false,
"properties": {
"spec": {"type": "string"},
"gpu": {"enum": ["cuda", "rocm", null, false]}
"gpu": {
"enum": ["cuda", "rocm", null, false],
"default": null
}
}
},
{"enum": [null, false]}
Expand Down
4 changes: 4 additions & 0 deletions unittests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def test_environments_yaml(yaml_path):
assert env["mpi"] is None
assert env["views"] == {}

env = raw["defaults-env-mpi-nogpu"]
assert env["mpi"]["spec"] is not None
assert env["mpi"]["gpu"] is None

# the full-env sets all of the fields
# test that they have been read correctly

Expand Down
8 changes: 8 additions & 0 deletions unittests/yaml/environments.full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ defaults-env:
# assert mpi=None
# assert packages=[]
# assert view=True
defaults-env-mpi-nogpu:
compiler:
- toolchain: gcc
spec: gcc@11
specs:
- tree
mpi:
spec: cray-mpich

0 comments on commit a70e0a7

Please sign in to comment.