flyte 2.0.0b22__py3-none-any.whl → 2.0.0b24__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 flyte might be problematic. Click here for more details.

Files changed (90) hide show
  1. flyte/__init__.py +7 -1
  2. flyte/_bin/runtime.py +35 -5
  3. flyte/_cache/cache.py +4 -2
  4. flyte/_cache/local_cache.py +215 -0
  5. flyte/_code_bundle/bundle.py +10 -2
  6. flyte/_context.py +4 -1
  7. flyte/_debug/constants.py +0 -1
  8. flyte/_debug/vscode.py +6 -1
  9. flyte/_deploy.py +193 -52
  10. flyte/_environment.py +5 -0
  11. flyte/_excepthook.py +1 -1
  12. flyte/_image.py +104 -75
  13. flyte/_initialize.py +51 -0
  14. flyte/_internal/controllers/_local_controller.py +64 -24
  15. flyte/_internal/controllers/remote/_action.py +4 -1
  16. flyte/_internal/controllers/remote/_controller.py +5 -2
  17. flyte/_internal/controllers/remote/_core.py +6 -3
  18. flyte/_internal/controllers/remote/_informer.py +1 -1
  19. flyte/_internal/imagebuild/docker_builder.py +92 -28
  20. flyte/_internal/imagebuild/image_builder.py +7 -13
  21. flyte/_internal/imagebuild/remote_builder.py +6 -1
  22. flyte/_internal/runtime/io.py +13 -1
  23. flyte/_internal/runtime/rusty.py +17 -2
  24. flyte/_internal/runtime/task_serde.py +11 -21
  25. flyte/_internal/runtime/taskrunner.py +1 -1
  26. flyte/_internal/runtime/trigger_serde.py +153 -0
  27. flyte/_logging.py +1 -1
  28. flyte/_protos/common/identifier_pb2.py +19 -1
  29. flyte/_protos/common/identifier_pb2.pyi +22 -0
  30. flyte/_protos/workflow/common_pb2.py +14 -3
  31. flyte/_protos/workflow/common_pb2.pyi +49 -0
  32. flyte/_protos/workflow/queue_service_pb2.py +41 -35
  33. flyte/_protos/workflow/queue_service_pb2.pyi +26 -12
  34. flyte/_protos/workflow/queue_service_pb2_grpc.py +34 -0
  35. flyte/_protos/workflow/run_definition_pb2.py +38 -38
  36. flyte/_protos/workflow/run_definition_pb2.pyi +4 -2
  37. flyte/_protos/workflow/run_service_pb2.py +60 -50
  38. flyte/_protos/workflow/run_service_pb2.pyi +24 -6
  39. flyte/_protos/workflow/run_service_pb2_grpc.py +34 -0
  40. flyte/_protos/workflow/task_definition_pb2.py +15 -11
  41. flyte/_protos/workflow/task_definition_pb2.pyi +19 -2
  42. flyte/_protos/workflow/task_service_pb2.py +18 -17
  43. flyte/_protos/workflow/task_service_pb2.pyi +5 -2
  44. flyte/_protos/workflow/trigger_definition_pb2.py +66 -0
  45. flyte/_protos/workflow/trigger_definition_pb2.pyi +117 -0
  46. flyte/_protos/workflow/trigger_definition_pb2_grpc.py +4 -0
  47. flyte/_protos/workflow/trigger_service_pb2.py +96 -0
  48. flyte/_protos/workflow/trigger_service_pb2.pyi +110 -0
  49. flyte/_protos/workflow/trigger_service_pb2_grpc.py +281 -0
  50. flyte/_run.py +42 -15
  51. flyte/_task.py +36 -4
  52. flyte/_task_environment.py +62 -15
  53. flyte/_trigger.py +382 -0
  54. flyte/_version.py +3 -3
  55. flyte/cli/_abort.py +3 -3
  56. flyte/cli/_build.py +1 -3
  57. flyte/cli/_common.py +29 -2
  58. flyte/cli/_create.py +74 -0
  59. flyte/cli/_delete.py +23 -1
  60. flyte/cli/_deploy.py +13 -9
  61. flyte/cli/_get.py +75 -34
  62. flyte/cli/_params.py +4 -2
  63. flyte/cli/_run.py +27 -22
  64. flyte/cli/_update.py +36 -0
  65. flyte/cli/_user.py +17 -0
  66. flyte/cli/main.py +9 -1
  67. flyte/errors.py +9 -0
  68. flyte/extend.py +4 -0
  69. flyte/io/_dir.py +513 -115
  70. flyte/io/_file.py +495 -135
  71. flyte/models.py +32 -0
  72. flyte/remote/__init__.py +6 -1
  73. flyte/remote/_client/_protocols.py +36 -2
  74. flyte/remote/_client/controlplane.py +19 -3
  75. flyte/remote/_run.py +42 -2
  76. flyte/remote/_task.py +14 -1
  77. flyte/remote/_trigger.py +308 -0
  78. flyte/remote/_user.py +33 -0
  79. flyte/storage/__init__.py +6 -1
  80. flyte/storage/_storage.py +119 -101
  81. flyte/types/_pickle.py +16 -3
  82. {flyte-2.0.0b22.data → flyte-2.0.0b24.data}/scripts/runtime.py +35 -5
  83. {flyte-2.0.0b22.dist-info → flyte-2.0.0b24.dist-info}/METADATA +3 -1
  84. {flyte-2.0.0b22.dist-info → flyte-2.0.0b24.dist-info}/RECORD +89 -77
  85. flyte/_protos/secret/secret_pb2_grpc_grpc.py +0 -198
  86. {flyte-2.0.0b22.data → flyte-2.0.0b24.data}/scripts/debug.py +0 -0
  87. {flyte-2.0.0b22.dist-info → flyte-2.0.0b24.dist-info}/WHEEL +0 -0
  88. {flyte-2.0.0b22.dist-info → flyte-2.0.0b24.dist-info}/entry_points.txt +0 -0
  89. {flyte-2.0.0b22.dist-info → flyte-2.0.0b24.dist-info}/licenses/LICENSE +0 -0
  90. {flyte-2.0.0b22.dist-info → flyte-2.0.0b24.dist-info}/top_level.txt +0 -0
