@@ -159,13 +159,12 @@ def custom_spack_env(self, env_dir, env_name):
159
159
if (not self .args .spec ):
160
160
raise Exception ("Must supply a --spec for a custom environment" )
161
161
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" ))):
164
163
# Create a new environment
165
164
env_cmd = SpackCommand ("env" )
166
- env_cmd ("create" , "--without-view" , "-d" , cur_env_dir )
165
+ env_cmd ("create" , "--without-view" , "-d" , env_dir )
167
166
168
- self .spack_env = environment .Environment (cur_env_dir )
167
+ self .spack_env = environment .Environment (env_dir )
169
168
environment .activate (self .spack_env )
170
169
# Get all the Spack commands
171
170
repo_cmd = SpackCommand ("repo" )
@@ -194,12 +193,8 @@ def custom_spack_env(self, env_dir, env_name):
194
193
if (not spack .spec .Spec (self .args .spec ).satisfies ("~mpi" )):
195
194
mpi_packages = ["mpich" , "openmpi" ]
196
195
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 } "
203
198
# Always add the spec for a custom environment
204
199
self .args .add_spec = True
205
200
@@ -225,22 +220,23 @@ def do_remove(loader):
225
220
226
221
def activate_spack_env (self ):
227
222
"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" )
229
224
# Check if we are on an LC machine and the environment exists
230
225
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 )):
232
227
# 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 } " )
235
230
if self .args .no_upstream :
236
- self .remove_upstream (cur_env_dir )
231
+ self .remove_upstream (env_dir )
237
232
from spack import environment
238
- self .spack_env = environment .Environment (cur_env_dir )
233
+ self .spack_env = environment .Environment (env_dir )
239
234
environment .activate (self .spack_env )
240
235
else :
241
236
# Otherwise, check if environment has been created
242
237
arch_cmd = SpackCommand ("arch" )
243
238
env_name = arch_cmd ().strip ()
239
+ env_dir = os .path .join (config_env_dir , env_name )
244
240
self .custom_spack_env (env_dir , env_name )
245
241
246
242
def concretize_spec (self ):
0 commit comments