diff options
author | Joseph Ciurej <ciurej1@llnl.gov> | 2020-06-09 16:57:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 16:57:27 -0700 |
commit | 9a18fbbc3ede80d52bd70a984961728e0909cd86 (patch) | |
tree | a9cd6a1778ce3cea545fe2107100536a8b567670 | |
parent | 31791f269b16e2f4c2b6e442fc4890dab1998279 (diff) | |
download | spack-9a18fbbc3ede80d52bd70a984961728e0909cd86.tar.gz spack-9a18fbbc3ede80d52bd70a984961728e0909cd86.tar.bz2 spack-9a18fbbc3ede80d52bd70a984961728e0909cd86.tar.xz spack-9a18fbbc3ede80d52bd70a984961728e0909cd86.zip |
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.
-rw-r--r-- | lib/spack/spack/environment.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/env.py | 30 |
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 00af2df2d9..1b9df358f4 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -37,6 +37,7 @@ from spack.spec import Spec 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 @@ class Environment(object): # 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): diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index f8ed37e17c..5703738731 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -22,6 +22,7 @@ from spack.stage import stage_prefix 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 @@ packages: 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: |