7 from AthenaCommon
import Logging, PropertyProxy
12 __author__ =
'Wim Lavrijsen (WLavrijsen@lbl.gov)'
14 __all__ = [
'ConfigurableMeta' ]
18 log = Logging.logging.getLogger(
'ConfigurableMeta' )
23 """The setting of Gaudi component properties needs to be deferred and
24 history of who set what where needs to be collected. This is done
25 by using PropertyProxy descriptors rather than the default ones."""
29 if 'getType' in dct
and not isinstance( dct[
'getType' ], classmethod ):
30 dct[
'getType' ] = classmethod( dct[
'getType' ] )
32 if 'setDefaults' in dct
and not isinstance( dct[
'setDefaults' ], classmethod ):
33 dct[
'setDefaults' ] = classmethod( dct[
'setDefaults' ] )
38 newclass = type.__new__( self, name, bases, dct )
40 if 'AthenaCommon' not in newclass.__module__:
43 meths = {
'getDlls' : 1,
48 for meth, nArgs
in meths.items():
50 f = getattr( newclass, meth )
51 except AttributeError:
52 raise NotImplementedError(
"%s is missing in class %s" % (meth,
str(newclass)))
55 nargcount = f.__code__.co_argcount
56 dflts = f.__defaults__
57 ndefaults = dflts
and len(dflts)
or 0
58 if not nargcount - ndefaults <= nArgs <= nargcount:
59 raise TypeError(
"%s.%s requires exactly %d arguments" % (newclass,meth,nArgs))
62 newclass.configurables = weakref.WeakValueDictionary()
66 slots = dct.get(
'__slots__' )
68 props = [ x
for x
in slots
if x[0] !=
'_' ]
69 propDict = dct.get(
'_propertyDocDct')
71 docString = propDict
and propDict.get(prop)
72 if type(slots)
is dict:
76 proxy = PropertyProxy.PropertyProxyFactory(
77 getattr( newclass, prop ), docString, default )
79 properties[ prop ] = proxy
80 setattr( newclass, prop, proxy )
85 bprops = base._properties.copy()
86 bprops.update( properties )
88 except AttributeError:
91 newclass._properties = properties
96 """To Gaudi, any object with the same type/name is the same object. Hence,
97 this is mimicked in the configuration: instantiating a new Configurable
98 of a type with the same name will return the same instance."""
102 cfg = cls.__new__( cls, *args, **kwargs )
105 if cfg
and (
not hasattr(cfg,
'_fInitOk')
or not cfg._fInitOk ):
106 cls.__init__( cfg, *args, **kwargs )