prefect-client 2.20.2__py3-none-any.whl → 2.20.4__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.
prefect/blocks/core.py CHANGED
@@ -18,9 +18,7 @@ from typing import (
18
18
  )
19
19
  from uuid import UUID, uuid4
20
20
 
21
- from griffe.dataclasses import Docstring
22
- from griffe.docstrings.dataclasses import DocstringSection, DocstringSectionKind
23
- from griffe.docstrings.parsers import Parser, parse
21
+ from griffe import Docstring, DocstringSection, DocstringSectionKind, Parser, parse
24
22
  from packaging.version import InvalidVersion, Version
25
23
 
26
24
  from prefect._internal.pydantic import HAS_PYDANTIC_V2
@@ -120,18 +118,20 @@ def _is_subclass(cls, parent_cls) -> bool:
120
118
  Checks if a given class is a subclass of another class. Unlike issubclass,
121
119
  this will not throw an exception if cls is an instance instead of a type.
122
120
  """
123
- return inspect.isclass(cls) and issubclass(cls, parent_cls)
121
+ # For python<=3.11 inspect.isclass() will return True for parametrized types (e.g. list[str])
122
+ # so we need to check for get_origin() to avoid TypeError for issubclass.
123
+ return inspect.isclass(cls) and not get_origin(cls) and issubclass(cls, parent_cls)
124
124
 
125
125
 
126
126
  def _collect_secret_fields(name: str, type_: Type, secrets: List[str]) -> None:
127
127
  """
128
128
  Recursively collects all secret fields from a given type and adds them to the
129
- secrets list, supporting nested Union / BaseModel fields. Also, note, this function
130
- mutates the input secrets list, thus does not return anything.
129
+ secrets list, supporting nested Union / Dict / Tuple / List / BaseModel fields.
130
+ Also, note, this function mutates the input secrets list, thus does not return anything.
131
131
  """
132
- if get_origin(type_) is Union:
133
- for union_type in get_args(type_):
134
- _collect_secret_fields(name, union_type, secrets)
132
+ if get_origin(type_) in (Union, dict, list, tuple):
133
+ for nested_type in get_args(type_):
134
+ _collect_secret_fields(name, nested_type, secrets)
135
135
  return
136
136
  elif _is_subclass(type_, BaseModel):
137
137
  for field in type_.__fields__.values():
@@ -241,25 +241,29 @@ class Block(BaseModel, ABC):
241
241
 
242
242
  # create block schema references
243
243
  refs = schema["block_schema_references"] = {}
244
+
245
+ def collect_block_schema_references(
246
+ field_name: str, annotation: type
247
+ ) -> None:
248
+ """Walk through the annotation and collect block schemas for any nested blocks."""
249
+ if Block.is_block_class(annotation):
250
+ if isinstance(refs.get(field_name), list):
251
+ refs[field_name].append(
252
+ annotation._to_block_schema_reference_dict()
253
+ )
254
+ elif isinstance(refs.get(field_name), dict):
255
+ refs[field_name] = [
256
+ refs[field_name],
257
+ annotation._to_block_schema_reference_dict(),
258
+ ]
259
+ else:
260
+ refs[field_name] = annotation._to_block_schema_reference_dict()
261
+ if get_origin(annotation) in (Union, list, tuple, dict):
262
+ for type_ in get_args(annotation):
263
+ collect_block_schema_references(field_name, type_)
264
+
244
265
  for field in model.__fields__.values():
245
- if Block.is_block_class(field.type_):
246
- refs[field.name] = field.type_._to_block_schema_reference_dict()
247
- if get_origin(field.type_) is Union:
248
- for type_ in get_args(field.type_):
249
- if Block.is_block_class(type_):
250
- if isinstance(refs.get(field.name), list):
251
- refs[field.name].append(
252
- type_._to_block_schema_reference_dict()
253
- )
254
- elif isinstance(refs.get(field.name), dict):
255
- refs[field.name] = [
256
- refs[field.name],
257
- type_._to_block_schema_reference_dict(),
258
- ]
259
- else:
260
- refs[
261
- field.name
262
- ] = type_._to_block_schema_reference_dict()
266
+ collect_block_schema_references(field.name, field.type_)
263
267
 
264
268
  def __init__(self, *args, **kwargs):
265
269
  super().__init__(*args, **kwargs)
@@ -888,13 +892,16 @@ class Block(BaseModel, ABC):
888
892
  "subclass and not on a Block interface class directly."
889
893
  )
890
894
 
895
+ async def register_blocks_in_annotation(annotation: type) -> None:
896
+ """Walk through the annotation and register any nested blocks."""
897
+ if Block.is_block_class(annotation):
898
+ await annotation.register_type_and_schema(client=client)
899
+ elif get_origin(annotation) in (Union, tuple, list, dict):
900
+ for inner_annotation in get_args(annotation):
901
+ await register_blocks_in_annotation(inner_annotation)
902
+
891
903
  for field in cls.__fields__.values():
892
- if Block.is_block_class(field.type_):
893
- await field.type_.register_type_and_schema(client=client)
894
- if get_origin(field.type_) is Union:
895
- for type_ in get_args(field.type_):
896
- if Block.is_block_class(type_):
897
- await type_.register_type_and_schema(client=client)
904
+ await register_blocks_in_annotation(field.annotation)
898
905
 
899
906
  try:
900
907
  block_type = await client.read_block_type_by_slug(
@@ -2665,12 +2665,14 @@ class PrefectClient:
2665
2665
  async def create_work_pool(
2666
2666
  self,
2667
2667
  work_pool: WorkPoolCreate,
2668
+ overwrite: bool = False,
2668
2669
  ) -> WorkPool:
2669
2670
  """
