Skip to content

Commit f92a64c

Browse files
committed
WIP: brutal solution for different dump API
if we decide it is worth switching, i'm going to deal with this properly with the needed (small) refactoring
1 parent 879f878 commit f92a64c

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

stackinator/builder.py

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

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

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

444447
# generate the makefile and spack.yaml files that describe the environments
445448
environment_files = recipe.environment_files
@@ -473,11 +476,10 @@ def generate(self, recipe):
473476
)
474477

475478
# write modules/modules.yaml
476-
modules_yaml = recipe.modules_yaml
477479
generate_modules_path = self.path / "modules"
478480
generate_modules_path.mkdir(exist_ok=True)
479481
with (generate_modules_path / "modules.yaml").open("w") as f:
480-
f.write(modules_yaml)
482+
yaml.dump(recipe.modules_yaml_data, f)
481483

482484
# write the meta data
483485
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ def environment_view_meta(self):
315315
return view_meta
316316

317317
@property
318-
def modules_yaml(self):
318+
def modules_yaml_data(self):
319319
with self.modules.open() as fid:
320320
raw = yaml.load(fid)
321321
raw["modules"]["default"]["roots"]["tcl"] = (pathlib.Path(self.mount) / "modules").as_posix()
322-
return yaml.dump(raw)
322+
return raw
323323

324324
# creates the self.environments field that describes the full specifications
325325
# for all of the environments sets, grouped in environments, from the raw
@@ -514,7 +514,7 @@ def compiler_files(self):
514514
files["config"][compiler]["spack.yaml"] = spack_yaml_template.render(config=config)
515515
# compilers/gcc/packages.yaml
516516
if compiler == "gcc":
517-
files["config"][compiler]["packages.yaml"] = yaml.dump(self.packages["gcc"])
517+
files["config"][compiler]["packages.yaml"] = self.packages["gcc"]
518518

519519
return files
520520

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)