Skip to content

Commit 656c85d

Browse files
committed
WIP: dump
1 parent b400938 commit 656c85d

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

stackinator/builder.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,17 @@ def generate(self, recipe):
309309
# the packages.yaml configuration that will be used when building all environments
310310
# - the system packages.yaml with gcc removed
311311
# - plus additional packages provided by the recipe
312-
global_packages_yaml = yaml.dump(recipe.packages["global"])
312+
313313
global_packages_path = config_path / "packages.yaml"
314314
with global_packages_path.open("w") as fid:
315-
fid.write(global_packages_yaml)
315+
yaml.dump(recipe.packages["global"], fid)
316316

317317
# generate a mirrors.yaml file if build caches have been configured
318318
if recipe.mirror:
319319
dst = config_path / "mirrors.yaml"
320320
self._logger.debug(f"generate the build cache mirror: {dst}")
321321
with dst.open("w") as fid:
322-
fid.write(cache.generate_mirrors_yaml(recipe.mirror))
322+
cache.generate_mirrors_yaml(recipe.mirror, fid)
323323

324324
# Add custom spack package recipes, configured via Spack repos.
325325
# Step 1: copy Spack repos to store_path where they will be used to
@@ -440,7 +440,10 @@ def generate(self, recipe):
440440
compiler_config_path.mkdir(exist_ok=True)
441441
for file, raw in files.items():
442442
with (compiler_config_path / file).open(mode="w") as f:
443-
f.write(raw)
443+
if type(raw) is str:
444+
f.write(raw)
445+
else:
446+
yaml.dump(raw, f)
444447

445448
# generate the makefile and spack.yaml files that describe the environments
446449
environment_files = recipe.environment_files
@@ -479,7 +482,7 @@ def generate(self, recipe):
479482
generate_modules_path = self.path / "modules"
480483
generate_modules_path.mkdir(exist_ok=True)
481484
with (generate_modules_path / "modules.yaml").open("w") as f:
482-
yaml.dump(recipe.modules, f)
485+
yaml.dump(recipe.modules_yaml_data, f)
483486

484487
# write the meta data
485488
meta_path = store_path / "meta"

stackinator/cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def configuration_from_file(file, mount):
4242
return raw
4343

4444

45-
def generate_mirrors_yaml(config):
45+
def generate_mirrors_yaml(config, out):
4646
path = config["path"].as_posix()
4747
mirrors = {
4848
"mirrors": {
@@ -57,4 +57,6 @@ def generate_mirrors_yaml(config):
5757
}
5858
}
5959

60-
return yaml.dump(mirrors, default_flow_style=False)
60+
yaml = YAML()
61+
yaml.default_flow_style = True
62+
yaml.dump(mirrors, out)

stackinator/recipe.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,13 @@ def environment_view_meta(self):
326326

327327
return view_meta
328328

329+
@property
330+
def modules_yaml_data(self):
331+
with self.modules.open() as fid:
332+
raw = yaml.load(fid)
333+
raw["modules"]["default"]["roots"]["tcl"] = (pathlib.Path(self.mount) / "modules").as_posix()
334+
return raw
335+
329336
# creates the self.environments field that describes the full specifications
330337
# for all of the environments sets, grouped in environments, from the raw
331338
# environments.yaml input.
@@ -528,7 +535,7 @@ def compiler_files(self):
528535
files["config"][compiler]["spack.yaml"] = spack_yaml_template.render(config=config)
529536
# compilers/gcc/packages.yaml
530537
if compiler == "gcc":
531-
files["config"][compiler]["packages.yaml"] = yaml.dump(self.packages["gcc"])
538+
files["config"][compiler]["packages.yaml"] = self.packages["gcc"]
532539

533540
return files
534541

stackinator/schema.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
from textwrap import dedent
44

55
import jsonschema
6-
import yaml
6+
from ruamel.yaml import YAML
77

88
from . import root_logger
99

1010
prefix = pathlib.Path(__file__).parent.resolve()
1111

1212

1313
def py2yaml(data, indent):
14-
dump = yaml.dump(data)
14+
yaml = YAML()
15+
from io import StringIO
16+
17+
buffer = StringIO()
18+
yaml.dump(data, buffer)
19+
dump = buffer.getvalue()
1520
lines = [ln for ln in dump.split("\n") if ln != ""]
1621
res = ("\n" + " " * indent).join(lines)
1722
return res

0 commit comments

Comments
 (0)