prefect-client 2.20.2__py3-none-any.whl → 3.0.0__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.
Files changed (288) hide show
  1. prefect/__init__.py +74 -110
  2. prefect/_internal/compatibility/deprecated.py +6 -115
  3. prefect/_internal/compatibility/experimental.py +4 -79
  4. prefect/_internal/compatibility/migration.py +166 -0
  5. prefect/_internal/concurrency/__init__.py +2 -2
  6. prefect/_internal/concurrency/api.py +1 -35
  7. prefect/_internal/concurrency/calls.py +0 -6
  8. prefect/_internal/concurrency/cancellation.py +0 -3
  9. prefect/_internal/concurrency/event_loop.py +0 -20
  10. prefect/_internal/concurrency/inspection.py +3 -3
  11. prefect/_internal/concurrency/primitives.py +1 -0
  12. prefect/_internal/concurrency/services.py +23 -0
  13. prefect/_internal/concurrency/threads.py +35 -0
  14. prefect/_internal/concurrency/waiters.py +0 -28
  15. prefect/_internal/integrations.py +7 -0
  16. prefect/_internal/pydantic/__init__.py +0 -45
  17. prefect/_internal/pydantic/annotations/pendulum.py +2 -2
  18. prefect/_internal/pydantic/v1_schema.py +21 -22
  19. prefect/_internal/pydantic/v2_schema.py +0 -2
  20. prefect/_internal/pydantic/v2_validated_func.py +18 -23
  21. prefect/_internal/pytz.py +1 -1
  22. prefect/_internal/retries.py +61 -0
  23. prefect/_internal/schemas/bases.py +45 -177
  24. prefect/_internal/schemas/fields.py +1 -43
  25. prefect/_internal/schemas/validators.py +47 -233
  26. prefect/agent.py +3 -695
  27. prefect/artifacts.py +173 -14
  28. prefect/automations.py +39 -4
  29. prefect/blocks/abstract.py +1 -1
  30. prefect/blocks/core.py +423 -164
  31. prefect/blocks/fields.py +2 -57
  32. prefect/blocks/notifications.py +43 -28
  33. prefect/blocks/redis.py +168 -0
  34. prefect/blocks/system.py +67 -20
  35. prefect/blocks/webhook.py +2 -9
  36. prefect/cache_policies.py +239 -0
  37. prefect/client/__init__.py +4 -0
  38. prefect/client/base.py +33 -27
  39. prefect/client/cloud.py +65 -20
  40. prefect/client/collections.py +1 -1
  41. prefect/client/orchestration.py +667 -440
  42. prefect/client/schemas/actions.py +115 -100
  43. prefect/client/schemas/filters.py +46 -52
  44. prefect/client/schemas/objects.py +228 -178
  45. prefect/client/schemas/responses.py +18 -36
  46. prefect/client/schemas/schedules.py +55 -36
  47. prefect/client/schemas/sorting.py +2 -0
  48. prefect/client/subscriptions.py +8 -7
  49. prefect/client/types/flexible_schedule_list.py +11 -0
  50. prefect/client/utilities.py +9 -6
  51. prefect/concurrency/asyncio.py +60 -11
  52. prefect/concurrency/context.py +24 -0
  53. prefect/concurrency/events.py +2 -2
  54. prefect/concurrency/services.py +46 -16
  55. prefect/concurrency/sync.py +51 -7
  56. prefect/concurrency/v1/asyncio.py +143 -0
  57. prefect/concurrency/v1/context.py +27 -0
  58. prefect/concurrency/v1/events.py +61 -0
  59. prefect/concurrency/v1/services.py +116 -0
  60. prefect/concurrency/v1/sync.py +92 -0
  61. prefect/context.py +246 -149
  62. prefect/deployments/__init__.py +33 -18
  63. prefect/deployments/base.py +10 -15
  64. prefect/deployments/deployments.py +2 -1048
  65. prefect/deployments/flow_runs.py +178 -0
  66. prefect/deployments/runner.py +72 -173
  67. prefect/deployments/schedules.py +31 -25
  68. prefect/deployments/steps/__init__.py +0 -1
  69. prefect/deployments/steps/core.py +7 -0
  70. prefect/deployments/steps/pull.py +15 -21
  71. prefect/deployments/steps/utility.py +2 -1
  72. prefect/docker/__init__.py +20 -0
  73. prefect/docker/docker_image.py +82 -0
  74. prefect/engine.py +15 -2466
  75. prefect/events/actions.py +17 -23
  76. prefect/events/cli/automations.py +20 -7
  77. prefect/events/clients.py +142 -80
  78. prefect/events/filters.py +14 -18
  79. prefect/events/related.py +74 -75
  80. prefect/events/schemas/__init__.py +0 -5
  81. prefect/events/schemas/automations.py +55 -46
  82. prefect/events/schemas/deployment_triggers.py +7 -197
  83. prefect/events/schemas/events.py +46 -65
  84. prefect/events/schemas/labelling.py +10 -14
  85. prefect/events/utilities.py +4 -5
  86. prefect/events/worker.py +23 -8
  87. prefect/exceptions.py +15 -0
  88. prefect/filesystems.py +30 -529
  89. prefect/flow_engine.py +827 -0
  90. prefect/flow_runs.py +379 -7
  91. prefect/flows.py +470 -360
  92. prefect/futures.py +382 -331
  93. prefect/infrastructure/__init__.py +5 -26
  94. prefect/infrastructure/base.py +3 -320
  95. prefect/infrastructure/provisioners/__init__.py +5 -3
  96. prefect/infrastructure/provisioners/cloud_run.py +13 -8
  97. prefect/infrastructure/provisioners/container_instance.py +14 -9
  98. prefect/infrastructure/provisioners/ecs.py +10 -8
  99. prefect/infrastructure/provisioners/modal.py +8 -5
  100. prefect/input/__init__.py +4 -0
  101. prefect/input/actions.py +2 -4
  102. prefect/input/run_input.py +9 -9
  103. prefect/logging/formatters.py +2 -4
  104. prefect/logging/handlers.py +9 -14
  105. prefect/logging/loggers.py +5 -5
  106. prefect/main.py +72 -0
  107. prefect/plugins.py +2 -64
  108. prefect/profiles.toml +16 -2
  109. prefect/records/__init__.py +1 -0
  110. prefect/records/base.py +223 -0
  111. prefect/records/filesystem.py +207 -0
  112. prefect/records/memory.py +178 -0
  113. prefect/records/result_store.py +64 -0
  114. prefect/results.py +577 -504
  115. prefect/runner/runner.py +124 -51
  116. prefect/runner/server.py +32 -34
  117. prefect/runner/storage.py +3 -12
  118. prefect/runner/submit.py +2 -10
  119. prefect/runner/utils.py +2 -2
  120. prefect/runtime/__init__.py +1 -0
  121. prefect/runtime/deployment.py +1 -0
  122. prefect/runtime/flow_run.py +40 -5
  123. prefect/runtime/task_run.py +1 -0
  124. prefect/serializers.py +28 -39
  125. prefect/server/api/collections_data/views/aggregate-worker-metadata.json +5 -14
  126. prefect/settings.py +209 -332
  127. prefect/states.py +160 -63
  128. prefect/task_engine.py +1478 -57
  129. prefect/task_runners.py +383 -287
  130. prefect/task_runs.py +240 -0
  131. prefect/task_worker.py +463 -0
  132. prefect/tasks.py +684 -374
  133. prefect/transactions.py +410 -0
  134. prefect/types/__init__.py +72 -86
  135. prefect/types/entrypoint.py +13 -0
  136. prefect/utilities/annotations.py +4 -3
  137. prefect/utilities/asyncutils.py +227 -148
  138. prefect/utilities/callables.py +138 -48
  139. prefect/utilities/collections.py +134 -86
  140. prefect/utilities/dispatch.py +27 -14
  141. prefect/utilities/dockerutils.py +11 -4
  142. prefect/utilities/engine.py +186 -32
  143. prefect/utilities/filesystem.py +4 -5
  144. prefect/utilities/importtools.py +26 -27
  145. prefect/utilities/pydantic.py +128 -38
  146. prefect/utilities/schema_tools/hydration.py +18 -1
  147. prefect/utilities/schema_tools/validation.py +30 -0
  148. prefect/utilities/services.py +35 -9
  149. prefect/utilities/templating.py +12 -2
  150. prefect/utilities/timeout.py +20 -5
  151. prefect/utilities/urls.py +195 -0
  152. prefect/utilities/visualization.py +1 -0
  153. prefect/variables.py +78 -59
  154. prefect/workers/__init__.py +0 -1
  155. prefect/workers/base.py +237 -244
  156. prefect/workers/block.py +5 -226
  157. prefect/workers/cloud.py +6 -0
  158. prefect/workers/process.py +265 -12
  159. prefect/workers/server.py +29 -11
  160. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/METADATA +30 -26
  161. prefect_client-3.0.0.dist-info/RECORD +201 -0
  162. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/WHEEL +1 -1
  163. prefect/_internal/pydantic/_base_model.py +0 -51
  164. prefect/_internal/pydantic/_compat.py +0 -82
  165. prefect/_internal/pydantic/_flags.py +0 -20
  166. prefect/_internal/pydantic/_types.py +0 -8
  167. prefect/_internal/pydantic/utilities/config_dict.py +0 -72
  168. prefect/_internal/pydantic/utilities/field_validator.py +0 -150
  169. prefect/_internal/pydantic/utilities/model_construct.py +0 -56
  170. prefect/_internal/pydantic/utilities/model_copy.py +0 -55
  171. prefect/_internal/pydantic/utilities/model_dump.py +0 -136
  172. prefect/_internal/pydantic/utilities/model_dump_json.py +0 -112
  173. prefect/_internal/pydantic/utilities/model_fields.py +0 -50
  174. prefect/_internal/pydantic/utilities/model_fields_set.py +0 -29
  175. prefect/_internal/pydantic/utilities/model_json_schema.py +0 -82
  176. prefect/_internal/pydantic/utilities/model_rebuild.py +0 -80
  177. prefect/_internal/pydantic/utilities/model_validate.py +0 -75
  178. prefect/_internal/pydantic/utilities/model_validate_json.py +0 -68
  179. prefect/_internal/pydantic/utilities/model_validator.py +0 -87
  180. prefect/_internal/pydantic/utilities/type_adapter.py +0 -71
  181. prefect/_vendor/fastapi/__init__.py +0 -25
  182. prefect/_vendor/fastapi/applications.py +0 -946
  183. prefect/_vendor/fastapi/background.py +0 -3
  184. prefect/_vendor/fastapi/concurrency.py +0 -44
  185. prefect/_vendor/fastapi/datastructures.py +0 -58
  186. prefect/_vendor/fastapi/dependencies/__init__.py +0 -0
  187. prefect/_vendor/fastapi/dependencies/models.py +0 -64
  188. prefect/_vendor/fastapi/dependencies/utils.py +0 -877
  189. prefect/_vendor/fastapi/encoders.py +0 -177
  190. prefect/_vendor/fastapi/exception_handlers.py +0 -40
  191. prefect/_vendor/fastapi/exceptions.py +0 -46
  192. prefect/_vendor/fastapi/logger.py +0 -3
  193. prefect/_vendor/fastapi/middleware/__init__.py +0 -1
  194. prefect/_vendor/fastapi/middleware/asyncexitstack.py +0 -25
  195. prefect/_vendor/fastapi/middleware/cors.py +0 -3
  196. prefect/_vendor/fastapi/middleware/gzip.py +0 -3
  197. prefect/_vendor/fastapi/middleware/httpsredirect.py +0 -3
  198. prefect/_vendor/fastapi/middleware/trustedhost.py +0 -3
  199. prefect/_vendor/fastapi/middleware/wsgi.py +0 -3
  200. prefect/_vendor/fastapi/openapi/__init__.py +0 -0
  201. prefect/_vendor/fastapi/openapi/constants.py +0 -2
  202. prefect/_vendor/fastapi/openapi/docs.py +0 -203
  203. prefect/_vendor/fastapi/openapi/models.py +0 -480
  204. prefect/_vendor/fastapi/openapi/utils.py +0 -485
  205. prefect/_vendor/fastapi/param_functions.py +0 -340
  206. prefect/_vendor/fastapi/params.py +0 -453
  207. prefect/_vendor/fastapi/py.typed +0 -0
  208. prefect/_vendor/fastapi/requests.py +0 -4
  209. prefect/_vendor/fastapi/responses.py +0 -40
  210. prefect/_vendor/fastapi/routing.py +0 -1331
  211. prefect/_vendor/fastapi/security/__init__.py +0 -15
  212. prefect/_vendor/fastapi/security/api_key.py +0 -98
  213. prefect/_vendor/fastapi/security/base.py +0 -6
  214. prefect/_vendor/fastapi/security/http.py +0 -172
  215. prefect/_vendor/fastapi/security/oauth2.py +0 -227
  216. prefect/_vendor/fastapi/security/open_id_connect_url.py +0 -34
  217. prefect/_vendor/fastapi/security/utils.py +0 -10
  218. prefect/_vendor/fastapi/staticfiles.py +0 -1
  219. prefect/_vendor/fastapi/templating.py +0 -3
  220. prefect/_vendor/fastapi/testclient.py +0 -1
  221. prefect/_vendor/fastapi/types.py +0 -3
  222. prefect/_vendor/fastapi/utils.py +0 -235
  223. prefect/_vendor/fastapi/websockets.py +0 -7
  224. prefect/_vendor/starlette/__init__.py +0 -1
  225. prefect/_vendor/starlette/_compat.py +0 -28
  226. prefect/_vendor/starlette/_exception_handler.py +0 -80
  227. prefect/_vendor/starlette/_utils.py +0 -88
  228. prefect/_vendor/starlette/applications.py +0 -261
  229. prefect/_vendor/starlette/authentication.py +0 -159
  230. prefect/_vendor/starlette/background.py +0 -43
  231. prefect/_vendor/starlette/concurrency.py +0 -59
  232. prefect/_vendor/starlette/config.py +0 -151
  233. prefect/_vendor/starlette/convertors.py +0 -87
  234. prefect/_vendor/starlette/datastructures.py +0 -707
  235. prefect/_vendor/starlette/endpoints.py +0 -130
  236. prefect/_vendor/starlette/exceptions.py +0 -60
  237. prefect/_vendor/starlette/formparsers.py +0 -276
  238. prefect/_vendor/starlette/middleware/__init__.py +0 -17
  239. prefect/_vendor/starlette/middleware/authentication.py +0 -52
  240. prefect/_vendor/starlette/middleware/base.py +0 -220
  241. prefect/_vendor/starlette/middleware/cors.py +0 -176
  242. prefect/_vendor/starlette/middleware/errors.py +0 -265
  243. prefect/_vendor/starlette/middleware/exceptions.py +0 -74
  244. prefect/_vendor/starlette/middleware/gzip.py +0 -113
  245. prefect/_vendor/starlette/middleware/httpsredirect.py +0 -19
  246. prefect/_vendor/starlette/middleware/sessions.py +0 -82
  247. prefect/_vendor/starlette/middleware/trustedhost.py +0 -64
  248. prefect/_vendor/starlette/middleware/wsgi.py +0 -147
  249. prefect/_vendor/starlette/py.typed +0 -0
  250. prefect/_vendor/starlette/requests.py +0 -328
  251. prefect/_vendor/starlette/responses.py +0 -347
  252. prefect/_vendor/starlette/routing.py +0 -933
  253. prefect/_vendor/starlette/schemas.py +0 -154
  254. prefect/_vendor/starlette/staticfiles.py +0 -248
  255. prefect/_vendor/starlette/status.py +0 -199
  256. prefect/_vendor/starlette/templating.py +0 -231
  257. prefect/_vendor/starlette/testclient.py +0 -804
  258. prefect/_vendor/starlette/types.py +0 -30
  259. prefect/_vendor/starlette/websockets.py +0 -193
  260. prefect/blocks/kubernetes.py +0 -119
  261. prefect/deprecated/__init__.py +0 -0
  262. prefect/deprecated/data_documents.py +0 -350
  263. prefect/deprecated/packaging/__init__.py +0 -12
  264. prefect/deprecated/packaging/base.py +0 -96
  265. prefect/deprecated/packaging/docker.py +0 -146
  266. prefect/deprecated/packaging/file.py +0 -92
  267. prefect/deprecated/packaging/orion.py +0 -80
  268. prefect/deprecated/packaging/serializers.py +0 -171
  269. prefect/events/instrument.py +0 -135
  270. prefect/infrastructure/container.py +0 -824
  271. prefect/infrastructure/kubernetes.py +0 -920
  272. prefect/infrastructure/process.py +0 -289
  273. prefect/manifests.py +0 -20
  274. prefect/new_flow_engine.py +0 -449
  275. prefect/new_task_engine.py +0 -423
  276. prefect/pydantic/__init__.py +0 -76
  277. prefect/pydantic/main.py +0 -39
  278. prefect/software/__init__.py +0 -2
  279. prefect/software/base.py +0 -50
  280. prefect/software/conda.py +0 -199
  281. prefect/software/pip.py +0 -122
  282. prefect/software/python.py +0 -52
  283. prefect/task_server.py +0 -322
  284. prefect_client-2.20.2.dist-info/RECORD +0 -294
  285. /prefect/{_internal/pydantic/utilities → client/types}/__init__.py +0 -0
  286. /prefect/{_vendor → concurrency/v1}/__init__.py +0 -0
  287. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/LICENSE +0 -0
  288. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/top_level.txt +0 -0
