diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2022-06-08 15:17:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-08 07:17:37 -0600 |
commit | d245c464870eb4d8c176233809358e10b7b48b52 (patch) | |
tree | 0fcf150151d62099a0e30faef6ffa8308c274ebf /lib | |
parent | 3eba28e3830012b30a9ff37040903b28b007098c (diff) | |
download | spack-d245c464870eb4d8c176233809358e10b7b48b52.tar.gz spack-d245c464870eb4d8c176233809358e10b7b48b52.tar.bz2 spack-d245c464870eb4d8c176233809358e10b7b48b52.tar.xz spack-d245c464870eb4d8c176233809358e10b7b48b52.zip |
bootstrap: account for disabled sources (#31042)
* bootstrap: account for disabled sources
Fix a bug introduced in #30192, which effectively skips
any prescription on disabled bootstrapping sources.
* Add unit test to avoid regression
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/bootstrap.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/test/bootstrap.py | 17 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py index 20668cf077..26080695ed 100644 --- a/lib/spack/spack/bootstrap.py +++ b/lib/spack/spack/bootstrap.py @@ -456,9 +456,10 @@ def _make_bootstrapper(conf): return _bootstrap_methods[btype](conf) -def _validate_source_is_trusted(conf): +def source_is_enabled_or_raise(conf): + """Raise ValueError if the source is not enabled for bootstrapping""" trusted, name = spack.config.get('bootstrap:trusted'), conf['name'] - if name not in trusted: + if not trusted.get(name, False): raise ValueError('source is not trusted') @@ -529,7 +530,7 @@ def ensure_module_importable_or_raise(module, abstract_spec=None): for current_config in bootstrapping_sources(): with h.forward(current_config['name']): - _validate_source_is_trusted(current_config) + source_is_enabled_or_raise(current_config) b = _make_bootstrapper(current_config) if b.try_import(module, abstract_spec): @@ -571,7 +572,7 @@ def ensure_executables_in_path_or_raise(executables, abstract_spec): for current_config in bootstrapping_sources(): with h.forward(current_config['name']): - _validate_source_is_trusted(current_config) + source_is_enabled_or_raise(current_config) b = _make_bootstrapper(current_config) if b.try_search_path(executables, abstract_spec): diff --git a/lib/spack/spack/test/bootstrap.py b/lib/spack/spack/test/bootstrap.py index fcb3e6418e..183f0bc6f4 100644 --- a/lib/spack/spack/test/bootstrap.py +++ b/lib/spack/spack/test/bootstrap.py @@ -180,3 +180,20 @@ def test_status_function_find_files( _, missing = spack.bootstrap.status_message('optional') assert missing is expected_missing + + +@pytest.mark.regression('31042') +def test_source_is_disabled(mutable_config): + # Get the configuration dictionary of the current bootstrapping source + conf = next(iter(spack.bootstrap.bootstrapping_sources())) + + # The source is not explicitly enabled or disabled, so the following + # call should raise to skip using it for bootstrapping + with pytest.raises(ValueError): + spack.bootstrap.source_is_enabled_or_raise(conf) + + # Try to explicitly disable the source and verify that the behavior + # is the same as above + spack.config.add('bootstrap:trusted:{0}:{1}'.format(conf['name'], False)) + with pytest.raises(ValueError): + spack.bootstrap.source_is_enabled_or_raise(conf) |