environment modifications : permit to pass parameters along with file to be sourced (#1626)
This commit is contained in:
parent
949766d92e
commit
eb17895630
@ -271,8 +271,12 @@ def from_sourcing_files(*args, **kwargs):
|
|||||||
|
|
||||||
env = EnvironmentModifications()
|
env = EnvironmentModifications()
|
||||||
# Check if the files are actually there
|
# Check if the files are actually there
|
||||||
if not all(os.path.isfile(file) for file in args):
|
files = [line.split(' ')[0] for line in args]
|
||||||
raise RuntimeError('trying to source non-existing files')
|
non_existing = [file for file in files if not os.path.isfile(file)]
|
||||||
|
if non_existing:
|
||||||
|
message = 'trying to source non-existing files\n'
|
||||||
|
message += '\n'.join(non_existing)
|
||||||
|
raise RuntimeError(message)
|
||||||
# Relevant kwd parameters and formats
|
# Relevant kwd parameters and formats
|
||||||
info = dict(kwargs)
|
info = dict(kwargs)
|
||||||
info.setdefault('shell', '/bin/bash')
|
info.setdefault('shell', '/bin/bash')
|
||||||
|
7
lib/spack/spack/test/data/sourceme_parameters.sh
Normal file
7
lib/spack/spack/test/data/sourceme_parameters.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ "$1" == "intel64" ]] ; then
|
||||||
|
export FOO='intel64'
|
||||||
|
else
|
||||||
|
export FOO='default'
|
||||||
|
fi
|
@ -119,7 +119,8 @@ def test_source_files(self):
|
|||||||
'spack', 'test', 'data')
|
'spack', 'test', 'data')
|
||||||
files = [
|
files = [
|
||||||
join_path(datadir, 'sourceme_first.sh'),
|
join_path(datadir, 'sourceme_first.sh'),
|
||||||
join_path(datadir, 'sourceme_second.sh')
|
join_path(datadir, 'sourceme_second.sh'),
|
||||||
|
join_path(datadir, 'sourceme_parameters.sh intel64')
|
||||||
]
|
]
|
||||||
env = EnvironmentModifications.from_sourcing_files(*files)
|
env = EnvironmentModifications.from_sourcing_files(*files)
|
||||||
modifications = env.group_by_name()
|
modifications = env.group_by_name()
|
||||||
@ -134,6 +135,11 @@ def test_source_files(self):
|
|||||||
self.assertEqual(len(modifications['NEW_VAR']), 1)
|
self.assertEqual(len(modifications['NEW_VAR']), 1)
|
||||||
self.assertTrue(isinstance(modifications['NEW_VAR'][0], SetEnv))
|
self.assertTrue(isinstance(modifications['NEW_VAR'][0], SetEnv))
|
||||||
self.assertEqual(modifications['NEW_VAR'][0].value, 'new')
|
self.assertEqual(modifications['NEW_VAR'][0].value, 'new')
|
||||||
|
|
||||||
|
self.assertEqual(len(modifications['FOO']), 1)
|
||||||
|
self.assertTrue(isinstance(modifications['FOO'][0], SetEnv))
|
||||||
|
self.assertEqual(modifications['FOO'][0].value, 'intel64')
|
||||||
|
|
||||||
# Unset variables
|
# Unset variables
|
||||||
self.assertEqual(len(modifications['EMPTY_PATH_LIST']), 1)
|
self.assertEqual(len(modifications['EMPTY_PATH_LIST']), 1)
|
||||||
self.assertTrue(isinstance(
|
self.assertTrue(isinstance(
|
||||||
|
Loading…
Reference in New Issue
Block a user