Skip to content

Commit

Permalink
#2: introduce !extend yaml tag to extend lists in config
Browse files Browse the repository at this point in the history
  • Loading branch information
tlamonthezie committed Sep 30, 2024
1 parent 184a527 commit 090f1e0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
14 changes: 7 additions & 7 deletions ci/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ setup:
CXX: mpicxx
GCOV: llvm-gcov
deps:
packages: [ *apk-packages, clang, clang-dev ]
packages: !extend [ *apk-packages, clang, clang-dev ]
mpich: ['3.3.2', '-j4', '', 'clang', 'clang++']

#vt
Expand All @@ -77,8 +77,8 @@ setup:
GCOV: gcov
# deps and versions to find in vt
deps:
packages: [ *apt-packages, gcc-9, g++-9]
cmake: *cmake-args
packages: !extend [*apt-packages, gcc-9, g++-9]
cmake: *cmake-args # 3.23.4 in vt but seems to be an error with vtk tiff build because error in Cmake CheckSize.
openmpi: *openmpi-args
zoltan: *zoltan-args
mpich: *mpich-args
Expand Down Expand Up @@ -110,7 +110,7 @@ setup:
CXX: g++-13
GCOV: gcov
deps:
packages: [ *apt-packages, gcc-13, g++-13 ]
packages: !extend [ *apt-packages, gcc-13, g++-13 ]
mesa: ~
conda: ~
conda-python-env: *conda-py3-all
Expand All @@ -124,7 +124,7 @@ setup:
CXX: g++-12
GCOV: gcov
deps:
packages: [ *apt-packages, gcc-12, g++-12 ]
packages: !extend [ *apt-packages, gcc-12, g++-12 ]
mesa: ~
conda: ~
conda-python-env: *conda-py3-all
Expand All @@ -138,7 +138,7 @@ setup:
CXX: g++-11
GCOV: gcov
deps:
packages: [*apt-packages, gcc-11, g++-11 ]
packages: !extend [*apt-packages, gcc-11, g++-11 ]
mesa: ~
conda: ~
conda-python-env: *conda-py3-all
Expand All @@ -152,7 +152,7 @@ setup:
CXX: g++-11
GCOV: gcov
deps:
packages: [*apt-packages, gcc-11, g++-11 ]
packages: !extend [*apt-packages, gcc-11, g++-11 ]
mesa: ~
conda: ~
conda-python-env: *conda-py3-all
Expand Down
36 changes: 26 additions & 10 deletions ci/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
"""Utility methods
"""

import copy
from typing import Union

import yaml


# < YAML custom tags
def yaml_list_extend_loader(loader, node):
"""Loads a YAML sequence node defining a list to extend and the elements to add"""
if not isinstance(node, yaml.SequenceNode):
raise RuntimeError("!extend only applicable to sequences")
params = loader.construct_sequence(node)
if not isinstance(params[0], list):
raise RuntimeError("!extend first argument must be a list")

l: list = copy.deepcopy(params[0])
if len(params) > 1:
for p in params[1:]:
if not isinstance(p, list):
l.extend([p])
else:
l.extend(p)
return l

# Required for safe_load
yaml.SafeLoader.add_constructor("!extend", yaml_list_extend_loader)
# > YAML custom tags

def resolve_conf(config: Union[dict,list]) -> dict:
"""Update configuration to ease its processing:
- Turn images list into a dict (images indexed by `repo:tag`)
Expand All @@ -29,16 +55,6 @@ def resolve_conf(config: Union[dict,list]) -> dict:
if not isinstance(args, list):
setup["deps"][dep_id] = [ args ]

# flatten package dependencies
if setup["deps"].get("packages") is not None:
flattened_args = []
for (_, arg) in enumerate(setup["deps"].get("packages")):
if isinstance(arg, list):
flattened_args.extend(arg)
else:
flattened_args.append(arg)
setup["deps"]["packages"] = flattened_args

# Index Docker images by their full name
config["images"] = dict((image.get("repository") + ":" + image.get("tag"), image)
for image in config.get("images"))
Expand Down

0 comments on commit 090f1e0

Please sign in to comment.