summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/environment.py12
-rw-r--r--lib/spack/spack/test/environment.py15
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index fae23335fc..7a9a4735fc 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -581,6 +581,10 @@ class ViewDescriptor(object):
tty.warn(msg)
+def _create_environment(*args, **kwargs):
+ return Environment(*args, **kwargs)
+
+
class Environment(object):
def __init__(self, path, init_file=None, with_view=None, keep_relative=False):
"""Create a new environment.
@@ -601,6 +605,9 @@ class Environment(object):
directory.
"""
self.path = os.path.abspath(path)
+ self.init_file = init_file
+ self.with_view = with_view
+ self.keep_relative = keep_relative
self.txlock = lk.Lock(self._transaction_lock_path)
@@ -643,6 +650,11 @@ class Environment(object):
# If with_view is None, then defer to the view settings determined by
# the manifest file
+ def __reduce__(self):
+ return _create_environment, (
+ self.path, self.init_file, self.with_view, self.keep_relative
+ )
+
def _rewrite_relative_paths_on_relocation(self, init_file_dir):
"""When initializing the environment from a manifest file and we plan
to store the environment in a different directory, we have to rewrite
diff --git a/lib/spack/spack/test/environment.py b/lib/spack/spack/test/environment.py
new file mode 100644
index 0000000000..145f390b28
--- /dev/null
+++ b/lib/spack/spack/test/environment.py
@@ -0,0 +1,15 @@
+# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+import pickle
+
+from spack.environment import Environment
+
+
+def test_environment_pickle(tmpdir):
+ env1 = Environment(str(tmpdir))
+ obj = pickle.dumps(env1)
+ env2 = pickle.loads(obj)
+ assert isinstance(env2, Environment)