lib/spack : expand spack config vars in 'include' section (#16210)

* Changed the 'include' config section to use 'substitute_path_variables' to allow for Spack config variables to be used (e.g. $spack).

* Fixed a bug with 'include' section path expansion and added a test case for 'include' paths with embedded config variables.
This commit is contained in:
Joseph Ciurej 2020-06-09 16:57:27 -07:00 committed by GitHub
parent 31791f269b
commit 9a18fbbc3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -37,6 +37,7 @@
from spack.spec_list import SpecList, InvalidSpecConstraintError
from spack.variant import UnknownVariantError
import spack.util.lock as lk
from spack.util.path import substitute_path_variables
#: environment variable used to indicate the active environment
spack_env_var = 'SPACK_ENV'
@ -780,8 +781,8 @@ def included_config_scopes(self):
# highest-precedence scopes are last.
includes = config_dict(self.yaml).get('include', [])
for i, config_path in enumerate(reversed(includes)):
# allow paths to contain environment variables
config_path = config_path.format(**os.environ)
# allow paths to contain spack config/environment variables, etc.
config_path = substitute_path_variables(config_path)
# treat relative paths as relative to the environment
if not os.path.isabs(config_path):

View File

@ -22,6 +22,7 @@
from spack.spec_list import SpecListError
from spack.util.mock_package import MockPackageMultiRepo
import spack.util.spack_json as sjson
from spack.util.path import substitute_path_variables
# everything here uses the mock_env_path
@ -539,6 +540,35 @@ def test_env_with_included_config_scope():
for x in e._get_environment_specs())
def test_env_with_included_config_var_path():
config_var_path = os.path.join('$tempdir', 'included-config.yaml')
test_config = """\
env:
include:
- %s
specs:
- mpileaks
""" % config_var_path
_env_create('test', StringIO(test_config))
e = ev.read('test')
config_real_path = substitute_path_variables(config_var_path)
fs.mkdirp(os.path.dirname(config_real_path))
with open(config_real_path, 'w') as f:
f.write("""\
packages:
mpileaks:
version: [2.2]
""")
with e:
e.concretize()
assert any(x.satisfies('mpileaks@2.2')
for x in e._get_environment_specs())
def test_env_config_precedence():
test_config = """\
env: