Bugfix: terminate if a spack.yaml include path does not exist (#18074)
This commit is contained in:
		| @@ -812,6 +812,7 @@ def included_config_scopes(self): | |||||||
|         # load config scopes added via 'include:', in reverse so that |         # load config scopes added via 'include:', in reverse so that | ||||||
|         # highest-precedence scopes are last. |         # highest-precedence scopes are last. | ||||||
|         includes = config_dict(self.yaml).get('include', []) |         includes = config_dict(self.yaml).get('include', []) | ||||||
|  |         missing = [] | ||||||
|         for i, config_path in enumerate(reversed(includes)): |         for i, config_path in enumerate(reversed(includes)): | ||||||
|             # allow paths to contain spack config/environment variables, etc. |             # allow paths to contain spack config/environment variables, etc. | ||||||
|             config_path = substitute_path_variables(config_path) |             config_path = substitute_path_variables(config_path) | ||||||
| @@ -826,15 +827,23 @@ def included_config_scopes(self): | |||||||
|                 config_name = 'env:%s:%s' % ( |                 config_name = 'env:%s:%s' % ( | ||||||
|                     self.name, os.path.basename(config_path)) |                     self.name, os.path.basename(config_path)) | ||||||
|                 scope = spack.config.ConfigScope(config_name, config_path) |                 scope = spack.config.ConfigScope(config_name, config_path) | ||||||
|             else: |             elif os.path.exists(config_path): | ||||||
|                 # files are assumed to be SingleFileScopes |                 # files are assumed to be SingleFileScopes | ||||||
|                 base, ext = os.path.splitext(os.path.basename(config_path)) |                 base, ext = os.path.splitext(os.path.basename(config_path)) | ||||||
|                 config_name = 'env:%s:%s' % (self.name, base) |                 config_name = 'env:%s:%s' % (self.name, base) | ||||||
|                 scope = spack.config.SingleFileScope( |                 scope = spack.config.SingleFileScope( | ||||||
|                     config_name, config_path, spack.schema.merged.schema) |                     config_name, config_path, spack.schema.merged.schema) | ||||||
|  |             else: | ||||||
|  |                 missing.append(config_path) | ||||||
|  |                 continue | ||||||
| 
 | 
 | ||||||
|             scopes.append(scope) |             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 |         return scopes | ||||||
| 
 | 
 | ||||||
|     def env_file_config_scope_name(self): |     def env_file_config_scope_name(self): | ||||||
|   | |||||||
| @@ -525,6 +525,28 @@ def test_env_with_config(): | |||||||
|                for x in e._get_environment_specs()) |                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(): | def test_env_with_included_config_file(): | ||||||
|     test_config = """\ |     test_config = """\ | ||||||
| env: | env: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tamara Dahlgren
					Tamara Dahlgren