@@ -1,27 +1,6 @@
1
- from prefect.infrastructure.base import Infrastructure, InfrastructureResult
2
- from prefect.infrastructure.container import DockerContainer, DockerContainerResult
3
- from prefect.infrastructure.kubernetes import (
4
- KubernetesClusterConfig,
5
- KubernetesImagePullPolicy,
6
- KubernetesJob,
7
- KubernetesJobResult,
8
- KubernetesManifest,
9
- KubernetesRestartPolicy,
10
- )
11
- from prefect.infrastructure.process import Process, ProcessResult
1
+ """
2
+ 2024-06-27: This surfaces an actionable error message for moved or removed objects in Prefect 3.0 upgrade.
3
+ """
4
+ from prefect._internal.compatibility.migration import getattr_migration
12
5
 
13
- # Declare API
14
- __all__ = [
15
- "DockerContainer",
16
- "DockerContainerResult",
17
- "Infrastructure",
18
- "InfrastructureResult",
19
- "KubernetesClusterConfig",
20
- "KubernetesImagePullPolicy",
21
- "KubernetesJob",
22
- "KubernetesJobResult",
23
- "KubernetesManifest",
24
- "KubernetesRestartPolicy",
25
- "Process",
26
- "ProcessResult",
27
- ]
6
+ __getattr__ = getattr_migration(__name__)
@@ -1,323 +1,6 @@
1
1
  """
2
- DEPRECATION WARNING:
3
-
4
- This module is deprecated as of March 2024 and will not be available after September 2024.
5
- Infrastructure blocks have been replaced by workers, which offer enhanced functionality and better performance.
6
-
7
- For upgrade instructions, see https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/.
2
+ 2024-06-27: This surfaces an actionable error message for moved or removed objects in Prefect 3.0 upgrade.
8
3
  """
