Respect custom user store when bootstrapping (#39001)
The user store is lazily evaluated. The change in #38975 made it such that the first evaluation was happening in the middle of swapping to user configuration. Ensure we construct the user store before that.
This commit is contained in:
parent
01167a1471
commit
3a565c66e9
3 changed files with 26 additions and 1 deletions
|
@ -150,6 +150,7 @@ def _add_compilers_if_missing() -> None:
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _ensure_bootstrap_configuration() -> Generator:
|
def _ensure_bootstrap_configuration() -> Generator:
|
||||||
|
spack.store.ensure_singleton_created()
|
||||||
bootstrap_store_path = store_path()
|
bootstrap_store_path = store_path()
|
||||||
user_configuration = _read_and_sanitize_configuration()
|
user_configuration = _read_and_sanitize_configuration()
|
||||||
with spack.environment.no_active_environment():
|
with spack.environment.no_active_environment():
|
||||||
|
|
|
@ -326,6 +326,11 @@ def specfile_matches(filename: str, **kwargs) -> List["spack.spec.Spec"]:
|
||||||
return spack.store.find(query, **kwargs)
|
return spack.store.find(query, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_singleton_created() -> None:
|
||||||
|
"""Ensures the lazily evaluated singleton is created"""
|
||||||
|
_ = STORE.db
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def use_store(
|
def use_store(
|
||||||
path: Union[str, pathlib.Path], extra_data: Optional[Dict[str, Any]] = None
|
path: Union[str, pathlib.Path], extra_data: Optional[Dict[str, Any]] = None
|
||||||
|
@ -349,7 +354,7 @@ def use_store(
|
||||||
data.update(extra_data)
|
data.update(extra_data)
|
||||||
|
|
||||||
# Swap the store with the one just constructed and return it
|
# Swap the store with the one just constructed and return it
|
||||||
_ = STORE.db
|
ensure_singleton_created()
|
||||||
spack.config.config.push_scope(
|
spack.config.config.push_scope(
|
||||||
spack.config.InternalConfigScope(name=scope_name, data={"config": {"install_tree": data}})
|
spack.config.InternalConfigScope(name=scope_name, data={"config": {"install_tree": data}})
|
||||||
)
|
)
|
||||||
|
|
|
@ -47,6 +47,25 @@ def test_store_padding_length_is_zero_during_bootstrapping(mutable_config, tmpdi
|
||||||
assert spack.config.config.get("config:install_tree:padded_length") == 512
|
assert spack.config.config.get("config:install_tree:padded_length") == 512
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.regression("38963")
|
||||||
|
def test_install_tree_customization_is_respected(mutable_config, tmp_path):
|
||||||
|
"""Tests that a custom user store is respected when we exit the bootstrapping
|
||||||
|
environment.
|
||||||
|
"""
|
||||||
|
spack.store.reinitialize()
|
||||||
|
store_dir = tmp_path / "store"
|
||||||
|
spack.config.config.set("config:install_tree:root", str(store_dir))
|
||||||
|
with spack.bootstrap.ensure_bootstrap_configuration():
|
||||||
|
assert spack.store.STORE.root == spack.bootstrap.config.store_path()
|
||||||
|
assert (
|
||||||
|
spack.config.config.get("config:install_tree:root")
|
||||||
|
== spack.bootstrap.config.store_path()
|
||||||
|
)
|
||||||
|
assert spack.config.config.get("config:install_tree:padded_length") == 0
|
||||||
|
assert spack.config.config.get("config:install_tree:root") == str(store_dir)
|
||||||
|
assert spack.store.STORE.root == str(store_dir)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"config_value,expected",
|
"config_value,expected",
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in a new issue