From 84381fbc80203aff14ee771cda77255721dd1859 Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Thu, 3 Sep 2020 05:37:24 -0700 Subject: Bugfix: terminate if a spack.yaml include path does not exist (#18074) --- lib/spack/spack/environment.py | 11 ++++++++++- lib/spack/spack/test/cmd/env.py | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'lib') 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: -- cgit v1.2.3-60-g2f50