@@ -12,6 +12,7 @@ from typing import (
12
12
  List,
13
13
  Literal,
14
14
  Optional,
15
+ Tuple,
15
16
  Union,
16
17
  cast,
17
18
  )
@@ -22,16 +23,16 @@ from ._cache import Cache, CacheRequest
22
23
  from ._doc import Documentation
23
24
  from ._environment import Environment
24
25
  from ._image import Image
26
+ from ._pod import PodTemplate
25
27
  from ._resources import Resources
26
28
  from ._retry import RetryStrategy
27
29
  from ._reusable_environment import ReusePolicy
28
30
  from ._secret import SecretRequest
29
31
  from ._task import AsyncFunctionTaskTemplate, TaskTemplate
32
+ from ._trigger import Trigger
30
33
  from .models import MAX_INLINE_IO_BYTES, NativeInterface
31
34
 
32
35
  if TYPE_CHECKING:
33
- from kubernetes.client import V1PodTemplate
34
-
35
36
  from ._task import FunctionTypes, P, R
36
37
 
37
38
 
@@ -60,13 +61,18 @@ class TaskEnvironment(Environment):
60
61
  that depend on each other.
61
62
  :param cache: Cache policy for the environment.
62
63
  :param reusable: Reuse policy for the environment, if set, a python process may be reused for multiple tasks.
64
+ :param plugin_config: Optional plugin configuration for custom task types.
65
+ If set, all tasks in this environment will use the specified plugin configuration.
66
+ :param queue: Optional queue name to use for tasks in this environment.
67
+ If not set, the default queue will be used.
68
+ :param pod_template: Optional pod template to use for tasks in this environment.
69
+ If not set, the default pod template will be used.
63
70
  """
64
71
 
65
72
  cache: CacheRequest = "disable"
66
73
  reusable: ReusePolicy | None = None
67
74
  plugin_config: Optional[Any] = None
68
- # TODO Shall we make this union of string or env? This way we can lookup the env by module/file:name
69
- # TODO also we could add list of files that are used by this environment
75
+ queue: Optional[str] = None
70
76
 
71
77
  _tasks: Dict[str, TaskTemplate] = field(default_factory=dict, init=False)
72
78
 
@@ -87,6 +93,8 @@ class TaskEnvironment(Environment):
87
93
  env_vars: Optional[Dict[str, str]] = None,
88
94
  secrets: Optional[SecretRequest] = None,
89
95
  depends_on: Optional[List[Environment]] = None,
96
+ description: Optional[str] = None,
97
+ interruptible: Optional[bool] = None,
90
98
  **kwargs: Any,
91
99
  ) -> TaskEnvironment:
92
100
  """
