diff options
author | Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> | 2020-09-03 05:37:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 14:37:24 +0200 |
commit | 84381fbc80203aff14ee771cda77255721dd1859 (patch) | |
tree | 4ee20f4f107bba7e9f262329dd5e0488f2d1404b /lib | |
parent | 3a562c0cecc45a4cee787b12b4376c7670415131 (diff) | |
download | spack-84381fbc80203aff14ee771cda77255721dd1859.tar.gz spack-84381fbc80203aff14ee771cda77255721dd1859.tar.bz2 spack-84381fbc80203aff14ee771cda77255721dd1859.tar.xz spack-84381fbc80203aff14ee771cda77255721dd1859.zip |
Bugfix: terminate if a spack.yaml include path does not exist (#18074)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/environment.py | 11 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/env.py | 22 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index ef9112a684..01f8f0a52b 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -812,6 +812,7 @@ class Environment(object): # load config scopes added via 'include:', in reverse so that # highest-precedence scopes are last. includes = config_dict(self.yaml).get('include', []) + missing = [] for i, config_path in enumerate(reversed(includes)): # allow paths to contain spack config/environment variables, etc. config_path = substitute_path_variables(config_path) @@ -826,15 +827,23 @@ class Environment(object): config_name = 'env:%s:%s' % ( self.name, os.path.basename(config_path)) scope = spack.config.ConfigScope(config_name, config_path) - else: + elif os.path.exists(config_path): # files are assumed to be SingleFileScopes base, ext = os.path.splitext(os.path.basename(config_path)) config_name = 'env:%s:%s' % (self.name, base) scope = spack.config.SingleFileScope( config_name, config_path, spack.schema.merged.schema) + else: + missing.append(config_path) + continue scopes.append(scope) + if missing: + msg = 'Detected {0} missing include path(s):'.format(len(missing)) + msg += '\n {0}'.format('\n '.join(missing)) + tty.die('{0}\nPlease correct and try again.'.format(msg)) + return scopes def env_file_config_scope_name(self): diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 26f0a10681..b7aa02e607 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -525,6 +525,28 @@ env: for x in e._get_environment_specs()) +def test_with_config_bad_include(env_deactivate, capfd): + env_name = 'test_bad_include' + test_config = """\ +spack: + include: + - /no/such/directory + - no/such/file.yaml +""" + _env_create(env_name, StringIO(test_config)) + + e = ev.read(env_name) + with pytest.raises(SystemExit): + with e: + e.concretize() + + out, err = capfd.readouterr() + + assert 'missing include' in err + assert '/no/such/directory' in err + assert 'no/such/file.yaml' in err + + def test_env_with_included_config_file(): test_config = """\ env: |