5454import SCons .Subst
5555import SCons .Tool
5656import SCons .Util
57+ from SCons .Util import MethodWrapper
5758import SCons .Warnings
5859
5960class _Null :
@@ -180,48 +181,17 @@ def _delete_duplicates(l, keep_last):
180181# Shannon at the following page (there called the "transplant" class):
181182#
182183# ASPN : Python Cookbook : Dynamically added methods to a class
183- # http ://aspn .activestate.com/ASPN/Cookbook/Python/Recipe/ 81732
184+ # https ://code .activestate.com/recipes/ 81732/
184185#
185186# We had independently been using the idiom as BuilderWrapper, but
186187# factoring out the common parts into this base class, and making
187188# BuilderWrapper a subclass that overrides __call__() to enforce specific
188189# Builder calling conventions, simplified some of our higher-layer code.
190+ #
191+ # Note: MethodWrapper moved to SCons.Util as it was needed there
192+ # and otherwise we had a circular import problem.
189193
190- class MethodWrapper :
191- """
192- A generic Wrapper class that associates a method (which can
193- actually be any callable) with an object. As part of creating this
194- MethodWrapper object an attribute with the specified (by default,
195- the name of the supplied method) is added to the underlying object.
196- When that new "method" is called, our __call__() method adds the
197- object as the first argument, simulating the Python behavior of
198- supplying "self" on method calls.
199-
200- We hang on to the name by which the method was added to the underlying
201- base class so that we can provide a method to "clone" ourselves onto
202- a new underlying object being copied (without which we wouldn't need
203- to save that info).
204- """
205- def __init__ (self , object , method , name = None ):
206- if name is None :
207- name = method .__name__
208- self .object = object
209- self .method = method
210- self .name = name
211- setattr (self .object , name , self )
212-
213- def __call__ (self , * args , ** kwargs ):
214- nargs = (self .object ,) + args
215- return self .method (* nargs , ** kwargs )
216-
217- def clone (self , new_object ):
218- """
219- Returns an object that re-binds the underlying "method" to
220- the specified new object.
221- """
222- return self .__class__ (new_object , self .method , self .name )
223-
224- class BuilderWrapper (MethodWrapper ):
194+ class BuilderWrapper (SCons .Util .MethodWrapper ):
225195 """
226196 A MethodWrapper subclass that that associates an environment with
227197 a Builder.
@@ -248,7 +218,7 @@ def __call__(self, target=None, source=_null, *args, **kw):
248218 target = [target ]
249219 if source is not None and not SCons .Util .is_List (source ):
250220 source = [source ]
251- return MethodWrapper .__call__ (self , target , source , * args , ** kw )
221+ return super () .__call__ (target , source , * args , ** kw )
252222
253223 def __repr__ (self ):
254224 return '<BuilderWrapper %s>' % repr (self .name )
@@ -2377,7 +2347,7 @@ def __getattr__(self, name):
23772347 # Environment they are being constructed with and so will not
23782348 # have access to overrided values. So we rebuild them with the
23792349 # OverrideEnvironment so they have access to overrided values.
2380- if isinstance (attr , ( MethodWrapper , BuilderWrapper ) ):
2350+ if isinstance (attr , MethodWrapper ):
23812351 return attr .clone (self )
23822352 else :
23832353 return attr
0 commit comments