@@ -91,16 +91,31 @@ def createSpec(self):
91
91
__confOpts__ = []
92
92
93
93
94
- def configSpec (cls ):
95
- class ConfigSpec (BaseConfig ):
96
- pass
97
-
98
- for k in cls .__dict__ :
99
- if k == '__path__' :
100
- ConfigSpec .__path__ = cls .__path__
101
- if k .startswith ("__" ): continue
102
- v = getattr (cls , k )
103
- d = OptConfig (v )
104
- d .__set_name__ (ConfigSpec , k )
105
- setattr (ConfigSpec , k , d )
106
- return ConfigSpec
94
+ def configSpec (pathOrCls ):
95
+ """ a decorator to help with the generation of the class config spec.
96
+ adds a get and set descriptor for eatch attribute in the config class.
97
+ except the attributes starting with "__".
98
+ params:
99
+ @pathOrCls: the config path,
100
+ or if the decorator is called without params, then the decorated class.
101
+ path as an argument in the decorator has a higher priority than the __path__ declared in the class.
102
+ """
103
+ def configDecorator (cls ):
104
+ class ConfigSpec (BaseConfig ):
105
+ pass
106
+
107
+ for k in cls .__dict__ :
108
+ if k == '__path__' :
109
+ ConfigSpec .__path__ = cls .__path__
110
+ if k .startswith ("__" ): continue
111
+ v = getattr (cls , k )
112
+ d = OptConfig (v )
113
+ d .__set_name__ (ConfigSpec , k )
114
+ setattr (ConfigSpec , k , d )
115
+ if isinstance (pathOrCls , str ):
116
+ ConfigSpec .__path__ = pathOrCls
117
+ return ConfigSpec
118
+ if isinstance (pathOrCls , str ):
119
+ return configDecorator
120
+ else :
121
+ return configDecorator (pathOrCls )
0 commit comments