@@ -102,6 +110,11 @@ class TaskEnvironment(Environment):
102
110
  :param depends_on: The environment dependencies to hint, so when you deploy the environment,
103
111
  the dependencies are also deployed. This is useful when you have a set of environments
104
112
  that depend on each other.
113
+ :param queue: The queue name to use for tasks in this environment.
114
+ :param pod_template: The pod template to use for tasks in this environment.
115
+ :param description: The description of the environment.
116
+ :param interruptible: Whether the environment is interruptible and can be scheduled on spot/preemptible
117
+ instances.
105
118
  :param kwargs: Additional parameters to override the environment (e.g., cache, reusable, plugin_config).
106
119
  """
107
120
  cache = kwargs.pop("cache", None)
@@ -131,6 +144,10 @@ class TaskEnvironment(Environment):
131
144
  kwargs["secrets"] = secrets
132
145
  if depends_on is not None:
133
146
  kwargs["depends_on"] = depends_on
147
+ if description is not None:
148
+ kwargs["description"] = description
149
+ if interruptible is not None:
150
+ kwargs["interruptible"] = interruptible
134
151
  return replace(self, **kwargs)
135
152
 
136
153
  def task(
@@ -142,10 +159,13 @@ class TaskEnvironment(Environment):
142
159
  retries: Union[int, RetryStrategy] = 0,
143
160
  timeout: Union[timedelta, int] = 0,
144
161
  docs: Optional[Documentation] = None,
145
- pod_template: Optional[Union[str, "V1PodTemplate"]] = None,
162
+ pod_template: Optional[Union[str, PodTemplate]] = None,
146
163
  report: bool = False,
164
+ interruptible: bool | None = None,
147
165
  max_inline_io_bytes: int = MAX_INLINE_IO_BYTES,
148
- ) -> Union[AsyncFunctionTaskTemplate, Callable[P, R]]:
166
+ queue: Optional[str] = None,
167
+ triggers: Tuple[Trigger, ...] | Trigger = (),
168
+ ) -> Union[AsyncFunctionTaskTemplate[P, R], Callable[P, R]]:
149
169
  """
150
170
  Decorate a function to be a task.
151
171
 
@@ -162,6 +182,12 @@ class TaskEnvironment(Environment):
162
182
  :param report: Optional Whether to generate the html report for the task, defaults to False.
163
183
  :param max_inline_io_bytes: Maximum allowed size (in bytes) for all inputs and outputs passed directly to the
164
184
  task (e.g., primitives, strings, dicts). Does not apply to files, directories, or dataframes.
185
+ :param triggers: Optional A tuple of triggers to associate with the task. This allows the task to be run on a
186
+ schedule or in response to events. Triggers can be defined using the `flyte.trigger` module.
187
+ :param interruptible: Optional Whether the task is interruptible, defaults to environment setting.
188
+ :param queue: Optional queue name to use for this task. If not set, the environment's queue will be used.
189
+
190
+ :return: A TaskTemplate that can be used to deploy the task.
165
191
  """
166
192
  from ._task import P, R
167
193
 
@@ -209,11 +235,15 @@ class TaskEnvironment(Environment):
209
235
  secrets=self.secrets,
210
236
  pod_template=pod_template or self.pod_template,
211
237
  parent_env=weakref.ref(self),
238
+ parent_env_name=self.name,
212
239
  interface=NativeInterface.from_callable(func),
213
240
  report=report,
214
241
  short_name=short,
215
242
  plugin_config=self.plugin_config,
216
243
  max_inline_io_bytes=max_inline_io_bytes,
244
+ queue=queue or self.queue,
245
+ interruptible=interruptible if interruptible is not None else self.interruptible,
246
+ triggers=triggers if isinstance(triggers, tuple) else (triggers,),
217
247
  )
218
248
  self._tasks[task_name] = tmpl
219
249
  return tmpl
@@ -229,16 +259,33 @@ class TaskEnvironment(Environment):
229
259
  """
230
260
  return self._tasks
231
261
 