9
- import abc
10
- import shlex
11
- import warnings
12
- from typing import TYPE_CHECKING, Dict, List, Optional
13
-
14
- import anyio.abc
15
-
16
- from prefect._internal.compatibility.deprecated import deprecated_class
17
- from prefect._internal.compatibility.experimental import (
18
- EXPERIMENTAL_WARNING,
19
- ExperimentalFeature,
20
- experiment_enabled,
21
- )
22
- from prefect._internal.pydantic import HAS_PYDANTIC_V2
23
- from prefect.client.schemas.actions import WorkPoolCreate
24
- from prefect.exceptions import ObjectAlreadyExists
25
-
26
- if HAS_PYDANTIC_V2:
27
- import pydantic.v1 as pydantic
28
- else:
29
- import pydantic
30
-
31
- from rich.console import Console
32
- from typing_extensions import Self
33
-
34
- import prefect
35
- from prefect.blocks.core import Block, BlockNotSavedError
36
- from prefect.logging import get_logger
37
- from prefect.settings import (
38
- PREFECT_EXPERIMENTAL_WARN,
39
- PREFECT_EXPERIMENTAL_WARN_ENHANCED_CANCELLATION,
40
- PREFECT_UI_URL,
41
- get_current_settings,
42
- )
43
- from prefect.utilities.asyncutils import sync_compatible
44
-
45
- MIN_COMPAT_PREFECT_VERSION = "2.0b12"
46
-
47
-
48
- if TYPE_CHECKING:
49
- from prefect.client.schemas.objects import Deployment, Flow, FlowRun
50
-
51
-
52
- class InfrastructureResult(pydantic.BaseModel, abc.ABC):
53
- identifier: str
54
- status_code: int
55
-
56
- def __bool__(self):
57
- return self.status_code == 0
58
-
59
-
60
- @deprecated_class(
61
- start_date="Mar 2024",
62
- help="Use the `BaseWorker` class to create custom infrastructure integrations instead."
63
- " Refer to the upgrade guide for more information:"
64
- " https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/.",
65
- )
66
- class Infrastructure(Block, abc.ABC):
67
- _block_schema_capabilities = ["run-infrastructure"]
68
-
69
- type: str
70
-
71
- env: Dict[str, Optional[str]] = pydantic.Field(
72
- default_factory=dict,
73
- title="Environment",
74
- description="Environment variables to set in the configured infrastructure.",
75
- )
76
- labels: Dict[str, str] = pydantic.Field(
77
- default_factory=dict,
78
- description="Labels applied to the infrastructure for metadata purposes.",
79
- )
80
- name: Optional[str] = pydantic.Field(
81
- default=None,
82
- description="Name applied to the infrastructure for identification.",
83
- )
84
- command: Optional[List[str]] = pydantic.Field(
85
- default=None,
86
- description="The command to run in the infrastructure.",
87
- )
88
-
89
- async def generate_work_pool_base_job_template(self):
90
- if self._block_document_id is None:
91
- raise BlockNotSavedError(
92
- "Cannot publish as work pool, block has not been saved. Please call"
93
- " `.save()` on your block before publishing."
94
- )
95
-
96
- block_schema = self.__class__.schema()
97
- return {
98
- "job_configuration": {"block": "{{ block }}"},
99
- "variables": {
100
- "type": "object",
101
- "properties": {
102
- "block": {
103
- "title": "Block",
104
- "description": (
105
- "The infrastructure block to use for job creation."
106
- ),
107
- "allOf": [{"$ref": f"#/definitions/{self.__class__.__name__}"}],
108
- "default": {
109
- "$ref": {"block_document_id": str(self._block_document_id)}
110
- },
111
- }
112
- },
113
- "required": ["block"],
114
- "definitions": {self.__class__.__name__: block_schema},
115
- },
116
- }
117
-
118
- def get_corresponding_worker_type(self):
119
- return "block"
120
-
121
- @sync_compatible
122
- async def publish_as_work_pool(self, work_pool_name: Optional[str] = None):
123
- """
124
- Creates a work pool configured to use the given block as the job creator.
125
-
126
- Used to migrate from a agents setup to a worker setup.
127
-
128
- Args:
129
- work_pool_name: The name to give to the created work pool. If not provided, the name of the current
130
- block will be used.
131
- """
132
-
133
- base_job_template = await self.generate_work_pool_base_job_template()
134
- work_pool_name = work_pool_name or self._block_document_name
135
-
136
- if work_pool_name is None:
137
- raise ValueError(
138
- "`work_pool_name` must be provided if the block has not been saved."
139
- )
140
-
141
- console = Console()
142
-
143
- try:
144
- async with prefect.get_client() as client:
145
- work_pool = await client.create_work_pool(
146
- work_pool=WorkPoolCreate(
147
- name=work_pool_name,
148
- type=self.get_corresponding_worker_type(),
149
- base_job_template=base_job_template,
150
- )
151
- )
152
- except ObjectAlreadyExists:
153
- console.print(
154
- (
155
- f"Work pool with name {work_pool_name!r} already exists, please use"
156
- " a different name."
157
- ),
158
- style="red",
159
- )
160
- return
161
-
162
- console.print(
163
- f"Work pool {work_pool.name} created!",
164
- style="green",
165
- )
166
- if PREFECT_UI_URL:
167
- console.print(
168
- "You see your new work pool in the UI at"
169
- f" {PREFECT_UI_URL.value()}/work-pools/work-pool/{work_pool.name}"
170
- )
171
-
172
- deploy_script = (
173
- "my_flow.deploy(work_pool_name='{work_pool.name}', image='my_image:tag')"
174
- )
175
- if not hasattr(self, "image"):
176
- deploy_script = (
177
- "my_flow.from_source(source='https://github.com/org/repo.git',"
178
- f" entrypoint='flow.py:my_flow').deploy(work_pool_name='{work_pool.name}')"
179
- )
180
- console.print(
181
- "\nYou can deploy a flow to this work pool by calling"
182
- f" [blue].deploy[/]:\n\n\t{deploy_script}\n"
183
- )
184
- console.print(
185
- "\nTo start a worker to execute flow runs in this work pool run:\n"
186
- )
187
- console.print(f"\t[blue]prefect worker start --pool {work_pool.name}[/]\n")
188
-
189
- @abc.abstractmethod
190
- async def run(
191
- self,
192
- task_status: anyio.abc.TaskStatus = None,
193
- ) -> InfrastructureResult:
194
- """
195
- Run the infrastructure.
196
-
197
- If provided a `task_status`, the status will be reported as started when the
198
- infrastructure is successfully created. The status return value will be an
199
- identifier for the infrastructure.
200
-
201
- The call will then monitor the created infrastructure, returning a result at
202
- the end containing a status code indicating if the infrastructure exited cleanly
203
- or encountered an error.
204
- """
205
- # Note: implementations should include `sync_compatible`
206
-
207
- @abc.abstractmethod
208
- def preview(self) -> str:
209
- """
210
- View a preview of the infrastructure that would be run.
211
- """
212
-
213
- @property
214
- def logger(self):
215
- return get_logger(f"prefect.infrastructure.{self.type}")
216
-
217
- @property
218
- def is_using_a_runner(self):
219
- return self.command is not None and "prefect flow-run execute" in shlex.join(
220
- self.command
221
- )
222
-
223
- @classmethod
224
- def _base_environment(cls) -> Dict[str, str]:
225
- """
226
- Environment variables that should be passed to all created infrastructure.
227
-
228
- These values should be overridable with the `env` field.
229
- """
230
- return get_current_settings().to_environment_variables(exclude_unset=True)
231
-
232
- def prepare_for_flow_run(
233
- self: Self,
234
- flow_run: "FlowRun",
235
- deployment: Optional["Deployment"] = None,
236
- flow: Optional["Flow"] = None,
237
- ) -> Self:
238
- """
239
- Return an infrastructure block that is prepared to execute a flow run.
240
- """
241
- if deployment is not None:
242
- deployment_labels = self._base_deployment_labels(deployment)
243
- else:
244
- deployment_labels = {}
245
-
246
- if flow is not None:
247
- flow_labels = self._base_flow_labels(flow)
248
- else:
249
- flow_labels = {}
250
-
251
- return self.copy(
252
- update={
253
- "env": {**self._base_flow_run_environment(flow_run), **self.env},
254
- "labels": {
255
- **self._base_flow_run_labels(flow_run),
256
- **deployment_labels,
257
- **flow_labels,
258
- **self.labels,
259
- },
260
- "name": self.name or flow_run.name,
261
- "command": self.command or self._base_flow_run_command(),
262
- }
263
- )
264
-
265
- @staticmethod
266
- def _base_flow_run_command() -> List[str]:
267
- """
268
- Generate a command for a flow run job.
269
- """
270
- if experiment_enabled("enhanced_cancellation"):
271
- if (
272
- PREFECT_EXPERIMENTAL_WARN
273
- and PREFECT_EXPERIMENTAL_WARN_ENHANCED_CANCELLATION
274
- ):
275
- warnings.warn(
276
- EXPERIMENTAL_WARNING.format(
277
- feature="Enhanced flow run cancellation",
278
- group="enhanced_cancellation",
279
- help="",
280
- ),
281
- ExperimentalFeature,
282
- stacklevel=3,
283
- )
284
- return ["prefect", "flow-run", "execute"]
285
-
286
- return ["python", "-m", "prefect.engine"]
287
-
288
- @staticmethod
289
- def _base_flow_run_labels(flow_run: "FlowRun") -> Dict[str, str]:
290
- """
291
- Generate a dictionary of labels for a flow run job.
292
- """
293
- return {
294
- "prefect.io/flow-run-id": str(flow_run.id),
295
- "prefect.io/flow-run-name": flow_run.name,
296
- "prefect.io/version": prefect.__version__,
297
- }
298
-
299
- @staticmethod
300
- def _base_flow_run_environment(flow_run: "FlowRun") -> Dict[str, str]:
301
- """
302
- Generate a dictionary of environment variables for a flow run job.
303
- """
304
- environment = {}
305
- environment["PREFECT__FLOW_RUN_ID"] = str(flow_run.id)
306
- return environment
307
-
308
- @staticmethod
309
- def _base_deployment_labels(deployment: "Deployment") -> Dict[str, str]:
310
- labels = {
311
- "prefect.io/deployment-name": deployment.name,
312
- }
313
- if deployment.updated is not None:
314
- labels["prefect.io/deployment-updated"] = deployment.updated.in_timezone(
315
- "utc"
316
- ).to_iso8601_string()
317
- return labels
4
+ from prefect._internal.compatibility.migration import getattr_migration
318
5
 
319
- @staticmethod
320
- def _base_flow_labels(flow: "Flow") -> Dict[str, str]:
321
- return {
322
- "prefect.io/flow-name": flow.name,
323
- }
6
+ __getattr__ = getattr_migration(__name__)
@@ -1,12 +1,14 @@
1
- from typing import Any, Dict, Optional, Protocol, Type
1
+ from typing import TYPE_CHECKING, Any, Dict, Optional, Protocol, Type
2
2
 
3
- from prefect.client.orchestration import PrefectClient
4
3
  from prefect.infrastructure.provisioners.modal import ModalPushProvisioner
5
4
  from .cloud_run import CloudRunPushProvisioner
6
5
  from .container_instance import ContainerInstancePushProvisioner
7
6
  from .ecs import ElasticContainerServicePushProvisioner
8
7
  import rich.console
9
8
 
9
+ if TYPE_CHECKING:
10
+ from prefect.client.orchestration import PrefectClient
11
+
10
12
  _provisioners = {
11
13
  "cloud-run:push": CloudRunPushProvisioner,
12
14
  "cloud-run-v2:push": CloudRunPushProvisioner,
@@ -29,7 +31,7 @@ class Provisioner(Protocol):
29
31
  self,
30
32
  work_pool_name: str,
31
33
  base_job_template: Dict[str, Any],
32
- client: Optional[PrefectClient] = None,
34
+ client: Optional["PrefectClient"] = None,
33
35
  ) -> Dict[str, Any]:
