@@ -71,11 +71,29 @@ def update(self, other):
71
71
self .eager .update (other )
72
72
73
73
def iteritems (self ):
74
+ """Warning: This forces the evaluation all of the items in this LazyDict
75
+ that are iterated over."""
74
76
for k , v in self .eager .iteritems ():
75
77
yield k , v
76
78
for k in self .lazy .keys ():
77
79
yield k , self [k ]
78
80
81
+ def apply (self , fn ):
82
+ """Delay the application of a computation to all items of the lazy dict.
83
+ Does no computation now. Instead the comuptation is performed when a
84
+ consumer attempts to access a value in this LazyDict"""
85
+ new_lazy = {}
86
+ for k , f in self .lazy .iteritems ():
87
+ def closure (f = f ):
88
+ return fn (f ())
89
+ new_lazy [k ] = closure
90
+ for k , v in self .eager .iteritems ():
91
+ def closure (v = v ):
92
+ return fn (v )
93
+ new_lazy [k ] = closure
94
+ self .lazy = new_lazy
95
+ self .eager = {}
96
+
79
97
class Resources :
80
98
def __init__ (self , base_path = None ):
81
99
self .base_path = base_path
@@ -199,7 +217,9 @@ def relative_to(self, base, dot=False):
199
217
v = [rel_path (f , base , dot ) for f in getattr (self , field )]
200
218
setattr (self , field , v )
201
219
202
- self .features = {k : f .relative_to (base , dot ) for k , f in self .features .iteritems () if f }
220
+ def to_apply (feature , base = base , dot = dot ):
221
+ feature .relative_to (base , dot )
222
+ self .features .apply (to_apply )
203
223
204
224
if self .linker_script is not None :
205
225
self .linker_script = rel_path (self .linker_script , base , dot )
@@ -212,7 +232,9 @@ def win_to_unix(self):
212
232
v = [f .replace ('\\ ' , '/' ) for f in getattr (self , field )]
213
233
setattr (self , field , v )
214
234
215
- self .features = {k : f .win_to_unix () for k , f in self .features .iteritems () if f }
235
+ def to_apply (feature ):
236
+ feature .win_to_unix ()
237
+ self .features .apply (to_apply )
216
238
217
239
if self .linker_script is not None :
218
240
self .linker_script = self .linker_script .replace ('\\ ' , '/' )
0 commit comments