Skip to content

Commit 17bd98d

Browse files
committed
Switched setting the MPI provider to just adding the mpi package onto the spec for custom environments
1 parent 2995685 commit 17bd98d

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

scripts/devtools/tpl-manager.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,12 @@ def custom_spack_env(self, env_dir, env_name):
159159
if (not self.args.spec):
160160
raise Exception("Must supply a --spec for a custom environment")
161161

162-
cur_env_dir = os.path.join(env_dir, env_name)
163-
if (not os.path.exists(os.path.join(cur_env_dir, "spack.yaml"))):
162+
if (not os.path.exists(os.path.join(env_dir, "spack.yaml"))):
164163
# Create a new environment
165164
env_cmd = SpackCommand("env")
166-
env_cmd("create", "--without-view", "-d", cur_env_dir)
165+
env_cmd("create", "--without-view", "-d", env_dir)
167166

168-
self.spack_env = environment.Environment(cur_env_dir)
167+
self.spack_env = environment.Environment(env_dir)
169168
environment.activate(self.spack_env)
170169
# Get all the Spack commands
171170
repo_cmd = SpackCommand("repo")
@@ -194,12 +193,8 @@ def custom_spack_env(self, env_dir, env_name):
194193
if (not spack.spec.Spec(self.args.spec).satisfies("~mpi")):
195194
mpi_packages = ["mpich", "openmpi"]
196195
mpi_pack = self.find_spack_package(mpi_packages)
197-
# Modify the providers to ensure the MPI package is being used
198-
def set_provider(loader):
199-
new_data = {"all": {"providers": {"mpi": [mpi_pack]}}}
200-
loader["spack"]["packages"].update(new_data)
201-
return loader
202-
self.modify_env_file(env_dir, set_provider)
196+
if (f"^{mpi_pack}" not in self.args.spec):
197+
self.args.spec += f"^{mpi_pack}"
203198
# Always add the spec for a custom environment
204199
self.args.add_spec = True
205200

@@ -225,22 +220,23 @@ def do_remove(loader):
225220

226221
def activate_spack_env(self):
227222
"Activates a Spack environment or creates and activates one when necessary"
228-
env_dir = os.path.join(get_config_dir(base_dir), "environments")
223+
config_env_dir = os.path.join(get_config_dir(base_dir), "environments")
229224
# Check if we are on an LC machine and the environment exists
230225
default_env = os.getenv("SYS_TYPE")
231-
if default_env and os.path.exists(os.path.join(env_dir, default_env)):
226+
if default_env and os.path.exists(os.path.join(config_env_dir, default_env)):
232227
# For LC systems
233-
cur_env_dir = os.path.join(env_dir, default_env)
234-
print(f"Activating Spack environment in {cur_env_dir}")
228+
env_dir = os.path.join(config_env_dir, default_env)
229+
print(f"Activating Spack environment in {env_dir}")
235230
if self.args.no_upstream:
236-
self.remove_upstream(cur_env_dir)
231+
self.remove_upstream(env_dir)
237232
from spack import environment
238-
self.spack_env = environment.Environment(cur_env_dir)
233+
self.spack_env = environment.Environment(env_dir)
239234
environment.activate(self.spack_env)
240235
else:
241236
# Otherwise, check if environment has been created
242237
arch_cmd = SpackCommand("arch")
243238
env_name = arch_cmd().strip()
239+
env_dir = os.path.join(config_env_dir, env_name)
244240
self.custom_spack_env(env_dir, env_name)
245241

246242
def concretize_spec(self):

0 commit comments

Comments
 (0)