Make BaseConfiguration pickleable (#47545)
Signed-off-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
parent
9bcd86071f
commit
a3645fd372
@ -330,18 +330,17 @@ class BaseConfiguration:
|
|||||||
default_projections = {"all": "{name}/{version}-{compiler.name}-{compiler.version}"}
|
default_projections = {"all": "{name}/{version}-{compiler.name}-{compiler.version}"}
|
||||||
|
|
||||||
def __init__(self, spec: spack.spec.Spec, module_set_name: str, explicit: bool) -> None:
|
def __init__(self, spec: spack.spec.Spec, module_set_name: str, explicit: bool) -> None:
|
||||||
# Module where type(self) is defined
|
|
||||||
m = inspect.getmodule(self)
|
|
||||||
assert m is not None # make mypy happy
|
|
||||||
self.module = m
|
|
||||||
# Spec for which we want to generate a module file
|
# Spec for which we want to generate a module file
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
self.name = module_set_name
|
self.name = module_set_name
|
||||||
self.explicit = explicit
|
self.explicit = explicit
|
||||||
# Dictionary of configuration options that should be applied
|
# Dictionary of configuration options that should be applied to the spec
|
||||||
# to the spec
|
|
||||||
self.conf = merge_config_rules(self.module.configuration(self.name), self.spec)
|
self.conf = merge_config_rules(self.module.configuration(self.name), self.spec)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def module(self):
|
||||||
|
return inspect.getmodule(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def projections(self):
|
def projections(self):
|
||||||
"""Projection from specs to module names"""
|
"""Projection from specs to module names"""
|
||||||
@ -775,10 +774,6 @@ def __init__(
|
|||||||
) -> None:
|
) -> None:
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
|
|
||||||
# This class is meant to be derived. Get the module of the
|
|
||||||
# actual writer.
|
|
||||||
self.module = inspect.getmodule(self)
|
|
||||||
assert self.module is not None # make mypy happy
|
|
||||||
m = self.module
|
m = self.module
|
||||||
|
|
||||||
# Create the triplet of configuration/layout/context
|
# Create the triplet of configuration/layout/context
|
||||||
@ -816,6 +811,10 @@ def __init__(
|
|||||||
name = type(self).__name__
|
name = type(self).__name__
|
||||||
raise ModulercHeaderNotDefined(msg.format(name))
|
raise ModulercHeaderNotDefined(msg.format(name))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def module(self):
|
||||||
|
return inspect.getmodule(self)
|
||||||
|
|
||||||
def _get_template(self):
|
def _get_template(self):
|
||||||
"""Gets the template that will be rendered for this spec."""
|
"""Gets the template that will be rendered for this spec."""
|
||||||
# Get templates and put them in the order of importance:
|
# Get templates and put them in the order of importance:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
import os
|
import os
|
||||||
|
import pickle
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -223,3 +224,10 @@ def test_check_module_set_name(mutable_config):
|
|||||||
|
|
||||||
with pytest.raises(spack.error.ConfigError, match=msg):
|
with pytest.raises(spack.error.ConfigError, match=msg):
|
||||||
spack.cmd.modules.check_module_set_name("third")
|
spack.cmd.modules.check_module_set_name("third")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("module_type", ["tcl", "lmod"])
|
||||||
|
def test_module_writers_are_pickleable(default_mock_concretization, module_type):
|
||||||
|
s = default_mock_concretization("mpileaks")
|
||||||
|
writer = spack.modules.module_types[module_type](s, "default")
|
||||||
|
assert pickle.loads(pickle.dumps(writer)).spec == s
|
||||||
|
Loading…
Reference in New Issue
Block a user