diff --git a/install_spack_env.sh b/install_spack_env.sh index ea3b131f6aedd385bd3e8486acfad710f6c960d2..a4dce99e835ba6a5e803635fd48c6539d99ae77b 100644 --- a/install_spack_env.sh +++ b/install_spack_env.sh @@ -57,8 +57,6 @@ spack env activate $EBRAINS_SPACK_ENV # update environment site-configs rm -rf $SPACK_ENV/site-config && cp -r $EBRAINS_REPO/site-config $SPACK_ENV # update spack.yaml: merge top-level and site-specific spack.yaml files -# TODO: find a more robust way to do this (maybe with yq? but we need to download the binary) -# TODO: or add pyyaml to dependencies and use python script spack-python $EBRAINS_REPO/site-config/ymerge.py $EBRAINS_REPO/spack.yaml $EBRAINS_REPO/site-config/$SYSTEMNAME/spack.yaml > /tmp/spack.yaml cp /tmp/spack.yaml $SPACK_ENV/ diff --git a/site-config/ymerge.py b/site-config/ymerge.py index 23a1f0a62659b87caffe029358b4aae24e93528b..accb877977fd1a95b83ea3ec44179d7928059ae8 100644 --- a/site-config/ymerge.py +++ b/site-config/ymerge.py @@ -1,4 +1,14 @@ -import sys +# spack-python script that merges two environment configuration files (spack.yaml) into one +# Usage: spack-python /path/to/first/spack.yaml /path/to/second/spack.yaml +# (note: if the second file does not exist, the output is the first file + +import sys, os from spack.config import merge_yaml, read_config_file, syaml -print(syaml.dump(merge_yaml(read_config_file(sys.argv[1]), read_config_file(sys.argv[2])))) +if not os.path.exists(sys.argv[2]): + merged = syaml.dump(read_config_file(sys.argv[1])) +else: + merged = syaml.dump(merge_yaml(read_config_file(sys.argv[1]), read_config_file(sys.argv[2]))) + +print(merged) +