232
- def add_task(self, task: TaskTemplate) -> TaskTemplate:
262
+ @classmethod
263
+ def from_task(cls, name: str, *tasks: TaskTemplate) -> TaskEnvironment:
233
264
  """
234
- Add a task to the environment.
265
+ Create a TaskEnvironment from a list of tasks. All tasks should have the same image or no Image defined.
266
+ Similarity of Image is determined by the python reference, not by value.
267
+
268
+ If images are different, an error is raised. If no image is defined, the image is set to "auto".
235
269
 
236
- Useful when you want to add a task to an environment that is not defined using the `task` decorator.
270
+ For any other tasks that need to be use these tasks, the returned environment can be used in the `depends_on`
271
+ attribute of the other TaskEnvironment.
272
+
273
+ :param name: The name of the environment.
274
+ :param tasks: The list of tasks to create the environment from.
237
275
 
238
- :param task: The TaskTemplate to add to this environment.
276
+ :raises ValueError: If tasks are assigned to multiple environments or have different images.
277
+ :return: The created TaskEnvironment.
239
278
  """
240
- if task.name in self._tasks:
241
- raise ValueError(f"Task {task.name} already exists in the environment. Task names should be unique.")
242
- self._tasks[task.name] = task
243
- task.parent_env = weakref.ref(self)
244
- return task
279
+ envs = [t.parent_env() for t in tasks if t.parent_env and t.parent_env() is not None]
280
+ if envs:
281
+ raise ValueError("Tasks cannot assigned to multiple environments.")
282
+ images = {t.image for t in tasks}
283
+ if len(images) > 1:
284
+ raise ValueError("Tasks must have the same image to be in the same environment.")
285
+ image: Union[str, Image] = images.pop() if images else "auto"
286
+ env = cls(name, image=image)
287
+ for t in tasks:
288
+ env._tasks[t.name] = t
289
+ t.parent_env = weakref.ref(env)
290
+ t.parent_env_name = name
291
+ return env
flyte/_trigger.py ADDED
@@ -0,0 +1,382 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from datetime import datetime
5
+ from typing import Any, Dict, Mapping, Union
6
+
7
+ import rich.repr
8
+
9
+
10
+ class _trigger_time:
11
+ """
12
+ This class represents the actual time of Trigger, which can be bound to any task input.
13
+ """
14
+
15
+
16
+ TriggerTime = _trigger_time()
17
+
18
+
19
+ @rich.repr.auto
20
+ @dataclass(frozen=True)
21
+ class Cron:
22
+ """
23
+ This class defines a Cron automation that can be associated with a Trigger in Flyte.
24
+ Example usage:
25
+ ```python
26
+ from flyte.trigger import Trigger, Cron
27
+ my_trigger = Trigger(
28
+ name="my_cron_trigger",
29
+ automation=Cron("0 * * * *"), # Runs every hour
30
+ description="A trigger that runs every hour",
31
+ )
32
+ ```
33
+ """
34
+
35
+ expression: str
36
+
37
+ def __str__(self):
38
+ return f"Cron Trigger: {self.expression}"
39
+
40
+
41
+ @rich.repr.auto
42
+ @dataclass(frozen=True)
43
+ class FixedRate:
44
+ """
45
+ This class defines a FixedRate automation that can be associated with a Trigger in Flyte.
46
+ Example usage:
47
+ ```python
48
+ from flyte.trigger import Trigger, FixedRate
49
+ my_trigger = Trigger(
50
+ name="my_fixed_rate_trigger",
51
+ automation=FixedRate(60), # Runs every hour
52
+ description="A trigger that runs every hour",
53
+ )
54
+ ```
55
+ """
56
+
57
+ interval_minutes: int
58
+ start_time: datetime | None = None
59
+
60
+ def __str__(self):
61
+ return f"FixedRate Trigger: every {self.interval_minutes} minutes"
62
+
63
+
64
+ @rich.repr.auto
65
+ @dataclass(frozen=True)
66
+ class Trigger:
67
+ """
68
+ This class defines specification of a Trigger, that can be associated with any Flyte V2 task.
69
+ The trigger then is deployed to the Flyte Platform.
70
+
71
+ Triggers can be used to run tasks on a schedule, in response to events, or based on other conditions.
72
+ The `Trigger` class encapsulates the metadata and configuration needed to define a trigger.
73
+
74
+ You can associate the same Trigger object with multiple tasks.
75
+
76
+ Example usage:
77
+ ```python
78
+ from flyte.trigger import Trigger
79
+ my_trigger = Trigger(
80
+ name="my_trigger",
81
+ description="A trigger that runs every hour",
82
+ )
83
+ ```
84
+
85
+ :param name: (str) The name of the trigger.
86
+ :param automation: (AutomationType) The automation type, currently only supports Cron.
87
+ :param description: (str) A description of the trigger, default is an empty string.
88
+ :param auto_activate: (bool) Whether the trigger should be automatically activated, default is True.
89
+ :param inputs: (Dict[str, Any]) Optional inputs for the trigger, default is None. If provided, will replace the
90
+ values for inputs to these defaults.
91
+ :param env_vars: (Dict[str, str]) Optional environment variables for the trigger, default is None. If provided, will
92
+ replace the environment variables set in the config of the task.
93
+ :param interruptible: (bool) Whether the trigger is interruptible, default is None. If provided,
94
+ it overrides whatever is set in the config of the task.
95
+ :param overwrite_cache: (bool) Whether to overwrite the cache, default is False.
96
+ :param queue: (str) Optional queue to run the trigger in, default is None.
97
+ :param labels: (Mapping[str, str]) Optional labels to attach to the trigger, default is None.
98
+ :param annotations: (Mapping[str, str]) Optional annotations to attach to the trigger, default is None.
99
+ """
100
+
101
+ name: str
102
+ automation: Union[Cron, FixedRate]
103
+ description: str = ""
104
+ auto_activate: bool = True
105
+ inputs: Dict[str, Any] | None = None
106
+ env_vars: Dict[str, str] | None = None
107
+ interruptible: bool | None = None
108
+ overwrite_cache: bool = False
109
+ queue: str | None = None
110
+ labels: Mapping[str, str] | None = None
111
+ annotations: Mapping[str, str] | None = None
112
+
113
+ def __post_init__(self):
114
+ if not self.name:
115
+ raise ValueError("Trigger name cannot be empty")
116
+ if self.automation is None:
117
+ raise ValueError("Automation cannot be None")
118
+
119
+ @classmethod
120
+ def daily(
121
+ cls,
122
+ trigger_time_input_key: str = "trigger_time",
123
+ *,
124
+ name: str = "daily",
125
+ description: str = "A trigger that runs daily at midnight",
126
+ auto_activate: bool = True,
127
+ inputs: Dict[str, Any] | None = None,
128
+ env_vars: Dict[str, str] | None = None,
129
+ interruptible: bool | None = None,
130
+ overwrite_cache: bool = False,
131
+ queue: str | None = None,
132
+ labels: Mapping[str, str] | None = None,
133
+ annotations: Mapping[str, str] | None = None,
134
+ ) -> Trigger:
135
+ """
136
+ Creates a Cron trigger that runs daily at midnight.
137
+
138
+ Args:
139
+ trigger_time_input_key (str): The input key for the trigger time, default is "trigger_time".
140
+ name (str): The name of the trigger, default is "daily".
141
+ description (str): A description of the trigger.
142
+ auto_activate (bool): Whether the trigger should be automatically activated.
143
+ inputs (Dict[str, Any] | None): Optional inputs for the trigger.
144
+ env_vars (Dict[str, str] | None): Optional environment variables.
145
+ interruptible (bool | None): Whether the trigger is interruptible.
146
+ overwrite_cache (bool): Whether to overwrite the cache.
147
+ queue (str | None): Optional queue to run the trigger in.
148
+ labels (Mapping[str, str] | None): Optional labels to attach to the trigger.
149
+ annotations (Mapping[str, str] | None): Optional annotations to attach to the trigger.
150
+
151
+ Returns:
152
+ Trigger: A trigger that runs daily at midnight.
153
+ """
154
+ final_inputs = {trigger_time_input_key: TriggerTime}
155
+ if inputs:
156
+ final_inputs.update(inputs)
157
+
158
+ return cls(
159
+ name=name,
160
+ automation=Cron("0 0 * * *"), # Cron expression for daily at midnight
161
+ description=description,
162
+ auto_activate=auto_activate,
163
+ inputs=final_inputs,
164
+ env_vars=env_vars,
165
+ interruptible=interruptible,
166
+ overwrite_cache=overwrite_cache,
167
+ queue=queue,
168
+ labels=labels,
169
+ annotations=annotations,
170
+ )
171
+
172
+ @classmethod
173
+ def hourly(
174
+ cls,
175
+ trigger_time_input_key: str = "trigger_time",
176
+ *,
177
+ name: str = "hourly",
178
+ description: str = "A trigger that runs every hour",
179
+ auto_activate: bool = True,
180
+ inputs: Dict[str, Any] | None = None,
181
+ env_vars: Dict[str, str] | None = None,
182
+ interruptible: bool | None = None,
183
+ overwrite_cache: bool = False,
184
+ queue: str | None = None,
185
+ labels: Mapping[str, str] | None = None,
186
+ annotations: Mapping[str, str] | None = None,
187
+ ) -> Trigger:
188
+ """
189
+ Creates a Cron trigger that runs every hour.
190
+
191
+ Args:
192
+ trigger_time_input_key (str): The input parameter for the trigger time, default is "trigger_time".
193
+ name (str): The name of the trigger, default is "hourly".
194
+ description (str): A description of the trigger.
195
+ auto_activate (bool): Whether the trigger should be automatically activated.
196
+ inputs (Dict[str, Any] | None): Optional inputs for the trigger.
197
+ env_vars (Dict[str, str] | None): Optional environment variables.
198
+ interruptible (bool | None): Whether the trigger is interruptible.
199
+ overwrite_cache (bool): Whether to overwrite the cache.
200
+ queue (str | None): Optional queue to run the trigger in.
201
+ labels (Mapping[str, str] | None): Optional labels to attach to the trigger.
202
+ annotations (Mapping[str, str] | None): Optional annotations to attach to the trigger.
203
+
204
+ Returns:
205
+ Trigger: A trigger that runs every hour, on the hour.
206
+ """
207
+ final_inputs = {trigger_time_input_key: TriggerTime}
208
+ if inputs:
209
+ final_inputs.update(inputs)
210
+
211
+ return cls(
212
+ name=name,
213
+ automation=Cron("0 * * * *"), # Cron expression for every hour
214
+ description=description,
215
+ auto_activate=auto_activate,
216
+ inputs=final_inputs,
217
+ env_vars=env_vars,
218
+ interruptible=interruptible,
219
+ overwrite_cache=overwrite_cache,
220
+ queue=queue,
221
+ labels=labels,
222
+ annotations=annotations,
223
+ )
224
+
225
+ @classmethod
226
+ def minutely(
227
+ cls,
228
+ trigger_time_input_key: str = "trigger_time",
229
+ *,
230
+ name: str = "minutely",
231
+ description: str = "A trigger that runs every minute",
232
+ auto_activate: bool = True,
233
+ inputs: Dict[str, Any] | None = None,
234
+ env_vars: Dict[str, str] | None = None,
235
+ interruptible: bool | None = None,
236
+ overwrite_cache: bool = False,
237
+ queue: str | None = None,
238
+ labels: Mapping[str, str] | None = None,
239
+ annotations: Mapping[str, str] | None = None,
240
+ ) -> Trigger:
241
+ """
242
+ Creates a Cron trigger that runs every minute.
243
+
244
+ Args:
245
+ trigger_time_input_key (str): The input parameter for the trigger time, default is "trigger_time".
246
+ name (str): The name of the trigger, default is "every_minute".
247
+ description (str): A description of the trigger.
248
+ auto_activate (bool): Whether the trigger should be automatically activated.
249
+ inputs (Dict[str, Any] | None): Optional inputs for the trigger.
250
+ env_vars (Dict[str, str] | None): Optional environment variables.
251
+ interruptible (bool | None): Whether the trigger is interruptible.
252
+ overwrite_cache (bool): Whether to overwrite the cache.
253
+ queue (str | None): Optional queue to run the trigger in.
254
+ labels (Mapping[str, str] | None): Optional labels to attach to the trigger.
255
+ annotations (Mapping[str, str] | None): Optional annotations to attach to the trigger.
256
+
257
+ Returns:
258
+ Trigger: A trigger that runs every minute.
259
+ """
260
+ final_inputs = {trigger_time_input_key: TriggerTime}
261
+ if inputs:
262
+ final_inputs.update(inputs)
263
+
264
+ return cls(
265
+ name=name,
266
+ automation=Cron("* * * * *"), # Cron expression for every minute
267
+ description=description,
268
+ auto_activate=auto_activate,
269
+ inputs=final_inputs,
270
+ env_vars=env_vars,
271
+ interruptible=interruptible,
272
+ overwrite_cache=overwrite_cache,
273
+ queue=queue,
274
+ labels=labels,
275
+ annotations=annotations,
276
+ )
277
+
278
+ @classmethod
279
+ def weekly(
280
+ cls,
281
+ trigger_time_input_key: str = "trigger_time",
282
+ *,
283
+ name: str = "weekly",
284
+ description: str = "A trigger that runs weekly on Sundays at midnight",
285
+ auto_activate: bool = True,
286
+ inputs: Dict[str, Any] | None = None,
287
+ env_vars: Dict[str, str] | None = None,
288
+ interruptible: bool | None = None,
289
+ overwrite_cache: bool = False,
290
+ queue: str | None = None,
291
+ labels: Mapping[str, str] | None = None,
292
+ annotations: Mapping[str, str] | None = None,
293
+ ) -> Trigger:
294
+ """
295
+ Creates a Cron trigger that runs weekly on Sundays at midnight.
296
+
297
+ Args:
298
+ trigger_time_input_key (str): The input parameter for the trigger time, default is "trigger_time".
299
+ name (str): The name of the trigger, default is "weekly".
300
+ description (str): A description of the trigger.
301
+ auto_activate (bool): Whether the trigger should be automatically activated.
302
+ inputs (Dict[str, Any] | None): Optional inputs for the trigger.
303
+ env_vars (Dict[str, str] | None): Optional environment variables.
304
+ interruptible (bool | None): Whether the trigger is interruptible.
305
+ overwrite_cache (bool): Whether to overwrite the cache.
306
+ queue (str | None): Optional queue to run the trigger in.
307
+ labels (Mapping[str, str] | None): Optional labels to attach to the trigger.
308
+ annotations (Mapping[str, str] | None): Optional annotations to attach to the trigger.
309
+
310
+ Returns:
311
+ Trigger: A trigger that runs weekly on Sundays at midnight.
312
+ """
313
+ final_inputs = {trigger_time_input_key: TriggerTime}
314
+ if inputs:
315
+ final_inputs.update(inputs)
316
+
317
+ return cls(
318
+ name=name,
319
+ automation=Cron("0 0 * * 0"), # Cron expression for every Sunday at midnight
320
+ description=description,
321
+ auto_activate=auto_activate,
322
+ inputs=final_inputs,
323
+ env_vars=env_vars,
324
+ interruptible=interruptible,
325
+ overwrite_cache=overwrite_cache,
326
+ queue=queue,
327
+ labels=labels,
328
+ annotations=annotations,
329
+ )
330
+
331
+ @classmethod
332
+ def monthly(
333
+ cls,
334
+ trigger_time_input_key: str = "trigger_time",
335
+ *,
336
+ name: str = "monthly",
337
+ description: str = "A trigger that runs monthly on the 1st at midnight",
338
+ auto_activate: bool = True,
339
+ inputs: Dict[str, Any] | None = None,
340
+ env_vars: Dict[str, str] | None = None,
341
+ interruptible: bool | None = None,
342
+ overwrite_cache: bool = False,
343
+ queue: str | None = None,
344
+ labels: Mapping[str, str] | None = None,
345
+ annotations: Mapping[str, str] | None = None,
346
+ ) -> Trigger:
347
+ """
348
+ Creates a Cron trigger that runs monthly on the 1st at midnight.
349
+
350
+ Args:
351
+ trigger_time_input_key (str): The input parameter for the trigger time, default is "trigger_time".
352
+ name (str): The name of the trigger, default is "monthly".
353
+ description (str): A description of the trigger.
354
+ auto_activate (bool): Whether the trigger should be automatically activated.
355
+ inputs (Dict[str, Any] | None): Optional inputs for the trigger.
356
+ env_vars (Dict[str, str] | None): Optional environment variables.
357
+ interruptible (bool | None): Whether the trigger is interruptible.
358
+ overwrite_cache (bool): Whether to overwrite the cache.
359
+ queue (str | None): Optional queue to run the trigger in.
360
+ labels (Mapping[str, str] | None): Optional labels to attach to the trigger.
361
+ annotations (Mapping[str, str] | None): Optional annotations to attach to the trigger.
362
+
363
+ Returns:
364
+ Trigger: A trigger that runs monthly on the 1st at midnight.
365
+ """
366
+ final_inputs = {trigger_time_input_key: TriggerTime}
367
+ if inputs:
368
+ final_inputs.update(inputs)
369
+
370
+ return cls(
371
+ name=name,
372
+ automation=Cron("0 0 1 * *"), # Cron expression for monthly on the 1st at midnight
373
+ description=description,
374
+ auto_activate=auto_activate,
375
+ inputs=final_inputs,
376
+ env_vars=env_vars,
377
+ interruptible=interruptible,
378
+ overwrite_cache=overwrite_cache,
379
+ queue=queue,
380
+ labels=labels,
381
+ annotations=annotations,
382
+ )
flyte/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.0.0b22'
32
- __version_tuple__ = version_tuple = (2, 0, 0, 'b22')
31
+ __version__ = version = '2.0.0b24'
32
+ __version_tuple__ = version_tuple = (2, 0, 0, 'b24')
33
33
 