2670
2671
  Creates a work pool with the provided configuration.
2671
2672
 
2672
2673
  Args:
2673
2674
  work_pool: Desired configuration for the new work pool.
2675
+ overwrite: Whether to overwrite an existing work pool with the same name.
2674
2676
 
2675
2677
  Returns:
2676
2678
  Information about the newly created work pool.
@@ -2682,7 +2684,24 @@ class PrefectClient:
2682
2684
  )
2683
2685
  except httpx.HTTPStatusError as e:
2684
2686
  if e.response.status_code == status.HTTP_409_CONFLICT:
2685
- raise prefect.exceptions.ObjectAlreadyExists(http_exc=e) from e
2687
+ if overwrite:
2688
+ existing_work_pool = await self.read_work_pool(
2689
+ work_pool_name=work_pool.name
2690
+ )
2691
+ if existing_work_pool.type != work_pool.type:
2692
+ warnings.warn(
2693
+ "Overwriting work pool type is not supported. Ignoring provided type.",
2694
+ category=UserWarning,
2695
+ )
2696
+ await self.update_work_pool(
2697
+ work_pool_name=work_pool.name,
2698
+ work_pool=WorkPoolUpdate.parse_obj(
2699
+ work_pool.dict(exclude={"name", "type"})
2700
+ ),
2701
+ )
2702
+ response = await self._client.get(f"/work_pools/{work_pool.name}")
2703
+ else:
2704
+ raise prefect.exceptions.ObjectAlreadyExists(http_exc=e) from e
2686
2705
  else:
2687
2706
  raise
2688
2707
 
prefect/engine.py CHANGED
@@ -332,6 +332,18 @@ def enter_flow_run_engine_from_subprocess(flow_run_id: UUID) -> State:
332
332
  return state
333
333
 
334
334
 
335
+ async def _make_flow_run(
336
+ flow: Flow, parameters: Dict[str, Any], state: State, client: PrefectClient
337
+ ) -> FlowRun:
338
+ return await client.create_flow_run(
339
+ flow,
340
+ # Send serialized parameters to the backend
341
+ parameters=flow.serialize_parameters(parameters),
342
+ state=state,
343
+ tags=TagsContext.get().current_tags,
344
+ )
345
+
346
+
335
347
  @inject_client
