Make SingleFileScope able to repopulate the cache after clearing it (#22559)
fixes #22547 SingleFileScope was not able to repopulate its cache before this change. This was affecting the configuration seen by environments using clingo bootstrapped from sources, since the bootstrapping operation involved a few cache invalidation for config files.
This commit is contained in:
		 Massimiliano Culpo
					Massimiliano Culpo
				
			
				
					committed by
					
						 Todd Gamblin
						Todd Gamblin
					
				
			
			
				
	
			
			
			 Todd Gamblin
						Todd Gamblin
					
				
			
						parent
						
							31a07f9bc4
						
					
				
				
					commit
					b11dd0478a
				
			| @@ -240,11 +240,18 @@ def get_section(self, section): | |||||||
|         #      } |         #      } | ||||||
|         #   } |         #   } | ||||||
|         # } |         # } | ||||||
|  | 
 | ||||||
|  |         # This bit ensures we have read the file and have | ||||||
|  |         # the raw data in memory | ||||||
|         if self._raw_data is None: |         if self._raw_data is None: | ||||||
|             self._raw_data = read_config_file(self.path, self.schema) |             self._raw_data = read_config_file(self.path, self.schema) | ||||||
|             if self._raw_data is None: |             if self._raw_data is None: | ||||||
|                 return None |                 return None | ||||||
| 
 | 
 | ||||||
|  |         # Here we know we have the raw data and ensure we | ||||||
|  |         # populate the sections dictionary, which may be | ||||||
|  |         # cleared by the clear() method | ||||||
|  |         if not self.sections: | ||||||
|             section_data = self._raw_data |             section_data = self._raw_data | ||||||
|             for key in self.yaml_path: |             for key in self.yaml_path: | ||||||
|                 if section_data is None: |                 if section_data is None: | ||||||
| @@ -253,6 +260,7 @@ def get_section(self, section): | |||||||
| 
 | 
 | ||||||
|             for section_key, data in section_data.items(): |             for section_key, data in section_data.items(): | ||||||
|                 self.sections[section_key] = {section_key: data} |                 self.sections[section_key] = {section_key: data} | ||||||
|  | 
 | ||||||
|         return self.sections.get(section, None) |         return self.sections.get(section, None) | ||||||
| 
 | 
 | ||||||
|     def _write_section(self, section): |     def _write_section(self, section): | ||||||
|   | |||||||
| @@ -72,6 +72,25 @@ def _write(config, data, scope): | |||||||
|     return _write |     return _write | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.fixture() | ||||||
|  | def env_yaml(tmpdir): | ||||||
|  |     """Return a sample env.yaml for test purposes""" | ||||||
|  |     env_yaml = str(tmpdir.join("env.yaml")) | ||||||
|  |     with open(env_yaml, 'w') as f: | ||||||
|  |         f.write("""\ | ||||||
|  | env: | ||||||
|  |     config: | ||||||
|  |         verify_ssl: False | ||||||
|  |         dirty: False | ||||||
|  |     packages: | ||||||
|  |         libelf: | ||||||
|  |             compiler: [ 'gcc@4.5.3' ] | ||||||
|  |     repos: | ||||||
|  |         - /x/y/z | ||||||
|  | """) | ||||||
|  |     return env_yaml | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def check_compiler_config(comps, *compiler_names): | def check_compiler_config(comps, *compiler_names): | ||||||
|     """Check that named compilers in comps match Spack's config.""" |     """Check that named compilers in comps match Spack's config.""" | ||||||
|     config = spack.config.get('compilers') |     config = spack.config.get('compilers') | ||||||
| @@ -797,23 +816,10 @@ def test_immutable_scope(tmpdir): | |||||||
|         scope._write_section('config') |         scope._write_section('config') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_single_file_scope(tmpdir, config): | def test_single_file_scope(config, env_yaml): | ||||||
|     env_yaml = str(tmpdir.join("env.yaml")) |  | ||||||
|     with open(env_yaml, 'w') as f: |  | ||||||
|         f.write("""\ |  | ||||||
| env: |  | ||||||
|     config: |  | ||||||
|         verify_ssl: False |  | ||||||
|         dirty: False |  | ||||||
|     packages: |  | ||||||
|         libelf: |  | ||||||
|             compiler: [ 'gcc@4.5.3' ] |  | ||||||
|     repos: |  | ||||||
|         - /x/y/z |  | ||||||
| """) |  | ||||||
| 
 |  | ||||||
|     scope = spack.config.SingleFileScope( |     scope = spack.config.SingleFileScope( | ||||||
|         'env', env_yaml, spack.schema.env.schema, ['env']) |         'env', env_yaml, spack.schema.env.schema, ['env'] | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|     with spack.config.override(scope): |     with spack.config.override(scope): | ||||||
|         # from the single-file config |         # from the single-file config | ||||||
| @@ -1045,3 +1051,20 @@ def test_bad_path_double_override(config): | |||||||
|                        match='Meaningless second override'): |                        match='Meaningless second override'): | ||||||
|         with spack.config.override('bad::double:override::directive', ''): |         with spack.config.override('bad::double:override::directive', ''): | ||||||
|             pass |             pass | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @pytest.mark.regression('22547') | ||||||
|  | def test_single_file_scope_cache_clearing(env_yaml): | ||||||
|  |     scope = spack.config.SingleFileScope( | ||||||
|  |         'env', env_yaml, spack.schema.env.schema, ['env'] | ||||||
|  |     ) | ||||||
|  |     # Check that we can retrieve data from the single file scope | ||||||
|  |     before = scope.get_section('config') | ||||||
|  |     assert before | ||||||
|  |     # Clear the cache of the Single file scope | ||||||
|  |     scope.clear() | ||||||
|  |     # Check that the section can be retireved again and it's | ||||||
|  |     # the same as before | ||||||
|  |     after = scope.get_section('config') | ||||||
|  |     assert after | ||||||
|  |     assert before == after | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user