Skip to content

Commit 45761e4

Browse files
committed
refactored modify_env_file and custom_spack_env to refer to ../../configs/config.yaml
1 parent 7d8517b commit 45761e4

1 file changed

Lines changed: 38 additions & 28 deletions

File tree

scripts/devtools/tpl-manager.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def find_all_spack_packages(self, packages, req=True):
173173
def modify_env_file(self, env_file, mod_func):
174174
"Modify the spack.yaml file"
175175
from spack.util import spack_yaml
176-
# Load the spack.yaml file
176+
import re
177177
with open(env_file) as ff:
178178
try:
179179
loader = spack_yaml.load(ff)
@@ -183,50 +183,62 @@ def modify_env_file(self, env_file, mod_func):
183183
with open(env_file, 'w') as ff:
184184
spack_yaml.dump(loader, ff)
185185

186+
# Fixup spack.yaml include:: list
187+
#
188+
# Spack's YAML dumper automatically quotes 'include::' because '::'
189+
# is special in YAML, but Spack requires it to be unquoted to recognize the
190+
# include directive
191+
with open(env_file, 'r') as ff:
192+
content = ff.read()
193+
content = re.sub(r" '['\"]?include:+['\"]?:", " include::", content)
194+
195+
with open(env_file, 'w') as ff:
196+
ff.write(content)
197+
186198
def custom_spack_env(self, env_name):
187199
"Use/create a custom Spack environment"
188200
from spack import environment
189201
if (not self.args.spec):
190202
raise Exception("Must supply a --spec for a custom environment (IE --spec spheral+mpi%gcc)")
191203
env_file = os.path.join(self.env_dir, "spack.yaml")
192204
if (not os.path.exists(env_file)):
205+
# Create a new environment
193206
env_cmd = SpackCommand("env")
194207
env_cmd("create", "--without-view", "-d", self.env_dir)
208+
195209
def set_concretize(loader):
196-
loader["spack"].update({
197-
"concretizer": {"unify": False},
198-
"config": {
199-
"install_tree": {"padded_length": 128},
200-
"misc_cache": "$spack/../misc_cache",
201-
"test_stage": "$spack/../test_stage",
202-
"build_stage": ["$spack/../build_stage"]
210+
develop_dict = {}
211+
repos_list = []
212+
213+
for package, path in package_dirs.items():
214+
repo_path = os.path.abspath(os.path.join(get_config_dir(path), f"spack_repo/{package}"))
215+
repos_list.append(repo_path)
216+
dev_path = os.path.abspath(path)
217+
develop_dict[package] = {
218+
"path": dev_path,
219+
"spec": f"{package}@=develop"
203220
}
204-
})
205-
if "repos" not in loader["spack"]:
206-
loader["spack"]["repos"] = {}
207-
loader["spack"]["repos"]["builtin"] = {
208-
"destination": "$spack/../packages",
209-
"git": "https://github.com/spack/spack-packages.git",
210-
"commit": "0f833a16999a012153c040c26c98256c14a1a4fd"
221+
222+
loader["spack"]["concretizer"] = {
223+
"unify": False,
224+
"reuse": False,
225+
"compiler_mixing": False
211226
}
227+
loader["spack"]["develop"] = develop_dict
228+
loader["spack"]["include::"] = [
229+
"../../configs/config.yaml"
230+
]
231+
loader["spack"]["repos"] = repos_list
232+
212233
return loader
234+
213235
self.modify_env_file(env_file, set_concretize)
236+
214237
self.spack_env = environment.Environment(self.env_dir)
215238
environment.activate(self.spack_env)
216-
# Get all the Spack commands
217-
repo_cmd = SpackCommand("repo")
218-
dev_cmd = SpackCommand("develop")
219239
comp_cmd = SpackCommand("compiler")
220240
ext_cmd = SpackCommand("external")
221-
cur_repos = repo_cmd("list") # spack repo list
222241

223-
# Add the repos and develop paths to the spack environment
224-
for package, path in package_dirs.items():
225-
if (package+" " not in cur_repos):
226-
repo_path = os.path.abspath(os.path.join(get_config_dir(path), f"spack_repo/{package}"))
227-
repo_cmd("add", f"{repo_path}") # spack repo add <repo_path>
228-
dev_path = os.path.abspath(path)
229-
dev_cmd("-p", dev_path, f"{package}@=develop") # spack develop <package>@=develop
230242
comp_cmd("find") # spack compiler find
231243
ext_cmd("find") # spack external find
232244
provider_dict = {}
@@ -252,11 +264,9 @@ def set_concretize(loader):
252264
opt_packages = ["hdf5", "ncurses"]
253265
for i in opt_packages:
254266
self.find_spack_package(i, req=False)
255-
# Hard-coding providers for these packages vastly improves TPL system
256267
provider_dict.update({"zlib-api": ["zlib"],
257268
"blas": ["openblas"],
258269
"lapack": ["openblas"]})
259-
# Always add the spec for a custom environment
260270
if (provider_dict):
261271
self.config_env_providers(provider_dict)
262272
self.args.add_spec = True

0 commit comments

Comments
 (0)