34
36
  ...
35
37
 
@@ -5,7 +5,7 @@ import tempfile
5
5
  from copy import deepcopy
6
6
  from pathlib import Path
7
7
  from textwrap import dedent
8
- from typing import Any, Dict, Optional
8
+ from typing import TYPE_CHECKING, Any, Dict, Optional
9
9
  from uuid import UUID
10
10
 
11
11
  from anyio import run_process
@@ -17,7 +17,7 @@ from rich.prompt import Confirm
17
17
  from rich.syntax import Syntax
18
18
 
19
19
  from prefect.cli._prompts import prompt, prompt_select_from_table
20
- from prefect.client.orchestration import PrefectClient, ServerType
20
+ from prefect.client.orchestration import ServerType
21
21
  from prefect.client.schemas.actions import BlockDocumentCreate
22
22
  from prefect.client.utilities import inject_client
23
23
  from prefect.exceptions import ObjectAlreadyExists
@@ -27,6 +27,9 @@ from prefect.settings import (
27
27
  update_current_profile,
28
28
  )
29
29
 
30
+ if TYPE_CHECKING:
31
+ from prefect.client.orchestration import PrefectClient
32
+
30
33
 
31
34
  class CloudRunPushProvisioner:
32
35
  def __init__(self):
@@ -215,7 +218,7 @@ class CloudRunPushProvisioner:
215
218
  ) from e