336
348
  async def create_then_begin_flow_run(
337
349
  flow: Flow,
@@ -351,6 +363,7 @@ async def create_then_begin_flow_run(
351
363
 
352
364
  await check_api_reachable(client, "Cannot create flow run")
353
365
 
366
+ flow_run = None
354
367
  state = Pending()
355
368
  if flow.should_validate_parameters:
356
369
  try:
@@ -359,14 +372,10 @@ async def create_then_begin_flow_run(
359
372
  state = await exception_to_failed_state(
360
373
  message="Validation of flow parameters failed with error:"
361
374
  )
375
+ flow_run = await _make_flow_run(flow, parameters, state, client)
376
+ await _run_flow_hooks(flow, flow_run, state)
362
377
 
363
- flow_run = await client.create_flow_run(
364
- flow,
365
- # Send serialized parameters to the backend
366
- parameters=flow.serialize_parameters(parameters),
367
- state=state,
368
- tags=TagsContext.get().current_tags,
369
- )
378
+ flow_run = flow_run or await _make_flow_run(flow, parameters, state, client)
370
379
 
371
380
  engine_logger.info(f"Created flow run {flow_run.name!r} for flow {flow.name!r}")
372
381
 
prefect/runner/runner.py CHANGED
@@ -35,7 +35,6 @@ import datetime
35
35
  import inspect
36
36
  import logging
37
37
  import os
38
- import shlex
39
38
  import shutil
40
39
  import signal
41
40
  import subprocess
@@ -97,7 +96,11 @@ from prefect.utilities.asyncutils import (
97
96
  sync_compatible,
98
97
  )
99
98
  from prefect.utilities.engine import propose_state
100
- from prefect.utilities.processutils import _register_signal, run_process
99
+ from prefect.utilities.processutils import (
100
+ _register_signal,
101
+ get_sys_executable,
102
+ run_process,
103
+ )
101
104
  from prefect.utilities.services import critical_service_loop
102
105
 
103
106
  __all__ = ["Runner"]
@@ -533,7 +536,7 @@ class Runner:
533
536
  task_status: anyio task status used to send a message to the caller
534
537
  than the flow run process has started.
535
538
  """
536
- command = f"{shlex.quote(sys.executable)} -m prefect.engine"
539
+ command = [get_sys_executable(), "-m", "prefect.engine"]
537
540
 
538
541
  flow_run_logger = self._get_flow_run_logger(flow_run)
539
542
 
@@ -580,7 +583,7 @@ class Runner:
580
583
  setattr(storage, "last_adhoc_pull", datetime.datetime.now())
581
584
 
582
585
  process = await run_process(
583
- shlex.split(command),
586
+ command=command,
584
587
  stream_output=True,
585
588
  task_status=task_status,
586
589
  env=env,
@@ -24,9 +24,7 @@ if HAS_PYDANTIC_V2:
24
24
  else:
25
25
  import pydantic
26
26
 
27
- from griffe.dataclasses import Docstring
28
- from griffe.docstrings.dataclasses import DocstringSectionKind
29
- from griffe.docstrings.parsers import Parser, parse
27
+ from griffe import Docstring, DocstringSectionKind, Parser, parse
30
28
  from typing_extensions import Literal
31
29
 
32
30
  from prefect.exceptions import (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prefect-client
3
- Version: 2.20.2
3
+ Version: 2.20.4
4
4
  Summary: Workflow orchestration and management.
5
5
  Home-page: https://www.prefect.io
6
6
  Author: Prefect Technologies, Inc.
@@ -31,10 +31,10 @@ Requires-Dist: croniter<3.0.0,>=1.0.12
31
31
  Requires-Dist: fsspec>=2022.5.0
32
32
  Requires-Dist: exceptiongroup>=1.2.1
33
33
  Requires-Dist: graphviz>=0.20.1
34
- Requires-Dist: griffe<0.48.0,>=0.20.0
34
+ Requires-Dist: griffe<2.0.0,>=0.49.0
35
35
  Requires-Dist: httpcore<2.0.0,>=1.0.5
36
36
  Requires-Dist: httpx[http2]!=0.23.2,>=0.23
37
- Requires-Dist: importlib-resources<6.2.0,>=6.1.3
37
+ Requires-Dist: importlib-resources<6.5.0,>=6.1.3
38
38
  Requires-Dist: jsonpatch<2.0,>=1.32
39
39
  Requires-Dist: jsonschema<5.0.0,>=4.0.0
40
40
  Requires-Dist: orjson<4.0,>=3.7
@@ -53,7 +53,7 @@ Requires-Dist: toml>=0.10.0
53
53
  Requires-Dist: typing-extensions<5.0.0,>=4.5.0
54
54
  Requires-Dist: ujson<6.0.0,>=5.8.0
55
55
  Requires-Dist: uvicorn!=0.29.0,>=0.14.0
56
- Requires-Dist: websockets<13.0,>=10.4
56
+ Requires-Dist: websockets<14.0,>=10.4
57
57
  Requires-Dist: itsdangerous
58
58
  Requires-Dist: python-multipart>=0.0.7
59
59
  Requires-Dist: importlib-metadata>=4.4; python_version < "3.10"
@@ -5,7 +5,7 @@ prefect/agent.py,sha256=HaGT0yh3fciluYpO99dVHo_LHq7N2cYLuWNrEV_kPV8,27789
5
5
  prefect/artifacts.py,sha256=mreaBE4qMoXkjc9YI-5cAxoye7ixraHB_zr8GTK9xPU,8694
6
6
  prefect/automations.py,sha256=rjVtQblBlKhD_q24bG6zbxJeb_XQJnodMlhr565aZJY,4853
7
7
  prefect/context.py,sha256=Hgn3rIjCbqfCmGnZzV_eZ2FwxGjEhaZjUw_nppqNQSA,18189
8
- prefect/engine.py,sha256=czyTcLPIaj_LOpPuWNheK0FfdOwX42VKLtonm7vZqH0,91938
8
+ prefect/engine.py,sha256=yw6LVoaEUCTR-NkSJXRau2gB9jNCspMw83ELaxmwpnE,92291
9
9
  prefect/exceptions.py,sha256=ElqC81_w6XbTaxLYANLMIPK8Fz46NmJZCRKL4NZ-JIg,10907
10
10
  prefect/filesystems.py,sha256=XniPSdBAqywj43X7GyfuWJQIbz07QJ5Y3cVNLhIF3lQ,35260
11
11
  prefect/flow_runs.py,sha256=mFHLavZk1yZ62H3UazuNDBZWAF7AqKttA4rMcHgsVSw,3119
@@ -155,7 +155,7 @@ prefect/_vendor/starlette/middleware/trustedhost.py,sha256=fDi67anj2a7MGviC0RAWh
155
155
  prefect/_vendor/starlette/middleware/wsgi.py,sha256=Ewk1cVDkcoXLVI2ZF0FEZLZCwCDjc0H7PnvWLlxurVY,5266
156
156
  prefect/blocks/__init__.py,sha256=BUfh6gIwA6HEjRyVCAiv0he3M1zfM-oY-JrlBfeWeY8,182
157
157
  prefect/blocks/abstract.py,sha256=AiAs0MC5JKCf0Xg0yofC5Qu2TZ52AjDMP1ntMGuP2dY,16311
158
- prefect/blocks/core.py,sha256=66pGFVPxtCCGWELqPXYqN8L0GoUXuUqv6jWw3Kk-tyY,43496
158
+ prefect/blocks/core.py,sha256=PWStXo61GsTmdVgyh1ubEkVatNzCacRyNXyG9caFMM4,43952
159
159
  prefect/blocks/fields.py,sha256=ANOzbNyDCBIvm6ktgbLTMs7JW2Sf6CruyATjAW61ks0,1607
160
160
  prefect/blocks/kubernetes.py,sha256=IN-hZkzIRvqjd_dzPZby3q8p7m2oUWqArBq24BU9cDg,4071
161
161
  prefect/blocks/notifications.py,sha256=LJd2mgV29URqItJyxtWUpdo4wswtm7KyIseuAjV3joI,28132
@@ -166,7 +166,7 @@ prefect/client/base.py,sha256=YSPeE7hV0NCuD6WzoAACDYGFK4Yq35d26pITZ3elNyY,24669
166
166
  prefect/client/cloud.py,sha256=E54OAFr7bY5IXhhMBdjGwLQiR0eU-WWFoEEiOq2l53I,4104
167
167
  prefect/client/collections.py,sha256=I9EgbTg4Fn57gn8vwP_WdDmgnATbx9gfkm2jjhCORjw,1037
168
168
  prefect/client/constants.py,sha256=Z_GG8KF70vbbXxpJuqW5pLnwzujTVeHbcYYRikNmGH0,29
169
- prefect/client/orchestration.py,sha256=O8DEbL7CP271MTVNlID8aRAl1xybfb6MwCUbYyjZejU,139211
169
+ prefect/client/orchestration.py,sha256=k_0W9QP0uCamt2FXW3JwZcAEDGS_ArwZx69lKsb02Gg,140180
170
170
  prefect/client/subscriptions.py,sha256=3kqPH3F-CwyrR5wygCpJMjRjM_gcQjd54Qjih6FcLlA,3372
171
171
  prefect/client/utilities.py,sha256=7V4IkfC8x_OZuPXGvtIMmwZCOW63hSY8iVQkuRYTR6g,3079
172
172
  prefect/client/schemas/__init__.py,sha256=KlyqFV-hMulMkNstBn_0ijoHoIwJZaBj6B1r07UmgvE,607
@@ -237,7 +237,7 @@ prefect/logging/logging.yml,sha256=UkEewf0c3_dURI2uCU4RrxkhI5Devoa1s93fl7hilcg,3
237
237
  prefect/pydantic/__init__.py,sha256=BsW32X7fvl44J1JQer1tkEpfleMtL2kL5Uy1KmwWvso,2714
238
238
  prefect/pydantic/main.py,sha256=ups_UULBhCPhB-E7X7-Qgbpor1oJdqChRzpD0ZYQH8A,839
239
239
  prefect/runner/__init__.py,sha256=7U-vAOXFkzMfRz1q8Uv6Otsvc0OrPYLLP44srwkJ_8s,89
240
- prefect/runner/runner.py,sha256=45sZR2kDvhTODyGmeiRe-bgVWq5JHsmZvFPBsiiyKxA,45147
240
+ prefect/runner/runner.py,sha256=OUbLIFHtDYKso5sp6m799qAnu5dpkIQbA3rGutwoCAg,45162
241
241
  prefect/runner/server.py,sha256=kXbKSRG21f44BGqOlWR3dcfKs92begC74aM6GdZ_z4E,10674
242
242
  prefect/runner/storage.py,sha256=QkIDKB5NQzy_hoNgl74JKuo_BtiOR74r_-lhccdJEvI,24850
243
243
  prefect/runner/submit.py,sha256=w53VdsqfwjW-M3e8hUAAoVlNrXsvGuuyGpEN0wi3vX0,8537
@@ -257,7 +257,7 @@ prefect/types/__init__.py,sha256=aZvlQ2uXl949sJ_khmxSVkRH3o6edo-eJ_GBGMBN5Yg,313
257
257
  prefect/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
258
258
  prefect/utilities/annotations.py,sha256=bXB43j5Zsq5gaBcJe9qnszBlnNwCTwqSTgcu2OkkRLo,2776
259
259
  prefect/utilities/asyncutils.py,sha256=ftu6MaV9qOZ3oCIErrneW07km2BydCezOMzvPUuCMUo,17246
260
- prefect/utilities/callables.py,sha256=YWilWp6oyL3D-hsyUuSE-h2KZ0aO_nbjhW75KsrLVmQ,21224
260
+ prefect/utilities/callables.py,sha256=0hzn4-51a2q1_aQ_QCymnl5NV-P9Zx5Nt0GUJahSAVg,21134
261
261
  prefect/utilities/collections.py,sha256=0v-NNXxYYzkUTCCNDMNB44AnDv9yj35UYouNraCqlo8,15449
262
262
  prefect/utilities/compat.py,sha256=mNQZDnzyKaOqy-OV-DnmH_dc7CNF5nQgW_EsA4xMr7g,906
263
263
  prefect/utilities/context.py,sha256=BThuUW94-IYgFYTeMIM9KMo8ShT3oiI7w5ajZHzU1j0,1377
@@ -287,8 +287,8 @@ prefect/workers/block.py,sha256=aYY__uq3v1eq1kkbVukxyhQNbkknaKYo6-_3tcrfKKA,8067
287
287
  prefect/workers/process.py,sha256=pPtCdA7fKQ4OsvoitT-cayZeh5HgLX4xBUYlb2Zad-Q,9475
288
288
  prefect/workers/server.py,sha256=WVZJxR8nTMzK0ov0BD0xw5OyQpT26AxlXbsGQ1OrxeQ,1551
289
289
  prefect/workers/utilities.py,sha256=VfPfAlGtTuDj0-Kb8WlMgAuOfgXCdrGAnKMapPSBrwc,2483
290
- prefect_client-2.20.2.dist-info/LICENSE,sha256=MCxsn8osAkzfxKC4CC_dLcUkU8DZLkyihZ8mGs3Ah3Q,11357
291
- prefect_client-2.20.2.dist-info/METADATA,sha256=A2xzGpbdwZqxOsA5PS1ehunrwe547RvIBtCqrU3yO-U,7392
292
- prefect_client-2.20.2.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
293
- prefect_client-2.20.2.dist-info/top_level.txt,sha256=MJZYJgFdbRc2woQCeB4vM6T33tr01TmkEhRcns6H_H4,8
294
- prefect_client-2.20.2.dist-info/RECORD,,
290
+ prefect_client-2.20.4.dist-info/LICENSE,sha256=MCxsn8osAkzfxKC4CC_dLcUkU8DZLkyihZ8mGs3Ah3Q,11357
291
+ prefect_client-2.20.4.dist-info/METADATA,sha256=Xv8N3s6Crb2OcuHHdOlG87aBeW9LQ-CEyOBgiA9Q4O4,7391
292
+ prefect_client-2.20.4.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
293
+ prefect_client-2.20.4.dist-info/top_level.txt,sha256=MJZYJgFdbRc2woQCeB4vM6T33tr01TmkEhRcns6H_H4,8
294
+ prefect_client-2.20.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.2.0)
2
+ Generator: setuptools (74.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5