Skip to content

Commit 1dfaeac

Browse files
committed
most code changes to allow pickling Spec/Package can be undone now that the spec is passed as a dictionary rather than an object
1 parent 727e70c commit 1dfaeac

File tree

6 files changed

+16
-61
lines changed

6 files changed

+16
-61
lines changed

lib/spack/spack/fetch_strategy.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,14 @@ def mirror_id(self):
214214
"""BundlePackages don't have a mirror id."""
215215

216216

217-
class FetchStrategyComposite(pattern.Composite):
217+
@pattern.composite(interface=FetchStrategy)
218+
class FetchStrategyComposite(object):
218219
"""Composite for a FetchStrategy object.
220+
221+
Implements the GoF composite pattern.
219222
"""
220223
matches = FetchStrategy.matches
221224

222-
def __init__(self):
223-
super(FetchStrategyComposite, self).__init__([
224-
'fetch', 'check', 'expand', 'reset', 'archive', 'cachable',
225-
'mirror_id'
226-
])
227-
228225
def source_id(self):
229226
component_ids = tuple(i.source_id() for i in self)
230227
if all(component_ids):

lib/spack/spack/package.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,6 @@ def _make_resource_stage(self, root_stage, fetcher, resource):
798798
path=self.path)
799799
return stage
800800

801-
def _download_search(self):
802-
dynamic_fetcher = fs.from_list_url(self)
803-
return [dynamic_fetcher] if dynamic_fetcher else []
804-
805801
def _make_root_stage(self, fetcher):
806802
# Construct a mirror path (TODO: get this out of package.py)
807803
mirror_paths = spack.mirror.mirror_archive_paths(
@@ -813,8 +809,12 @@ def _make_root_stage(self, fetcher):
813809
stage_name = "{0}{1}-{2}-{3}".format(stage_prefix, s.name, s.version,
814810
s.dag_hash())
815811

812+
def download_search():
813+
dynamic_fetcher = fs.from_list_url(self)
814+
return [dynamic_fetcher] if dynamic_fetcher else []
815+
816816
stage = Stage(fetcher, mirror_paths=mirror_paths, name=stage_name,
817-
path=self.path, search_fn=self._download_search)
817+
path=self.path, search_fn=download_search)
818818
return stage
819819

820820
def _make_stage(self):

lib/spack/spack/stage.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,19 +648,17 @@ def _add_to_root_stage(self):
648648
install(src, destination_path)
649649

650650

651-
class StageComposite(pattern.Composite):
651+
@pattern.composite(method_list=[
652+
'fetch', 'create', 'created', 'check', 'expand_archive', 'restage',
653+
'destroy', 'cache_local', 'cache_mirror', 'managed_by_spack'])
654+
class StageComposite:
652655
"""Composite for Stage type objects. The first item in this composite is
653656
considered to be the root package, and operations that return a value are
654657
forwarded to it."""
655658
#
656659
# __enter__ and __exit__ delegate to all stages in the composite.
657660
#
658661

659-
def __init__(self):
660-
super(StageComposite, self).__init__([
661-
'fetch', 'create', 'created', 'check', 'expand_archive', 'restage',
662-
'destroy', 'cache_local', 'cache_mirror', 'managed_by_spack'])
663-
664662
def __enter__(self):
665663
for item in self:
666664
item.__enter__()

lib/spack/spack/store.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,10 @@ def _store():
8181
#: Singleton store instance
8282
store = llnl.util.lang.Singleton(_store)
8383

84-
85-
def _store_root():
86-
return store.root
87-
88-
89-
def _store_db():
90-
return store.db
91-
92-
93-
def _store_layout():
94-
return store.layout
95-
96-
9784
# convenience accessors for parts of the singleton store
98-
root = llnl.util.lang.LazyReference(_store_root)
99-
db = llnl.util.lang.LazyReference(_store_db)
100-
layout = llnl.util.lang.LazyReference(_store_layout)
85+
root = llnl.util.lang.LazyReference(lambda: store.root)
86+
db = llnl.util.lang.LazyReference(lambda: store.db)
87+
layout = llnl.util.lang.LazyReference(lambda: store.layout)
10188

10289

10390
def retrieve_upstream_dbs():

lib/spack/spack/util/pattern.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,6 @@
88
import functools
99

1010

11-
class Delegate(object):
12-
def __init__(self, name, container):
13-
self.name = name
14-
self.container = container
15-
16-
def __call__(self, *args, **kwargs):
17-
return [getattr(item, self.name)(*args, **kwargs)
18-
for item in self.container]
19-
20-
21-
class Composite(list):
22-
def __init__(self, fns_to_delegate):
23-
self.fns_to_delegate = fns_to_delegate
24-
25-
def __getattr__(self, name):
26-
if name != 'fns_to_delegate' and name in self.fns_to_delegate:
27-
return Delegate(name, self)
28-
else:
29-
return self.__getattribute__(name)
30-
31-
3211
def composite(interface=None, method_list=None, container=list):
3312
"""Decorator implementing the GoF composite pattern.
3413

lib/spack/spack/util/prefix.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ def join(self, string):
4949
Prefix: the newly created installation prefix
5050
"""
5151
return Prefix(os.path.join(self, string))
52-
53-
def __getstate__(self):
54-
return self.__dict__
55-
56-
def __setstate__(self, d):
57-
self.__dict__.update(d)

0 commit comments

Comments
 (0)