Skip to content

Commit d345d74

Browse files
committed
feat(native): Support explicit @config("<name>") annotations
1 parent 0f357f8 commit d345d74

File tree

1 file changed

+22
-0
lines changed
  • packages/cubejs-backend-native/python/cube/src/conf

1 file changed

+22
-0
lines changed

packages/cubejs-backend-native/python/cube/src/conf/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def __init__(self):
125125
self.orchestrator_options = None
126126

127127
def __call__(self, func):
128+
if isinstance(func, str):
129+
return AttrRef(self, func)
130+
128131
if not callable(func):
129132
raise ConfigurationException("@config decorator must be used with functions, actual: '%s'" % type(func).__name__)
130133

@@ -133,6 +136,25 @@ def __call__(self, func):
133136
else:
134137
raise ConfigurationException("Unknown configuration property: '%s'" % func.__name__)
135138

139+
class AttrRef:
140+
config: Configuration
141+
attribute: str
142+
143+
def __init__(self, config: Configuration, attribue: str):
144+
self.config = config
145+
self.attribute = attribue
146+
147+
def __call__(self, func):
148+
if not callable(func):
149+
raise ConfigurationException("@config decorator must be used with functions, actual: '%s'" % type(func).__name__)
150+
151+
if hasattr(self.config, self.attribute):
152+
setattr(self.config, self.attribute, func)
153+
else:
154+
raise ConfigurationException("Unknown configuration property: '%s'" % func.__name__)
155+
156+
return func
157+
136158
config = Configuration()
137159
# backward compatibility
138160
settings = config

0 commit comments

Comments
 (0)