ob-metaflow-extensions 1.1.45rc3__py2.py3-none-any.whl → 1.5.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ob-metaflow-extensions might be problematic. Click here for more details.

Files changed (128) hide show
  1. metaflow_extensions/outerbounds/__init__.py +1 -7
  2. metaflow_extensions/outerbounds/config/__init__.py +35 -0
  3. metaflow_extensions/outerbounds/plugins/__init__.py +186 -57
  4. metaflow_extensions/outerbounds/plugins/apps/__init__.py +0 -0
  5. metaflow_extensions/outerbounds/plugins/apps/app_cli.py +0 -0
  6. metaflow_extensions/outerbounds/plugins/apps/app_utils.py +187 -0
  7. metaflow_extensions/outerbounds/plugins/apps/consts.py +3 -0
  8. metaflow_extensions/outerbounds/plugins/apps/core/__init__.py +15 -0
  9. metaflow_extensions/outerbounds/plugins/apps/core/_state_machine.py +506 -0
  10. metaflow_extensions/outerbounds/plugins/apps/core/_vendor/__init__.py +0 -0
  11. metaflow_extensions/outerbounds/plugins/apps/core/_vendor/spinner/__init__.py +4 -0
  12. metaflow_extensions/outerbounds/plugins/apps/core/_vendor/spinner/spinners.py +478 -0
  13. metaflow_extensions/outerbounds/plugins/apps/core/app_config.py +128 -0
  14. metaflow_extensions/outerbounds/plugins/apps/core/app_deploy_decorator.py +330 -0
  15. metaflow_extensions/outerbounds/plugins/apps/core/artifacts.py +0 -0
  16. metaflow_extensions/outerbounds/plugins/apps/core/capsule.py +958 -0
  17. metaflow_extensions/outerbounds/plugins/apps/core/click_importer.py +24 -0
  18. metaflow_extensions/outerbounds/plugins/apps/core/code_package/__init__.py +3 -0
  19. metaflow_extensions/outerbounds/plugins/apps/core/code_package/code_packager.py +618 -0
  20. metaflow_extensions/outerbounds/plugins/apps/core/code_package/examples.py +125 -0
  21. metaflow_extensions/outerbounds/plugins/apps/core/config/__init__.py +15 -0
  22. metaflow_extensions/outerbounds/plugins/apps/core/config/cli_generator.py +165 -0
  23. metaflow_extensions/outerbounds/plugins/apps/core/config/config_utils.py +966 -0
  24. metaflow_extensions/outerbounds/plugins/apps/core/config/schema_export.py +299 -0
  25. metaflow_extensions/outerbounds/plugins/apps/core/config/typed_configs.py +233 -0
  26. metaflow_extensions/outerbounds/plugins/apps/core/config/typed_init_generator.py +537 -0
  27. metaflow_extensions/outerbounds/plugins/apps/core/config/unified_config.py +1125 -0
  28. metaflow_extensions/outerbounds/plugins/apps/core/config_schema.yaml +337 -0
  29. metaflow_extensions/outerbounds/plugins/apps/core/dependencies.py +115 -0
  30. metaflow_extensions/outerbounds/plugins/apps/core/deployer.py +959 -0
  31. metaflow_extensions/outerbounds/plugins/apps/core/experimental/__init__.py +89 -0
  32. metaflow_extensions/outerbounds/plugins/apps/core/perimeters.py +87 -0
  33. metaflow_extensions/outerbounds/plugins/apps/core/secrets.py +164 -0
  34. metaflow_extensions/outerbounds/plugins/apps/core/utils.py +233 -0
  35. metaflow_extensions/outerbounds/plugins/apps/core/validations.py +17 -0
  36. metaflow_extensions/outerbounds/plugins/apps/deploy_decorator.py +201 -0
  37. metaflow_extensions/outerbounds/plugins/apps/supervisord_utils.py +243 -0
  38. metaflow_extensions/outerbounds/plugins/auth_server.py +28 -8
  39. metaflow_extensions/outerbounds/plugins/aws/__init__.py +4 -0
  40. metaflow_extensions/outerbounds/plugins/aws/assume_role.py +3 -0
  41. metaflow_extensions/outerbounds/plugins/aws/assume_role_decorator.py +118 -0
  42. metaflow_extensions/outerbounds/plugins/card_utilities/__init__.py +0 -0
  43. metaflow_extensions/outerbounds/plugins/card_utilities/async_cards.py +142 -0
  44. metaflow_extensions/outerbounds/plugins/card_utilities/extra_components.py +545 -0
  45. metaflow_extensions/outerbounds/plugins/card_utilities/injector.py +70 -0
  46. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/__init__.py +2 -0
  47. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/coreweave.py +71 -0
  48. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/external_chckpt.py +85 -0
  49. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/nebius.py +73 -0
  50. metaflow_extensions/outerbounds/plugins/fast_bakery/__init__.py +0 -0
  51. metaflow_extensions/outerbounds/plugins/fast_bakery/baker.py +110 -0
  52. metaflow_extensions/outerbounds/plugins/fast_bakery/docker_environment.py +391 -0
  53. metaflow_extensions/outerbounds/plugins/fast_bakery/fast_bakery.py +188 -0
  54. metaflow_extensions/outerbounds/plugins/fast_bakery/fast_bakery_cli.py +54 -0
  55. metaflow_extensions/outerbounds/plugins/fast_bakery/fast_bakery_decorator.py +50 -0
  56. metaflow_extensions/outerbounds/plugins/kubernetes/kubernetes_client.py +79 -0
  57. metaflow_extensions/outerbounds/plugins/kubernetes/pod_killer.py +374 -0
  58. metaflow_extensions/outerbounds/plugins/nim/card.py +140 -0
  59. metaflow_extensions/outerbounds/plugins/nim/nim_decorator.py +101 -0
  60. metaflow_extensions/outerbounds/plugins/nim/nim_manager.py +379 -0
  61. metaflow_extensions/outerbounds/plugins/nim/utils.py +36 -0
  62. metaflow_extensions/outerbounds/plugins/nvcf/__init__.py +0 -0
  63. metaflow_extensions/outerbounds/plugins/nvcf/constants.py +3 -0
  64. metaflow_extensions/outerbounds/plugins/nvcf/exceptions.py +94 -0
  65. metaflow_extensions/outerbounds/plugins/nvcf/heartbeat_store.py +178 -0
  66. metaflow_extensions/outerbounds/plugins/nvcf/nvcf.py +417 -0
  67. metaflow_extensions/outerbounds/plugins/nvcf/nvcf_cli.py +280 -0
  68. metaflow_extensions/outerbounds/plugins/nvcf/nvcf_decorator.py +242 -0
  69. metaflow_extensions/outerbounds/plugins/nvcf/utils.py +6 -0
  70. metaflow_extensions/outerbounds/plugins/nvct/__init__.py +0 -0
  71. metaflow_extensions/outerbounds/plugins/nvct/exceptions.py +71 -0
  72. metaflow_extensions/outerbounds/plugins/nvct/nvct.py +131 -0
  73. metaflow_extensions/outerbounds/plugins/nvct/nvct_cli.py +289 -0
  74. metaflow_extensions/outerbounds/plugins/nvct/nvct_decorator.py +286 -0
  75. metaflow_extensions/outerbounds/plugins/nvct/nvct_runner.py +218 -0
  76. metaflow_extensions/outerbounds/plugins/nvct/utils.py +29 -0
  77. metaflow_extensions/outerbounds/plugins/ollama/__init__.py +225 -0
  78. metaflow_extensions/outerbounds/plugins/ollama/constants.py +1 -0
  79. metaflow_extensions/outerbounds/plugins/ollama/exceptions.py +22 -0
  80. metaflow_extensions/outerbounds/plugins/ollama/ollama.py +1924 -0
  81. metaflow_extensions/outerbounds/plugins/ollama/status_card.py +292 -0
  82. metaflow_extensions/outerbounds/plugins/optuna/__init__.py +48 -0
  83. metaflow_extensions/outerbounds/plugins/perimeters.py +19 -5
  84. metaflow_extensions/outerbounds/plugins/profilers/deco_injector.py +70 -0
  85. metaflow_extensions/outerbounds/plugins/profilers/gpu_profile_decorator.py +88 -0
  86. metaflow_extensions/outerbounds/plugins/profilers/simple_card_decorator.py +96 -0
  87. metaflow_extensions/outerbounds/plugins/s3_proxy/__init__.py +7 -0
  88. metaflow_extensions/outerbounds/plugins/s3_proxy/binary_caller.py +132 -0
  89. metaflow_extensions/outerbounds/plugins/s3_proxy/constants.py +11 -0
  90. metaflow_extensions/outerbounds/plugins/s3_proxy/exceptions.py +13 -0
  91. metaflow_extensions/outerbounds/plugins/s3_proxy/proxy_bootstrap.py +59 -0
  92. metaflow_extensions/outerbounds/plugins/s3_proxy/s3_proxy_api.py +93 -0
  93. metaflow_extensions/outerbounds/plugins/s3_proxy/s3_proxy_decorator.py +250 -0
  94. metaflow_extensions/outerbounds/plugins/s3_proxy/s3_proxy_manager.py +225 -0
  95. metaflow_extensions/outerbounds/plugins/secrets/__init__.py +0 -0
  96. metaflow_extensions/outerbounds/plugins/secrets/secrets.py +204 -0
  97. metaflow_extensions/outerbounds/plugins/snowflake/__init__.py +3 -0
  98. metaflow_extensions/outerbounds/plugins/snowflake/snowflake.py +378 -0
  99. metaflow_extensions/outerbounds/plugins/snowpark/__init__.py +0 -0
  100. metaflow_extensions/outerbounds/plugins/snowpark/snowpark.py +309 -0
  101. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_cli.py +277 -0
  102. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_client.py +150 -0
  103. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_decorator.py +273 -0
  104. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_exceptions.py +13 -0
  105. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_job.py +241 -0
  106. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_service_spec.py +259 -0
  107. metaflow_extensions/outerbounds/plugins/tensorboard/__init__.py +50 -0
  108. metaflow_extensions/outerbounds/plugins/torchtune/__init__.py +163 -0
  109. metaflow_extensions/outerbounds/plugins/vllm/__init__.py +255 -0
  110. metaflow_extensions/outerbounds/plugins/vllm/constants.py +1 -0
  111. metaflow_extensions/outerbounds/plugins/vllm/exceptions.py +1 -0
  112. metaflow_extensions/outerbounds/plugins/vllm/status_card.py +352 -0
  113. metaflow_extensions/outerbounds/plugins/vllm/vllm_manager.py +621 -0
  114. metaflow_extensions/outerbounds/profilers/gpu.py +131 -47
  115. metaflow_extensions/outerbounds/remote_config.py +53 -16
  116. metaflow_extensions/outerbounds/toplevel/global_aliases_for_metaflow_package.py +138 -2
  117. metaflow_extensions/outerbounds/toplevel/ob_internal.py +4 -0
  118. metaflow_extensions/outerbounds/toplevel/plugins/ollama/__init__.py +1 -0
  119. metaflow_extensions/outerbounds/toplevel/plugins/optuna/__init__.py +1 -0
  120. metaflow_extensions/outerbounds/toplevel/plugins/snowflake/__init__.py +1 -0
  121. metaflow_extensions/outerbounds/toplevel/plugins/torchtune/__init__.py +1 -0
  122. metaflow_extensions/outerbounds/toplevel/plugins/vllm/__init__.py +1 -0
  123. metaflow_extensions/outerbounds/toplevel/s3_proxy.py +88 -0
  124. {ob_metaflow_extensions-1.1.45rc3.dist-info → ob_metaflow_extensions-1.5.1.dist-info}/METADATA +2 -2
  125. ob_metaflow_extensions-1.5.1.dist-info/RECORD +133 -0
  126. ob_metaflow_extensions-1.1.45rc3.dist-info/RECORD +0 -19
  127. {ob_metaflow_extensions-1.1.45rc3.dist-info → ob_metaflow_extensions-1.5.1.dist-info}/WHEEL +0 -0
  128. {ob_metaflow_extensions-1.1.45rc3.dist-info → ob_metaflow_extensions-1.5.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1125 @@
1
+ """
2
+ Unified Configuration System for Outerbounds Apps
3
+
4
+ This module provides a type-safe, declarative configuration system that serves as the
5
+ single source of truth for app configuration. It automatically generates CLI options,
6
+ handles config file parsing, and manages field merging behavior.
7
+
8
+ No external dependencies required - uses only Python standard library.
9
+ """
10
+
11
+
12
+ import os
13
+ import json
14
+ from typing import Any, Dict, List, Optional, Union, Type
15
+ import re
16
+
17
+ from .config_utils import (
18
+ ConfigFieldContext,
19
+ ConfigField,
20
+ ConfigMeta,
21
+ JsonFriendlyKeyValuePairType,
22
+ PureStringKVPairType,
23
+ CommaSeparatedListType,
24
+ FieldBehavior,
25
+ CLIOption,
26
+ config_meta_to_dict,
27
+ merge_field_values,
28
+ apply_defaults,
29
+ populate_config_recursive,
30
+ validate_config_meta,
31
+ validate_required_fields,
32
+ ConfigValidationFailedException,
33
+ commit_owner_names_across_tree,
34
+ )
35
+
36
+ from collections import namedtuple
37
+
38
+
39
+ # Result of image baking operation
40
+ # - image: The fully qualified Docker image URL
41
+ # - python_path: Path to the Python executable in the baked image
42
+ BakedImage = namedtuple("BakedImage", ["image", "python_path"])
43
+
44
+ # Result of code packaging operation
45
+ # - url: The package URL in object storage
46
+ # - key: Unique content-addressed key identifying this package
47
+ PackagedCode = namedtuple("PackagedCode", ["url", "key"])
48
+
49
+
50
+ class classproperty(property):
51
+ def __get__(self, owner_self, owner_cls):
52
+ return self.fget(owner_cls)
53
+
54
+
55
+ class AuthType:
56
+ BROWSER = "Browser"
57
+ API = "API"
58
+ BROWSER_AND_API = "BrowserAndApi"
59
+
60
+ @classmethod
61
+ def enums(cls):
62
+ return [cls.BROWSER, cls.API, cls.BROWSER_AND_API]
63
+
64
+ @classproperty
65
+ def default(cls):
66
+ return cls.BROWSER
67
+
68
+ @classmethod
69
+ def choices(cls):
70
+ return [cls.BROWSER, cls.API, cls.BROWSER_AND_API]
71
+
72
+
73
+ class UnitParser:
74
+ UNIT_FREE_REGEX = r"^\d+$"
75
+
76
+ metrics = {
77
+ "memory": {
78
+ "default_unit": "Mi",
79
+ "requires_unit": True, # if a Unit free value is provided then we will add the default unit to it.
80
+ # Regex to match values with units (e.g., "512Mi", "4Gi", "1024Ki")
81
+ "correct_unit_regex": r"^\d+(\.\d+)?(Ki|Mi|Gi|Ti|Pi|Ei)$",
82
+ },
83
+ "cpu": {
84
+ "default_unit": None,
85
+ "requires_unit": False, # if a Unit free value is provided then we will not add the default unit to it.
86
+ # Accepts values like 400m, 4, 0.4, 1000n, etc.
87
+ # Regex to match values with units (e.g., "400m", "1000n", "2", "0.5")
88
+ "correct_unit_regex": r"^(\d+(\.\d+)?(m|n)?|\d+(\.\d+)?)$",
89
+ },
90
+ "disk": {
91
+ "default_unit": "Mi",
92
+ "requires_unit": True, # if a Unit free value is provided then we will add the default unit to it.
93
+ # Regex to match values with units (e.g., "100Mi", "1Gi", "500Ki")
94
+ "correct_unit_regex": r"^\d+(\.\d+)?(Ki|Mi|Gi|Ti|Pi|Ei)$",
95
+ },
96
+ "gpu": {
97
+ "default_unit": None,
98
+ "requires_unit": False,
99
+ # Regex to match values with units (usually just integer count, e.g., "1", "2")
100
+ "correct_unit_regex": r"^\d+$",
101
+ },
102
+ }
103
+
104
+ def __init__(self, metric_name: str):
105
+ self.metric_name = metric_name
106
+
107
+ def validate(self, value: str):
108
+ if re.match(self.metrics[self.metric_name]["correct_unit_regex"], value):
109
+ return True
110
+ return False
111
+
112
+ def process(self, value: str):
113
+ value = str(value)
114
+ if self.metrics[self.metric_name]["requires_unit"]:
115
+ if re.match(self.UNIT_FREE_REGEX, value):
116
+ # This means the value is unit free and we need to add the default unit to it.
117
+ value = "%s%s" % (
118
+ value.strip(),
119
+ self.metrics[self.metric_name]["default_unit"],
120
+ )
121
+ return value
122
+
123
+ return value
124
+
125
+ def parse(self, value: Union[str, None]):
126
+ if value is None:
127
+ return None
128
+ return self.process(value)
129
+
130
+ @staticmethod
131
+ def validation_wrapper_fn(
132
+ metric_name: str,
133
+ ):
134
+ def validation_fn(value: str):
135
+ if value is None:
136
+ return True
137
+ field_info = ResourceConfig._get_field(ResourceConfig, metric_name) # type: ignore
138
+ parser = UnitParser(metric_name)
139
+ validation = parser.validate(value)
140
+ if not validation:
141
+ raise ConfigValidationFailedException(
142
+ field_name=metric_name,
143
+ field_info=field_info,
144
+ current_value=value,
145
+ message=f"Invalid value for `{metric_name}`. Must be of the format {parser.metrics[metric_name]['correct_unit_regex']}.",
146
+ )
147
+ return validation
148
+
149
+ return validation_fn
150
+
151
+
152
+ class BasicValidations:
153
+ def __init__(self, config_meta_class, field_name):
154
+ self.config_meta_class = config_meta_class
155
+ self.field_name = field_name
156
+
157
+ def _get_field(self):
158
+ return self.config_meta_class._get_field(self.config_meta_class, self.field_name) # type: ignore
159
+
160
+ def enum_validation(self, enums: List[str], current_value):
161
+ if current_value not in enums:
162
+ raise ConfigValidationFailedException(
163
+ field_name=self.field_name,
164
+ field_info=self._get_field(),
165
+ current_value=current_value,
166
+ message=f"Configuration field {self.field_name} has invalid value {current_value}. Value must be one of: {'/'.join(enums)}",
167
+ )
168
+ return True
169
+
170
+ def range_validation(self, min_value, max_value, current_value):
171
+ if current_value < min_value or current_value > max_value:
172
+ raise ConfigValidationFailedException(
173
+ field_name=self.field_name,
174
+ field_info=self._get_field(),
175
+ current_value=current_value,
176
+ message=f"Configuration field {self.field_name} has invalid value {current_value}. Value must be between {min_value} and {max_value}",
177
+ )
178
+ return True
179
+
180
+ def length_validation(self, max_length, current_value):
181
+ if len(current_value) > max_length:
182
+ raise ConfigValidationFailedException(
183
+ field_name=self.field_name,
184
+ field_info=self._get_field(),
185
+ current_value=current_value,
186
+ message=f"Configuration field {self.field_name} has invalid value {current_value}. Value must be less than {max_length}",
187
+ )
188
+ return True
189
+
190
+ def regex_validation(self, regex, current_value):
191
+ if not re.match(regex, current_value):
192
+ raise ConfigValidationFailedException(
193
+ field_name=self.field_name,
194
+ field_info=self._get_field(),
195
+ current_value=current_value,
196
+ message=f"Configuration field {self.field_name} has invalid value {current_value}. Value must match regex {regex}",
197
+ )
198
+ return True
199
+
200
+
201
+ class ResourceConfig(metaclass=ConfigMeta):
202
+ """Resource configuration for the app."""
203
+
204
+ # TODO: Add Unit Validation/Parsing Support for the Fields.
205
+ cpu = ConfigField(
206
+ default="1",
207
+ cli_meta=CLIOption(
208
+ name="cpu",
209
+ cli_option_str="--cpu",
210
+ ),
211
+ field_type=str,
212
+ help="CPU requests",
213
+ example="500m",
214
+ validation_fn=UnitParser.validation_wrapper_fn("cpu"),
215
+ parsing_fn=UnitParser("cpu").parse,
216
+ )
217
+ memory = ConfigField(
218
+ default="4Gi",
219
+ cli_meta=CLIOption(
220
+ name="memory",
221
+ cli_option_str="--memory",
222
+ ),
223
+ field_type=str,
224
+ help="Memory requests",
225
+ example="512Mi",
226
+ validation_fn=UnitParser.validation_wrapper_fn("memory"),
227
+ parsing_fn=UnitParser("memory").parse,
228
+ )
229
+ gpu = ConfigField(
230
+ cli_meta=CLIOption(
231
+ name="gpu",
232
+ cli_option_str="--gpu",
233
+ ),
234
+ field_type=str,
235
+ help="GPU requests",
236
+ example="1",
237
+ validation_fn=UnitParser.validation_wrapper_fn("gpu"),
238
+ parsing_fn=UnitParser("gpu").parse,
239
+ )
240
+ disk = ConfigField(
241
+ default="20Gi",
242
+ cli_meta=CLIOption(
243
+ name="disk",
244
+ cli_option_str="--disk",
245
+ ),
246
+ field_type=str,
247
+ help="Storage disk size.",
248
+ example="1Gi",
249
+ validation_fn=UnitParser.validation_wrapper_fn("disk"),
250
+ parsing_fn=UnitParser("disk").parse,
251
+ )
252
+
253
+ shared_memory = ConfigField(
254
+ cli_meta=CLIOption(
255
+ name="shared_memory",
256
+ cli_option_str="--shared-memory",
257
+ ),
258
+ field_type=str,
259
+ help="Shared memory",
260
+ example="1Gi",
261
+ validation_fn=UnitParser.validation_wrapper_fn("memory"),
262
+ parsing_fn=UnitParser("memory").parse,
263
+ )
264
+
265
+
266
+ class HealthCheckConfig(metaclass=ConfigMeta):
267
+ """Health check configuration."""
268
+
269
+ enabled = ConfigField(
270
+ default=False,
271
+ cli_meta=CLIOption(
272
+ name="health_check_enabled",
273
+ cli_option_str="--health-check-enabled",
274
+ is_flag=True,
275
+ ),
276
+ field_type=bool,
277
+ help="Whether to enable health checks.",
278
+ example=True,
279
+ )
280
+ path = ConfigField(
281
+ cli_meta=CLIOption(
282
+ name="health_check_path",
283
+ cli_option_str="--health-check-path",
284
+ ),
285
+ field_type=str,
286
+ help="The path for health checks.",
287
+ example="/health",
288
+ )
289
+ initial_delay_seconds = ConfigField(
290
+ cli_meta=CLIOption(
291
+ name="health_check_initial_delay",
292
+ cli_option_str="--health-check-initial-delay",
293
+ ),
294
+ field_type=int,
295
+ help="Number of seconds to wait before performing the first health check.",
296
+ example=10,
297
+ )
298
+ period_seconds = ConfigField(
299
+ cli_meta=CLIOption(
300
+ name="health_check_period",
301
+ cli_option_str="--health-check-period",
302
+ ),
303
+ field_type=int,
304
+ help="How often to perform the health check.",
305
+ example=30,
306
+ )
307
+
308
+
309
+ class AuthConfig(metaclass=ConfigMeta):
310
+ """Authentication configuration."""
311
+
312
+ type = ConfigField(
313
+ default=AuthType.BROWSER,
314
+ cli_meta=CLIOption(
315
+ name="auth_type",
316
+ cli_option_str="--auth-type",
317
+ choices=AuthType.choices(),
318
+ ),
319
+ field_type=str,
320
+ help="The type of authentication to use for the app.",
321
+ example="Browser",
322
+ )
323
+ public = ConfigField(
324
+ default=True,
325
+ cli_meta=CLIOption(
326
+ name="auth_public",
327
+ cli_option_str="--public-access/--private-access",
328
+ is_flag=True,
329
+ ),
330
+ field_type=bool,
331
+ help="Whether the app is public or not.",
332
+ example=True,
333
+ )
334
+
335
+ @staticmethod
336
+ def validate(auth_config: "AuthConfig"):
337
+ if auth_config.type is None:
338
+ return True
339
+ return BasicValidations(AuthConfig, "type").enum_validation(
340
+ AuthType.choices(), auth_config.type
341
+ )
342
+
343
+
344
+ class ScalingPolicyConfig(metaclass=ConfigMeta):
345
+ """
346
+ Policies for autoscaling replicas. Available policies:
347
+ - Request based Autoscaling (rpm)
348
+ """
349
+
350
+ # TODO Change the defaulting if we have more autoscaling policies.
351
+ rpm = ConfigField(
352
+ field_type=int,
353
+ cli_meta=CLIOption(
354
+ name="scaling_rpm",
355
+ cli_option_str="--scaling-rpm",
356
+ ),
357
+ help=(
358
+ "Scale up replicas when the requests per minute crosses this threshold. "
359
+ "If nothing is provided and the replicas.max and replicas.min is set then "
360
+ "the default rpm would be 60."
361
+ ),
362
+ default=60,
363
+ )
364
+
365
+
366
+ class ReplicaConfig(metaclass=ConfigMeta):
367
+ """Replica configuration."""
368
+
369
+ fixed = ConfigField(
370
+ cli_meta=CLIOption(
371
+ name="fixed_replicas",
372
+ cli_option_str="--fixed-replicas",
373
+ ),
374
+ field_type=int,
375
+ help="The fixed number of replicas to deploy the app with. If min and max are set, this will raise an error.",
376
+ example=1,
377
+ )
378
+
379
+ min = ConfigField(
380
+ cli_meta=CLIOption(
381
+ name="min_replicas",
382
+ cli_option_str="--min-replicas",
383
+ ),
384
+ field_type=int,
385
+ help="The minimum number of replicas to deploy the app with.",
386
+ example=1,
387
+ )
388
+ max = ConfigField(
389
+ cli_meta=CLIOption(
390
+ name="max_replicas",
391
+ cli_option_str="--max-replicas",
392
+ ),
393
+ field_type=int,
394
+ help="The maximum number of replicas to deploy the app with.",
395
+ example=10,
396
+ )
397
+
398
+ scaling_policy = ConfigField(
399
+ cli_meta=None,
400
+ field_type=ScalingPolicyConfig,
401
+ help=(
402
+ "Scaling policy defines the the metric based on which the replicas will horizontally scale. "
403
+ "If min and max replicas are set and are not the same, then a scaling policy will be applied. "
404
+ "Default scaling policies can be 60 rpm (ie 1 rps). "
405
+ ),
406
+ )
407
+
408
+ @staticmethod
409
+ def defaults(replica_config: "ReplicaConfig"):
410
+ if all(
411
+ [
412
+ replica_config.min is None,
413
+ replica_config.max is None,
414
+ replica_config.fixed is None,
415
+ ]
416
+ ):
417
+ # if nothing is set then set
418
+ replica_config.fixed = 1
419
+ elif replica_config.min is not None and replica_config.max is None:
420
+ replica_config.max = replica_config.min
421
+
422
+ return
423
+
424
+ @staticmethod
425
+ def validate(replica_config: "ReplicaConfig"):
426
+ both_min_max_set = (
427
+ replica_config.min is not None and replica_config.max is not None
428
+ )
429
+ fixed_set = replica_config.fixed is not None
430
+ max_is_set = replica_config.max is not None
431
+ min_is_set = replica_config.min is not None
432
+ any_min_max_set = (
433
+ replica_config.min is not None or replica_config.max is not None
434
+ )
435
+
436
+ def _greater_than_equals_zero(x):
437
+ return x is not None and x >= 0
438
+
439
+ if both_min_max_set and replica_config.min > replica_config.max: # type: ignore
440
+ raise ConfigValidationFailedException(
441
+ field_name="min",
442
+ field_info=replica_config._get_field("min"), # type: ignore
443
+ current_value=replica_config.min,
444
+ message="Min replicas cannot be greater than max replicas",
445
+ )
446
+ if fixed_set and any_min_max_set:
447
+ raise ConfigValidationFailedException(
448
+ field_name="fixed",
449
+ field_info=replica_config._get_field("fixed"), # type: ignore
450
+ current_value=replica_config.fixed,
451
+ message="Fixed replicas cannot be set when min or max replicas are set",
452
+ )
453
+
454
+ if max_is_set and not min_is_set:
455
+ raise ConfigValidationFailedException(
456
+ field_name="min",
457
+ field_info=replica_config._get_field("min"), # type: ignore
458
+ current_value=replica_config.min,
459
+ message="If max replicas is set then min replicas must be set too.",
460
+ )
461
+
462
+ if fixed_set and replica_config.fixed < 0: # type: ignore
463
+ raise ConfigValidationFailedException(
464
+ field_name="fixed",
465
+ field_info=replica_config._get_field("fixed"), # type: ignore
466
+ current_value=replica_config.fixed,
467
+ message="Fixed replicas cannot be less than 0",
468
+ )
469
+
470
+ if min_is_set and not _greater_than_equals_zero(replica_config.min):
471
+ raise ConfigValidationFailedException(
472
+ field_name="min",
473
+ field_info=replica_config._get_field("min"), # type: ignore
474
+ current_value=replica_config.min,
475
+ message="Min replicas cannot be less than 0",
476
+ )
477
+
478
+ if max_is_set and not _greater_than_equals_zero(replica_config.max):
479
+ raise ConfigValidationFailedException(
480
+ field_name="max",
481
+ field_info=replica_config._get_field("max"), # type: ignore
482
+ current_value=replica_config.max,
483
+ message="Max replicas cannot be less than 0",
484
+ )
485
+ return True
486
+
487
+
488
+ def more_than_n_not_none(n, *args):
489
+ return sum(1 for arg in args if arg is not None) > n
490
+
491
+
492
+ class DependencyConfig(metaclass=ConfigMeta):
493
+ """Dependency configuration."""
494
+
495
+ from_requirements_file = ConfigField(
496
+ cli_meta=CLIOption(
497
+ name="dep_from_requirements",
498
+ cli_option_str="--dep-from-requirements",
499
+ ),
500
+ field_type=str,
501
+ help="The path to the requirements.txt file to attach to the app.",
502
+ behavior=FieldBehavior.NOT_ALLOWED,
503
+ example="requirements.txt",
504
+ )
505
+ from_pyproject_toml = ConfigField(
506
+ cli_meta=CLIOption(
507
+ name="dep_from_pyproject",
508
+ cli_option_str="--dep-from-pyproject",
509
+ ),
510
+ field_type=str,
511
+ help="The path to the pyproject.toml file to attach to the app.",
512
+ behavior=FieldBehavior.NOT_ALLOWED,
513
+ example="pyproject.toml",
514
+ )
515
+ python = ConfigField(
516
+ cli_meta=CLIOption(
517
+ name="python",
518
+ cli_option_str="--python",
519
+ ),
520
+ field_type=str,
521
+ help="The Python version to use for the app.",
522
+ behavior=FieldBehavior.UNION,
523
+ example="3.10",
524
+ )
525
+ pypi = ConfigField(
526
+ cli_meta=CLIOption(
527
+ name="pypi", # TODO: Can set CLI meta to None
528
+ cli_option_str="--pypi",
529
+ hidden=True, # Complex structure, better handled in config file
530
+ ),
531
+ field_type=dict,
532
+ help="A dictionary of pypi dependencies to attach to the app. The key is the package name and the value is the version.",
533
+ behavior=FieldBehavior.NOT_ALLOWED,
534
+ example={"numpy": "1.23.0", "pandas": ""},
535
+ )
536
+ conda = ConfigField(
537
+ cli_meta=CLIOption( # TODO: Can set CLI meta to None
538
+ name="conda",
539
+ cli_option_str="--conda",
540
+ hidden=True, # Complex structure, better handled in config file
541
+ ),
542
+ field_type=dict,
543
+ help="A dictionary of conda dependencies to attach to the app. The key is the package name and the value is the version.",
544
+ behavior=FieldBehavior.NOT_ALLOWED,
545
+ example={"numpy": "1.23.0", "pandas": ""},
546
+ )
547
+
548
+ @staticmethod
549
+ def validate(dependency_config: "DependencyConfig"):
550
+ # You can either have from_requirements_file or from_pyproject_toml or python with pypi or conda
551
+ # but not more than one of them.
552
+ if more_than_n_not_none(
553
+ 1,
554
+ dependency_config.from_requirements_file,
555
+ dependency_config.from_pyproject_toml,
556
+ ):
557
+ raise ConfigValidationFailedException(
558
+ field_name="from_requirements_file",
559
+ field_info=dependency_config._get_field("from_requirements_file"), # type: ignore
560
+ current_value=dependency_config.from_requirements_file,
561
+ message="Cannot set from_requirements_file and from_pyproject_toml at the same time",
562
+ )
563
+ if any([dependency_config.pypi, dependency_config.conda]) and any(
564
+ [
565
+ dependency_config.from_requirements_file,
566
+ dependency_config.from_pyproject_toml,
567
+ ]
568
+ ):
569
+ raise ConfigValidationFailedException(
570
+ field_name="pypi" if dependency_config.pypi else "conda",
571
+ field_info=dependency_config._get_field( # type: ignore
572
+ "pypi" if dependency_config.pypi else "conda"
573
+ ),
574
+ current_value=dependency_config.pypi or dependency_config.conda,
575
+ message="Cannot set pypi or conda when from_requirements_file or from_pyproject_toml is set",
576
+ )
577
+ return True
578
+
579
+
580
+ class PackageConfig(metaclass=ConfigMeta):
581
+ """Package configuration."""
582
+
583
+ src_paths = ConfigField(
584
+ cli_meta=CLIOption(
585
+ name="package_src_path",
586
+ cli_option_str="--package-src-path",
587
+ multiple=True,
588
+ click_type=str,
589
+ ),
590
+ field_type=list,
591
+ help="The path to the source code to deploy with the App.",
592
+ example=["./"],
593
+ )
594
+ suffixes = ConfigField(
595
+ cli_meta=CLIOption(
596
+ name="package_suffixes",
597
+ cli_option_str="--package-suffixes",
598
+ ),
599
+ field_type=list,
600
+ help="A list of suffixes to add to the source code to deploy with the App.",
601
+ example=[".py", ".ipynb"],
602
+ )
603
+
604
+ @staticmethod
605
+ def validate(package_config: "PackageConfig"):
606
+ if package_config.src_paths is None:
607
+ return True
608
+ if package_config.src_paths:
609
+ for path in package_config.src_paths:
610
+ if not os.path.exists(path):
611
+ raise ConfigValidationFailedException(
612
+ field_name="src_paths",
613
+ field_info=package_config._get_field("src_paths"), # type: ignore
614
+ current_value=package_config.src_paths,
615
+ message=f"Path does not exist : `{path}`",
616
+ )
617
+ if not os.path.isdir(path):
618
+ raise ConfigValidationFailedException(
619
+ field_name="src_paths",
620
+ field_info=package_config._get_field("src_paths"), # type: ignore
621
+ current_value=package_config.src_paths,
622
+ message=f"Path is not a directory : `{path}`",
623
+ )
624
+ return True
625
+
626
+
627
+ def everything_is_string(*args):
628
+ return all(isinstance(arg, str) for arg in args)
629
+
630
+
631
+ class BasicAppValidations:
632
+ @staticmethod
633
+ def name(name):
634
+ if name is None:
635
+ return True
636
+ regex = r"^[a-z0-9-]+$" # Only allow lowercase letters, numbers, and hyphens
637
+ validator = BasicValidations(CoreConfig, "name")
638
+ return validator.length_validation(150, name) and validator.regex_validation(
639
+ regex, name
640
+ )
641
+
642
+ @staticmethod
643
+ def port(port):
644
+ if port is None:
645
+ return True
646
+ return BasicValidations(CoreConfig, "port").range_validation(1, 65535, port)
647
+
648
+ @staticmethod
649
+ def tags(tags):
650
+ if tags is None:
651
+ return True
652
+ if not all(
653
+ isinstance(tag, dict)
654
+ and len(tag) == 1
655
+ and all(
656
+ [everything_is_string(*tag.keys()), everything_is_string(*tag.values())]
657
+ )
658
+ for tag in tags
659
+ ):
660
+ raise ConfigValidationFailedException(
661
+ field_name="tags",
662
+ field_info=CoreConfig._get_field(CoreConfig, "tags"), # type: ignore
663
+ current_value=tags,
664
+ message="Tags must be a list of dictionaries with one key and the value must be a string. Currently they are set to %s "
665
+ % (str(tags)),
666
+ )
667
+ return True
668
+
669
+ @staticmethod
670
+ def secrets(secrets):
671
+ if secrets is None: # If nothing is set we dont care.
672
+ return True
673
+
674
+ if not isinstance(secrets, list):
675
+ raise ConfigValidationFailedException(
676
+ field_name="secrets",
677
+ field_info=CoreConfig._get_field(CoreConfig, "secrets"), # type: ignore
678
+ current_value=secrets,
679
+ message="Secrets must be a list of strings. Currently they are set to %s "
680
+ % (str(secrets)),
681
+ )
682
+ from ..validations import secrets_validator
683
+
684
+ try:
685
+ secrets_validator(secrets)
686
+ except Exception as e:
687
+ raise ConfigValidationFailedException(
688
+ field_name="secrets",
689
+ field_info=CoreConfig._get_field(CoreConfig, "secrets"), # type: ignore
690
+ current_value=secrets,
691
+ message=f"Secrets validation failed, {e}",
692
+ )
693
+ return True
694
+
695
+ @staticmethod
696
+ def persistence(persistence):
697
+ if persistence is None:
698
+ return True
699
+ return BasicValidations(CoreConfig, "persistence").enum_validation(
700
+ ["none", "postgres"], persistence
701
+ )
702
+
703
+
704
+ class CoreConfig(metaclass=ConfigMeta):
705
+ """Unified App Configuration - The single source of truth for application configuration.
706
+
707
+ CoreConfig is the central configuration class that defines all application settings using the
708
+ ConfigMeta metaclass and ConfigField descriptors. It provides a declarative, type-safe way
709
+ to manage configuration from multiple sources (CLI, config files, environment) with automatic
710
+ validation, merging, and CLI generation.
711
+
712
+ Core Features:
713
+ - **Declarative Configuration**: All fields are defined using ConfigField descriptors
714
+ - **Multi-Source Configuration**: Supports CLI options, config files (JSON/YAML), and programmatic setting
715
+ - **Automatic CLI Generation**: CLI options are automatically generated from field metadata
716
+ - **Type Safety**: Built-in type checking and validation for all fields
717
+ - **Hierarchical Structure**: Supports nested configuration objects (resources, auth, dependencies)
718
+ - **Intelligent Merging**: Configurable merging behavior for different field types
719
+ - **Validation Framework**: Comprehensive validation with custom validation functions
720
+
721
+ Configuration Lifecycle:
722
+ 1. **Definition**: Fields are defined declaratively using ConfigField descriptors
723
+ 2. **Instantiation**: Objects are created with all fields initialized to None or nested objects
724
+ 3. **Population**: Values are populated from CLI options, config files, or direct assignment
725
+ 4. **Merging**: Multiple config sources are merged according to field behavior settings
726
+ 5. **Validation**: Field validation functions and required field checks are performed
727
+ 6. **Default Application**: Default values are applied to any remaining None fields
728
+ 7. **Commit**: Final validation and preparation for use
729
+
730
+
731
+ Usage Examples:
732
+ Create from CLI options:
733
+ ```python
734
+ config = CoreConfig.from_cli({
735
+ 'name': 'myapp',
736
+ 'port': 8080,
737
+ 'commands': ['python app.py']
738
+ })
739
+ ```
740
+
741
+ Create from config file:
742
+ ```python
743
+ config = CoreConfig.from_file('config.yaml')
744
+ ```
745
+
746
+ Create from dictionary:
747
+ ```python
748
+ config = CoreConfig.from_dict({
749
+ 'name': 'myapp',
750
+ 'port': 8080,
751
+ 'resources': {
752
+ 'cpu': '500m',
753
+ 'memory': '1Gi'
754
+ }
755
+ })
756
+ ```
757
+
758
+ Merge configurations:
759
+ ```python
760
+ file_config = CoreConfig.from_file('config.yaml')
761
+ cli_config = CoreConfig.from_cli(cli_options)
762
+ final_config = CoreConfig.merge_configs(file_config, cli_config)
763
+ final_config.commit() # Validate and apply defaults
764
+ ```
765
+ """
766
+
767
+ # TODO: We can add Force Upgrade / No Deps flags here too if we need to.
768
+ # Since those can be exposed on the CLI side and the APP state will anyways
769
+ # be expored before being worked upon.
770
+
771
+ SCHEMA_DOC = """Schema for defining Outerbounds Apps configuration. This schema is what we will end up using on the CLI/programmatic interface.
772
+ How to read this schema:
773
+ 1. If the a property has `mutation_behavior` set to `union` then it will allow overrides of values at runtime from the CLI.
774
+ 2. If the property has `mutation_behavior`set to `not_allowed` then either the CLI or the config file value will be used (which ever is not None). If the user supplies something in both then an error will be raised.
775
+ 3. If a property has `experimental` set to true then a lot its validations may-be skipped and parsing handled somewhere else.
776
+ """
777
+
778
+ # Required fields
779
+ name = ConfigField(
780
+ cli_meta=CLIOption(
781
+ name="name",
782
+ cli_option_str="--name",
783
+ ),
784
+ validation_fn=BasicAppValidations.name,
785
+ field_type=str,
786
+ required=True,
787
+ help="The name of the app to deploy.",
788
+ example="myapp",
789
+ )
790
+ port = ConfigField(
791
+ cli_meta=CLIOption(
792
+ name="port",
793
+ cli_option_str="--port",
794
+ ),
795
+ validation_fn=BasicAppValidations.port,
796
+ field_type=int,
797
+ required=True,
798
+ help="Port where the app is hosted. When deployed this will be port on which we will deploy the app.",
799
+ example=8000,
800
+ )
801
+
802
+ # Optional basic fields
803
+ description = ConfigField(
804
+ cli_meta=CLIOption(
805
+ name="description",
806
+ cli_option_str="--description",
807
+ ),
808
+ field_type=str,
809
+ help="The description of the app to deploy.",
810
+ example="This is a description of my app.",
811
+ )
812
+ app_type = ConfigField(
813
+ cli_meta=CLIOption(
814
+ name="app_type",
815
+ cli_option_str="--app-type",
816
+ ),
817
+ field_type=str,
818
+ help="The User defined type of app to deploy. Its only used for bookkeeping purposes.",
819
+ example="MyCustomAgent",
820
+ )
821
+ image = ConfigField(
822
+ cli_meta=CLIOption(
823
+ name="image",
824
+ cli_option_str="--image",
825
+ ),
826
+ field_type=str,
827
+ help="The Docker image to deploy with the App.",
828
+ example="python:3.10-slim",
829
+ )
830
+
831
+ # List fields
832
+ tags = ConfigField(
833
+ cli_meta=CLIOption(
834
+ name="tags",
835
+ cli_option_str="--tag",
836
+ multiple=True,
837
+ click_type=PureStringKVPairType,
838
+ ),
839
+ field_type=list,
840
+ validation_fn=BasicAppValidations.tags,
841
+ help="The tags of the app to deploy.",
842
+ example=[{"foo": "bar"}, {"x": "y"}],
843
+ )
844
+ secrets = ConfigField(
845
+ cli_meta=CLIOption(
846
+ name="secrets", cli_option_str="--secret", multiple=True, click_type=str
847
+ ),
848
+ field_type=list,
849
+ help="Outerbounds integrations to attach to the app. You can use the value you set in the `@secrets` decorator in your code.",
850
+ example=["hf-token"],
851
+ validation_fn=BasicAppValidations.secrets,
852
+ )
853
+ compute_pools = ConfigField(
854
+ cli_meta=CLIOption(
855
+ name="compute_pools",
856
+ cli_option_str="--compute-pools",
857
+ multiple=True,
858
+ click_type=str,
859
+ ),
860
+ field_type=list,
861
+ help="A list of compute pools to deploy the app to.",
862
+ example=["default", "large"],
863
+ )
864
+ environment = ConfigField(
865
+ cli_meta=CLIOption(
866
+ name="environment",
867
+ cli_option_str="--env",
868
+ multiple=True,
869
+ click_type=JsonFriendlyKeyValuePairType, # TODO: Fix me.
870
+ ),
871
+ field_type=dict,
872
+ help="Environment variables to deploy with the App.",
873
+ example={
874
+ "DEBUG": True,
875
+ "DATABASE_CONFIG": {"host": "localhost", "port": 5432},
876
+ "ALLOWED_ORIGINS": ["http://localhost:3000", "https://myapp.com"],
877
+ },
878
+ )
879
+ commands = ConfigField(
880
+ cli_meta=None, # We dont expose commands as an options. We rather expose it like `--` with click.
881
+ field_type=list,
882
+ required=True, # Either from CLI or from config file.
883
+ help="A list of commands to run the app with.", # TODO: Fix me: make me configurable via the -- stuff in click.
884
+ example=["python app.py", "python app.py --foo bar"],
885
+ behavior=FieldBehavior.NOT_ALLOWED,
886
+ )
887
+
888
+ # Complex nested fields
889
+ resources = ConfigField(
890
+ cli_meta=None, # No top-level CLI option, only nested fields have CLI options
891
+ field_type=ResourceConfig,
892
+ # TODO : see if we can add a validation func for resources.
893
+ help="Resource configuration for the app.",
894
+ )
895
+ auth = ConfigField(
896
+ cli_meta=None, # No top-level CLI option, only nested fields have CLI options
897
+ field_type=AuthConfig,
898
+ help="Auth related configurations.",
899
+ validation_fn=AuthConfig.validate,
900
+ )
901
+ replicas = ConfigField(
902
+ cli_meta=None, # No top-level CLI option, only nested fields have CLI options
903
+ validation_fn=ReplicaConfig.validate,
904
+ field_type=ReplicaConfig,
905
+ default=ReplicaConfig.defaults,
906
+ help="The number of replicas to deploy the app with.",
907
+ )
908
+ dependencies = ConfigField(
909
+ cli_meta=None, # No top-level CLI option, only nested fields have CLI options
910
+ validation_fn=DependencyConfig.validate,
911
+ field_type=DependencyConfig,
912
+ available_in=ConfigFieldContext.CLI,
913
+ help="The dependencies to attach to the app. ",
914
+ )
915
+ package = ConfigField(
916
+ cli_meta=None, # No top-level CLI option, only nested fields have CLI options
917
+ field_type=PackageConfig,
918
+ help="Configurations associated with packaging the app.",
919
+ validation_fn=PackageConfig.validate,
920
+ available_in=ConfigFieldContext.CLI,
921
+ )
922
+
923
+ # Programmatic-only field for pre-packaged code
924
+ code_package = ConfigField(
925
+ cli_meta=None,
926
+ field_type=tuple, # PackagedCode is a namedtuple (tuple subclass)
927
+ strict_types=False, # Accept PackagedCode namedtuple from package_code()
928
+ available_in=ConfigFieldContext.PROGRAMMATIC,
929
+ help="Pre-packaged code from package_code(). A PackagedCode namedtuple containing url and key.",
930
+ )
931
+
932
+ no_deps = ConfigField(
933
+ cli_meta=CLIOption(
934
+ name="no_deps",
935
+ cli_option_str="--no-deps",
936
+ help="Do not any dependencies. Directly used the image provided",
937
+ is_flag=True,
938
+ ),
939
+ available_in=ConfigFieldContext.CLI,
940
+ field_type=bool,
941
+ default=False,
942
+ help="Do not bake any dependencies. Directly used the image provided",
943
+ )
944
+
945
+ force_upgrade = ConfigField(
946
+ cli_meta=CLIOption(
947
+ name="force_upgrade",
948
+ cli_option_str="--force-upgrade",
949
+ help="Force upgrade the app even if it is currently being upgraded.",
950
+ is_flag=True,
951
+ ),
952
+ field_type=bool,
953
+ default=False,
954
+ help="Force upgrade the app even if it is currently being upgraded.",
955
+ )
956
+
957
+ # ------- Experimental -------------
958
+ # These options get treated in the `..experimental` module.
959
+ # If we move any option as a first class citizen then we need to move
960
+ # its capsule parsing from the `..experimental` module to the `..capsule.CapsuleInput` module.
961
+
962
+ persistence = ConfigField(
963
+ cli_meta=CLIOption(
964
+ name="persistence",
965
+ cli_option_str="--persistence",
966
+ choices=["none", "postgres"],
967
+ ),
968
+ validation_fn=BasicAppValidations.persistence,
969
+ field_type=str,
970
+ help="The persistence mode to deploy the app with.",
971
+ default="none",
972
+ example="postgres",
973
+ is_experimental=True,
974
+ )
975
+
976
+ project = ConfigField(
977
+ cli_meta=CLIOption(
978
+ name="project",
979
+ cli_option_str="--project",
980
+ ),
981
+ field_type=str,
982
+ help="The project name to deploy the app to.",
983
+ is_experimental=True,
984
+ example="my-project",
985
+ )
986
+ branch = ConfigField(
987
+ cli_meta=CLIOption(
988
+ name="branch",
989
+ cli_option_str="--branch",
990
+ ),
991
+ field_type=str,
992
+ help="The branch name to deploy the app to.",
993
+ is_experimental=True,
994
+ example="main",
995
+ )
996
+ models = ConfigField(
997
+ cli_meta=None,
998
+ field_type=list,
999
+ is_experimental=True,
1000
+ example=[{"asset_id": "model-123", "asset_instance_id": "instance-456"}],
1001
+ )
1002
+ data = ConfigField(
1003
+ cli_meta=None,
1004
+ field_type=list,
1005
+ is_experimental=True,
1006
+ example=[{"asset_id": "data-789", "asset_instance_id": "instance-101"}],
1007
+ )
1008
+ generate_static_url = ConfigField(
1009
+ cli_meta=CLIOption(
1010
+ name="generate_static_url",
1011
+ cli_option_str="--generate-static-url",
1012
+ is_flag=True,
1013
+ ),
1014
+ field_type=bool,
1015
+ help="Generate a static URL for the app based on its name.",
1016
+ default=False,
1017
+ )
1018
+ # ------- /Experimental -------------
1019
+
1020
+ def to_dict(self):
1021
+ return config_meta_to_dict(self)
1022
+
1023
+ @staticmethod
1024
+ def merge_configs(
1025
+ base_config: "CoreConfig", override_config: "CoreConfig"
1026
+ ) -> "CoreConfig":
1027
+ """
1028
+ Merge two configurations with override taking precedence.
1029
+
1030
+ Handles FieldBehavior for proper merging:
1031
+ - UNION: Merge values (for lists, dicts)
1032
+ - NOT_ALLOWED: Base config value takes precedence (override is ignored)
1033
+
1034
+ Args:
1035
+ base_config: Base configuration (lower precedence)
1036
+ override_config: Override configuration (higher precedence)
1037
+
1038
+ Returns:
1039
+ Merged CoreConfig instance
1040
+ """
1041
+ merged_config = CoreConfig()
1042
+
1043
+ # Process each field according to its behavior
1044
+ for field_name, field_info in CoreConfig._fields.items(): # type: ignore
1045
+ base_value = getattr(base_config, field_name, None)
1046
+ override_value = getattr(override_config, field_name, None)
1047
+
1048
+ # Get the behavior for this field
1049
+ behavior = getattr(field_info, "behavior", FieldBehavior.UNION)
1050
+
1051
+ merged_value = merge_field_values(
1052
+ base_value, override_value, field_info, behavior
1053
+ )
1054
+
1055
+ setattr(merged_config, field_name, merged_value)
1056
+
1057
+ return merged_config
1058
+
1059
+ def set_defaults(self):
1060
+ apply_defaults(self)
1061
+
1062
+ def validate(self):
1063
+ validate_config_meta(self)
1064
+
1065
+ @commit_owner_names_across_tree
1066
+ def commit(self):
1067
+ self.validate()
1068
+ validate_required_fields(self)
1069
+ self.set_defaults()
1070
+
1071
+ @classmethod
1072
+ def from_dict(cls, config_data: Dict[str, Any]) -> "CoreConfig":
1073
+ config = cls()
1074
+ # Define functions for dict source
1075
+ def get_dict_key(field_name, field_info):
1076
+ return field_name
1077
+
1078
+ def get_dict_value(source_data, key):
1079
+ return source_data.get(key)
1080
+
1081
+ populate_config_recursive(
1082
+ config, cls, config_data, get_dict_key, get_dict_value
1083
+ )
1084
+ return config
1085
+
1086
+ @classmethod
1087
+ def from_cli(cls, cli_options: Dict[str, Any]) -> "CoreConfig":
1088
+ config = cls()
1089
+ # Define functions for CLI source
1090
+ def get_cli_key(field_name, field_info):
1091
+ # Need to have a special Exception for commands since the Commands
1092
+ # are passed down via unprocessed args after `--` in click
1093
+ if field_name == cls.commands.name:
1094
+ return field_name
1095
+ # Return the CLI parameter name if CLI metadata exists
1096
+ if field_info.cli_meta and not field_info.cli_meta.hidden:
1097
+ return field_info.cli_meta.name
1098
+ return None
1099
+
1100
+ def get_cli_value(source_data, key):
1101
+ value = source_data.get(key)
1102
+ # Only return non-None values since None means not set in CLI
1103
+ if value is None:
1104
+ return None
1105
+ if key == cls.environment.name:
1106
+ _env_dict = {}
1107
+ for v in value:
1108
+ _env_dict.update(v)
1109
+ return _env_dict
1110
+ if type(value) == tuple or type(value) == list:
1111
+ obj = list(x for x in source_data[key])
1112
+ if len(obj) == 0:
1113
+ return None # Dont return Empty Lists so that we can set Nones
1114
+ return obj
1115
+ return value
1116
+
1117
+ # Use common recursive population function with nested value checking
1118
+ populate_config_recursive(
1119
+ config,
1120
+ cls,
1121
+ cli_options,
1122
+ get_cli_key,
1123
+ get_cli_value,
1124
+ )
1125
+ return config