216
219
 
217
220
  async def _create_gcp_credentials_block(
218
- self, block_document_name: str, key: dict, client: PrefectClient
221
+ self, block_document_name: str, key: dict, client: "PrefectClient"
219
222
  ) -> UUID:
220
223
  credentials_block_type = await client.read_block_type_by_slug("gcp-credentials")
221
224
 
@@ -242,7 +245,9 @@ class CloudRunPushProvisioner:
242
245
  )
243
246
  return block_doc.id
244
247
 
245
- async def _create_provision_table(self, work_pool_name: str, client: PrefectClient):
248
+ async def _create_provision_table(
249
+ self, work_pool_name: str, client: "PrefectClient"
250
+ ):
246
251
  return Panel(
247
252
  dedent(
248
253
  f"""\
@@ -268,7 +273,7 @@ class CloudRunPushProvisioner:
268
273
  )
269
274
 
270
275
  async def _customize_resource_names(
271
- self, work_pool_name: str, client: PrefectClient
276
+ self, work_pool_name: str, client: "PrefectClient"
272
277
  ) -> bool:
273
278
  self._service_account_name = prompt(
274
279
  "Please enter a name for the service account",
@@ -294,7 +299,7 @@ class CloudRunPushProvisioner:
294
299
  self,
295
300
  work_pool_name: str,
296
301
  base_job_template: dict,
297
- client: Optional[PrefectClient] = None,
302
+ client: Optional["PrefectClient"] = None,
298
303
  ) -> Dict[str, Any]:
299
304
  assert client, "Client injection failed"
300
305
  await self._verify_gcloud_ready()
@@ -399,7 +404,7 @@ class CloudRunPushProvisioner:
399
404
  dedent(
400
405
  f"""\
401
406
  from prefect import flow
402
- from prefect.deployments import DeploymentImage
407
+ from prefect.docker import DockerImage
403
408
 
404
409
 
405
410
  @flow(log_prints=True)
@@ -411,7 +416,7 @@ class CloudRunPushProvisioner:
411
416
  my_flow.deploy(
412
417
  name="my-deployment",
413
418
  work_pool_name="{work_pool_name}",
414
- image=DeploymentImage(
419
+ image=DockerImage(
415
420
  name="my-image:latest",
416
421
  platform="linux/amd64",
417
422
  )
@@ -10,6 +10,7 @@ Classes:
10
10
  ContainerInstancePushProvisioner: A class for provisioning infrastructure using Azure Container Instances.
11
11
 
12
12
  """
13
+
13
14
  import json
14
15
  import random
15
16
  import shlex
@@ -18,7 +19,7 @@ import subprocess
18
19
  import time
19
20
  from copy import deepcopy
20
21
  from textwrap import dedent
21
- from typing import Any, Dict, Optional
22
+ from typing import TYPE_CHECKING, Any, Dict, Optional
22
23
  from uuid import UUID
23
24
 
24
25
  from anyio import run_process
@@ -29,7 +30,6 @@ from rich.prompt import Confirm
29
30
  from rich.syntax import Syntax
30
31
 
31
32
  from prefect.cli._prompts import prompt, prompt_select_from_table
32
- from prefect.client.orchestration import PrefectClient
33
33
  from prefect.client.schemas.actions import BlockDocumentCreate
34
34
  from prefect.client.utilities import inject_client
35
35
  from prefect.exceptions import ObjectAlreadyExists, ObjectNotFound
@@ -38,6 +38,9 @@ from prefect.settings import (
38
38
  update_current_profile,
39
39
  )
40
40
 
41
+ if TYPE_CHECKING:
42
+ from prefect.client.orchestration import PrefectClient
43
+
41
44
 
42
45
  class AzureCLI:
43
46
  """
@@ -684,7 +687,7 @@ class ContainerInstancePushProvisioner:
684
687
  client_id: str,
685
688
  tenant_id: str,
686
689
  client_secret: str,
687
- client: PrefectClient,
690
+ client: "PrefectClient",
688
691
  ) -> UUID:
689
692
  """
690
693
  Creates a credentials block for Azure Container Instance.
@@ -755,7 +758,7 @@ class ContainerInstancePushProvisioner:
755
758
  raise e
756
759
 
757
760
  async def _aci_credentials_block_exists(
758
- self, block_name: str, client: PrefectClient
761
+ self, block_name: str, client: "PrefectClient"
759
762
  ) -> bool:
760
763
  """
761
764
  Checks if an ACI credentials block with the given name already exists.
@@ -782,7 +785,9 @@ class ContainerInstancePushProvisioner:
782
785
  else:
783
786
  return False
784
787
 
785
- async def _create_provision_table(self, work_pool_name: str, client: PrefectClient):
788
+ async def _create_provision_table(
789
+ self, work_pool_name: str, client: "PrefectClient"
790
+ ):
786
791
  return Panel(
787
792
  dedent(
788
793
  f"""\
@@ -809,7 +814,7 @@ class ContainerInstancePushProvisioner:
809
814
  )
810
815
 
811
816
  async def _customize_resource_names(
812
- self, work_pool_name: str, client: PrefectClient
817
+ self, work_pool_name: str, client: "PrefectClient"
813
818
  ) -> bool:
814
819
  self._resource_group_name = prompt(
815
820
  "Please enter a name for the resource group",
@@ -851,7 +856,7 @@ class ContainerInstancePushProvisioner:
851
856
  self,
852
857
  work_pool_name: str,
853
858
  base_job_template: Dict[str, Any],
854
- client: Optional[PrefectClient] = None,
859
+ client: Optional["PrefectClient"] = None,
855
860
  ) -> Dict[str, Any]:
856
861
  """
857
862
  Orchestrates the provisioning of Azure resources and setup for the push work pool.
@@ -1037,7 +1042,7 @@ class ContainerInstancePushProvisioner:
1037
1042
  dedent(
1038
1043
  f"""\
1039
1044
  from prefect import flow
1040
- from prefect.deployments import DeploymentImage
1045
+ from prefect.docker import DockerImage
1041
1046
 
1042
1047
 
1043
1048
  @flow(log_prints=True)
@@ -1049,7 +1054,7 @@ class ContainerInstancePushProvisioner:
1049
1054
  my_flow.deploy(
1050
1055
  name="my-deployment",
1051
1056
  work_pool_name="{work_pool_name}",
1052
- image=DeploymentImage(
1057
+ image=DockerImage(
1053
1058
  name="my-image:latest",
1054
1059
  platform="linux/amd64",
1055
1060
  )
@@ -9,7 +9,7 @@ import sys
9
9
  from copy import deepcopy
10
10
  from functools import partial
11
11
  from textwrap import dedent
12
- from typing import Any, Callable, Dict, List, Optional
12
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
13
13
 
14
14
  import anyio
15
15
  from anyio import run_process
@@ -20,7 +20,6 @@ from rich.prompt import Confirm
20
20
  from rich.syntax import Syntax
21
21
 
22
22
  from prefect.cli._prompts import prompt
23
- from prefect.client.orchestration import PrefectClient
24
23
  from prefect.client.schemas.actions import BlockDocumentCreate
25
24
  from prefect.client.utilities import inject_client
26
25
  from prefect.exceptions import ObjectNotFound
@@ -31,6 +30,9 @@ from prefect.settings import (
31
30
  from prefect.utilities.collections import get_from_dict
32
31
  from prefect.utilities.importtools import lazy_import
33
32
 
33
+ if TYPE_CHECKING:
34
+ from prefect.client.orchestration import PrefectClient
35
+
34
36
  boto3 = lazy_import("boto3")
35
37
 
36
38
  current_console = contextvars.ContextVar("console", default=Console())
@@ -250,7 +252,7 @@ class CredentialsBlockResource:
250
252
 
251
253
  @inject_client
252
254
  async def requires_provisioning(
253
- self, client: Optional[PrefectClient] = None
255
+ self, client: Optional["PrefectClient"] = None
254
256
  ) -> bool:
255
257
  if self._requires_provisioning is None:
256
258
  try:
@@ -280,7 +282,7 @@ class CredentialsBlockResource:
280
282
  self,
281
283
  base_job_template: Dict[str, Any],
282
284
  advance: Callable[[], None],
283
- client: Optional[PrefectClient] = None,
285
+ client: Optional["PrefectClient"] = None,
284
286
  ):
285
287
  """
286
288
  Provisions an AWS credentials block.
@@ -365,7 +367,7 @@ class AuthenticationResource:
365
367
  work_pool_name: str,
366
368
  user_name: str = "prefect-ecs-user",
367
369
  policy_name: str = "prefect-ecs-policy",
368
- credentials_block_name: str = None,
370
+ credentials_block_name: Optional[str] = None,
369
371
  ):
370
372
  self._user_name = user_name
371
373
  self._credentials_block_name = (
@@ -948,7 +950,7 @@ class ContainerRepositoryResource:
948
950
  dedent(
949
951
  f"""\
950
952
  from prefect import flow
951
- from prefect.deployments import DeploymentImage
953
+ from prefect.docker import DockerImage
952
954
 
953
955
 
954
956
  @flow(log_prints=True)
@@ -960,7 +962,7 @@ class ContainerRepositoryResource:
960
962
  my_flow.deploy(
961
963
  name="my-deployment",
962
964
  work_pool_name="{self._work_pool_name}",
963
- image=DeploymentImage(
965
+ image=DockerImage(
964
966
  name="{self._repository_name}:latest",
965
967
  platform="linux/amd64",
966
968
  )
@@ -1128,7 +1130,7 @@ class ElasticContainerServicePushProvisioner:
1128
1130
  work_pool_name: str,
1129
1131
  user_name: str = "prefect-ecs-user",
1130
1132
  policy_name: str = "prefect-ecs-policy",
1131
- credentials_block_name: str = None,
1133
+ credentials_block_name: Optional[str] = None,
1132
1134
  cluster_name: str = "prefect-ecs-cluster",
1133
1135
  vpc_name: str = "prefect-ecs-vpc",
1134
1136
  ecs_security_group_name: str = "prefect-ecs-security-group",
@@ -2,20 +2,23 @@ import importlib
2
2
  import shlex
3
3
  import sys
4
4
  from copy import deepcopy
5
- from typing import Any, Dict, Optional, Tuple
5
+ from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple
6
6
 
7
7
  from anyio import run_process
8
8
  from rich.console import Console
9
9
  from rich.progress import Progress, SpinnerColumn, TextColumn
10
10
  from rich.prompt import Confirm
11
11
 
12
- from prefect.client.orchestration import PrefectClient
13
12
  from prefect.client.schemas.actions import BlockDocumentCreate
14
13
  from prefect.client.schemas.objects import BlockDocument
15
14
  from prefect.client.utilities import inject_client
16
15
  from prefect.exceptions import ObjectNotFound
17
16
  from prefect.utilities.importtools import lazy_import
18
17
 
18
+ if TYPE_CHECKING:
19
+ from prefect.client.orchestration import PrefectClient
20
+
21
+
19
22
  modal = lazy_import("modal")
20
23
 
21
24
 
@@ -24,7 +27,7 @@ class ModalPushProvisioner:
24
27
  A infrastructure provisioner for Modal push work pools.
25
28
  """
26
29
 
27
- def __init__(self, client: Optional[PrefectClient] = None):
30
+ def __init__(self, client: Optional["PrefectClient"] = None):
28
31
  self._console = Console()
29
32
 
30
33
  @property
@@ -91,7 +94,7 @@ class ModalPushProvisioner:
91
94
  block_document_name: str,
92
95
  modal_token_id: str,
93
96
  modal_token_secret: str,
94
- client: PrefectClient,
97
+ client: "PrefectClient",
95
98
  ) -> BlockDocument:
96
99
  """
97
100
  Creates a ModalCredentials block containing the provided token ID and secret.
@@ -142,7 +145,7 @@ class ModalPushProvisioner:
142
145
  self,
143
146
  work_pool_name: str,
144
147
  base_job_template: Dict[str, Any],
145
- client: Optional[PrefectClient] = None,
148
+ client: Optional["PrefectClient"] = None,
146
149
  ) -> Dict[str, Any]:
147
150
  """
148
151
  Provisions resources necessary for a Modal push work pool.