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 2021-03-26 08:16:11 +01:00 committed by GitHub
parent 728f62ec8d
commit 0bed64503d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 16 deletions

View File

@ -241,11 +241,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:
self._raw_data = read_config_file(self.path, self.schema)
if self._raw_data is 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
for key in self.yaml_path:
if section_data is None:
@ -254,6 +261,7 @@ def get_section(self, section):
for section_key, data in section_data.items():
self.sections[section_key] = {section_key: data}
return self.sections.get(section, None)
def _write_section(self, section):

View File

@ -73,6 +73,25 @@ def _write(config, data, scope):
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):
"""Check that named compilers in comps match Spack's config."""
config = spack.config.get('compilers')
@ -861,23 +880,10 @@ def test_immutable_scope(tmpdir):
scope._write_section('config')
def test_single_file_scope(tmpdir, config):
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
""")
def test_single_file_scope(config, env_yaml):
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):
# from the single-file config
@ -1109,3 +1115,20 @@ def test_bad_path_double_override(config):
match='Meaningless second override'):
with spack.config.override('bad::double:override::directive', ''):
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