34
- __commit_id__ = commit_id = 'gce9a6bede'
34
+ __commit_id__ = commit_id = 'gb6f235fcb'
flyte/cli/_abort.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import rich_click as click
2
- from rich.console import Console
3
2
 
4
3
  from flyte.cli import _common as common
5
4
 
@@ -23,6 +22,7 @@ def run(cfg: common.CLIConfig, run_name: str, project: str | None = None, domain
23
22
  cfg.init(project=project, domain=domain)
24
23
  r = Run.get(name=run_name)
25
24
  if r:
26
- console = Console()
27
- r.abort()
25
+ console = common.get_console()
26
+ with console.status(f"Aborting run '{run_name}'...", spinner="dots"):
27
+ r.abort()
28
28
  console.print(f"Run '{run_name}' has been aborted.")
flyte/cli/_build.py CHANGED
@@ -44,9 +44,7 @@ class BuildEnvCommand(click.Command):
44
44
  super().__init__(*args, **kwargs)
45
45
 
46
46
  def invoke(self, ctx: click.Context):
47
- from rich.console import Console
48
-
49
- console = Console()
47
+ console = common.get_console()
50
48
  console.print(f"Building Environment: {self.obj_name}")
51
49
  obj: CLIConfig = ctx.obj
52
50
  obj.init()
flyte/cli/_common.py CHANGED
@@ -1,11 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import importlib.util
4
+ import json
4
5
  import logging
5
6
  import os
6
7
  import sys
7
8
  from abc import abstractmethod
8
9
  from dataclasses import dataclass, replace
10
+ from functools import lru_cache
9
11
  from pathlib import Path
10
12
  from types import MappingProxyType, ModuleType
11
13
  from typing import Any, Dict, Iterable, List, Literal, Optional
@@ -19,10 +21,11 @@ from rich.pretty import pretty_repr
19
21
  from rich.table import Table
20
22
  from rich.traceback import Traceback
21
23
 
24
+ import flyte.config
22
25
  import flyte.errors
23
26
  from flyte.config import Config
24
27
 
25
- OutputFormat = Literal["table", "json", "table-simple"]
28
+ OutputFormat = Literal["table", "json", "table-simple", "json-raw"]
26
29
 
27
30
  PREFERRED_BORDER_COLOR = "dim cyan"
28
31
  PREFERRED_ACCENT_COLOR = "bold #FFD700"
@@ -177,7 +180,7 @@ class InvokeBaseMixin:
177
180
  except Exception as e:
178
181
  if ctx.obj and ctx.obj.log_level and ctx.obj.log_level <= logging.DEBUG:
179
182
  # If the user has requested verbose output, print the full traceback
180
- console = Console()
183
+ console = get_console()
181
184
  console.print(Traceback.from_exception(type(e), e, e.__traceback__))
182
185
  exit(1)
183
186
  else:
@@ -381,6 +384,11 @@ def format(title: str, vals: Iterable[Any], of: OutputFormat = "table") -> Table
381
384
  if not vals:
382
385
  return pretty_repr([])
383
386
  return pretty_repr([v.to_dict() for v in vals])
387
+ case "json-raw":
388
+ if not vals:
389
+ return []
390
+ return json.dumps([v.to_dict() for v in vals])
391
+
384
392
  raise click.ClickException("Unknown output format. Supported formats are: table, table-simple, json.")
385
393
 
386
394
 
@@ -395,3 +403,22 @@ def get_panel(title: str, renderable: Any, of: OutputFormat = "table") -> Panel:
395
403
  title=f"[{PREFERRED_ACCENT_COLOR}]{title}[/{PREFERRED_ACCENT_COLOR}]",
396
404
  border_style=PREFERRED_BORDER_COLOR,
397
405
  )
406
+
407
+
408
+ def get_console() -> Console:
409
+ """
410
+ Get a console that is configured to use colors if the terminal supports it.
411
+ """
412
+ return Console(color_system="auto", force_terminal=True, width=120)
413
+
414
+
415
+ @lru_cache()
416
+ def initialize_config(ctx: click.Context, project: str, domain: str, root_dir: str | None = None):
417
+ obj: CLIConfig | None = ctx.obj
418
+ if obj is None:
419
+ import flyte.config
420
+
421
+ obj = CLIConfig(flyte.config.auto(), ctx)
422
+
423
+ obj.init(project, domain, root_dir)
424
+ return obj