prefect-client 3.2.12__py3-none-any.whl → 3.2.14__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/_build_info.py +3 -3
- prefect/client/orchestration/_flow_runs/client.py +34 -4
- prefect/client/schemas/actions.py +12 -0
- prefect/client/schemas/objects.py +18 -0
- prefect/deployments/runner.py +1 -9
- prefect/docker/docker_image.py +2 -1
- prefect/flow_engine.py +11 -5
- prefect/flow_runs.py +1 -1
- prefect/flows.py +3 -4
- prefect/logging/loggers.py +5 -4
- prefect/results.py +9 -3
- prefect/runner/__init__.py +2 -0
- prefect/runner/runner.py +1 -1
- prefect/runner/server.py +12 -7
- prefect/runner/storage.py +37 -37
- prefect/runner/submit.py +36 -25
- prefect/runner/utils.py +9 -5
- prefect/server/api/collections_data/views/aggregate-worker-metadata.json +4 -4
- prefect/server/api/flow_runs.py +21 -0
- prefect/server/api/server.py +17 -0
- prefect/server/api/task_runs.py +52 -1
- prefect/settings/models/tasks.py +5 -0
- prefect/task_engine.py +27 -0
- prefect/tasks.py +8 -2
- prefect/telemetry/run_telemetry.py +11 -3
- prefect/transactions.py +5 -0
- prefect/utilities/engine.py +2 -2
- prefect/utilities/importtools.py +6 -9
- prefect/workers/base.py +189 -104
- prefect/workers/process.py +7 -6
- {prefect_client-3.2.12.dist-info → prefect_client-3.2.14.dist-info}/METADATA +1 -1
- {prefect_client-3.2.12.dist-info → prefect_client-3.2.14.dist-info}/RECORD +34 -34
- {prefect_client-3.2.12.dist-info → prefect_client-3.2.14.dist-info}/WHEEL +0 -0
- {prefect_client-3.2.12.dist-info → prefect_client-3.2.14.dist-info}/licenses/LICENSE +0 -0
prefect/_build_info.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generated by versioningit
|
2
|
-
__version__ = "3.2.
|
3
|
-
__build_date__ = "2025-03-
|
4
|
-
__git_commit__ = "
|
2
|
+
__version__ = "3.2.14"
|
3
|
+
__build_date__ = "2025-03-21 15:55:26.682402+00:00"
|
4
|
+
__git_commit__ = "775b957d124ecd8cc3f0005e45019f1f9e855973"
|
5
5
|
__dirty__ = False
|
@@ -46,6 +46,9 @@ class FlowRunClient(BaseClient):
|
|
46
46
|
tags: "Iterable[str] | None" = None,
|
47
47
|
parent_task_run_id: "UUID | None" = None,
|
48
48
|
state: "State[R] | None" = None,
|
49
|
+
work_pool_name: str | None = None,
|
50
|
+
work_queue_name: str | None = None,
|
51
|
+
job_variables: dict[str, Any] | None = None,
|
49
52
|
) -> "FlowRun":
|
50
53
|
"""
|
51
54
|
Create a flow run for a flow.
|
@@ -59,7 +62,10 @@ class FlowRunClient(BaseClient):
|
|
59
62
|
parent_task_run_id: if a subflow run is being created, the placeholder task
|
60
63
|
run identifier in the parent flow
|
61
64
|
state: The initial state for the run. If not provided, defaults to
|
62
|
-
`
|
65
|
+
`Pending`.
|
66
|
+
work_pool_name: The name of the work pool to run the flow run in.
|
67
|
+
work_queue_name: The name of the work queue to place the flow run in.
|
68
|
+
job_variables: The job variables to use when setting up flow run infrastructure.
|
63
69
|
|
64
70
|
Raises:
|
65
71
|
httpx.RequestError: if the Prefect API does not successfully create a run for any reason
|
@@ -100,7 +106,16 @@ class FlowRunClient(BaseClient):
|
|
100
106
|
),
|
101
107
|
)
|
102
108
|
|
103
|
-
|
109
|
+
if work_pool_name is not None:
|
110
|
+
flow_run_create.work_pool_name = work_pool_name
|
111
|
+
if work_queue_name is not None:
|
112
|
+
flow_run_create.work_queue_name = work_queue_name
|
113
|
+
if job_variables is not None:
|
114
|
+
flow_run_create.job_variables = job_variables
|
115
|
+
|
116
|
+
flow_run_create_json = flow_run_create.model_dump(
|
117
|
+
mode="json", exclude_unset=True
|
118
|
+
)
|
104
119
|
response = self.request("POST", "/flow_runs/", json=flow_run_create_json)
|
105
120
|
|
106
121
|
flow_run = FlowRun.model_validate(response.json())
|
@@ -480,6 +495,9 @@ class FlowRunAsyncClient(BaseAsyncClient):
|
|
480
495
|
tags: "Iterable[str] | None" = None,
|
481
496
|
parent_task_run_id: "UUID | None" = None,
|
482
497
|
state: "State[R] | None" = None,
|
498
|
+
work_pool_name: str | None = None,
|
499
|
+
work_queue_name: str | None = None,
|
500
|
+
job_variables: dict[str, Any] | None = None,
|
483
501
|
) -> "FlowRun":
|
484
502
|
"""
|
485
503
|
Create a flow run for a flow.
|
@@ -493,7 +511,10 @@ class FlowRunAsyncClient(BaseAsyncClient):
|
|
493
511
|
parent_task_run_id: if a subflow run is being created, the placeholder task
|
494
512
|
run identifier in the parent flow
|
495
513
|
state: The initial state for the run. If not provided, defaults to
|
496
|
-
`
|
514
|
+
`Pending`.
|
515
|
+
work_pool_name: The name of the work pool to run the flow run in.
|
516
|
+
work_queue_name: The name of the work queue to place the flow run in.
|
517
|
+
job_variables: The job variables to use when setting up flow run infrastructure.
|
497
518
|
|
498
519
|
Raises:
|
499
520
|
httpx.RequestError: if the Prefect API does not successfully create a run for any reason
|
@@ -534,7 +555,16 @@ class FlowRunAsyncClient(BaseAsyncClient):
|
|
534
555
|
),
|
535
556
|
)
|
536
557
|
|
537
|
-
|
558
|
+
if work_pool_name is not None:
|
559
|
+
flow_run_create.work_pool_name = work_pool_name
|
560
|
+
if work_queue_name is not None:
|
561
|
+
flow_run_create.work_queue_name = work_queue_name
|
562
|
+
if job_variables is not None:
|
563
|
+
flow_run_create.job_variables = job_variables
|
564
|
+
|
565
|
+
flow_run_create_json = flow_run_create.model_dump(
|
566
|
+
mode="json", exclude_unset=True
|
567
|
+
)
|
538
568
|
response = await self.request("POST", "/flow_runs/", json=flow_run_create_json)
|
539
569
|
|
540
570
|
flow_run = FlowRun.model_validate(response.json())
|
@@ -23,6 +23,7 @@ from prefect._internal.schemas.validators import (
|
|
23
23
|
from prefect.client.schemas.objects import (
|
24
24
|
StateDetails,
|
25
25
|
StateType,
|
26
|
+
WorkPoolStorageConfiguration,
|
26
27
|
)
|
27
28
|
from prefect.client.schemas.schedules import (
|
28
29
|
SCHEDULE_TYPES,
|
@@ -443,6 +444,9 @@ class FlowRunCreate(ActionBaseModel):
|
|
443
444
|
idempotency_key: Optional[str] = Field(default=None)
|
444
445
|
|
445
446
|
labels: KeyValueLabelsField = Field(default_factory=dict)
|
447
|
+
work_pool_name: Optional[str] = Field(default=None)
|
448
|
+
work_queue_name: Optional[str] = Field(default=None)
|
449
|
+
job_variables: Optional[dict[str, Any]] = Field(default=None)
|
446
450
|
|
447
451
|
|
448
452
|
class DeploymentFlowRunCreate(ActionBaseModel):
|
@@ -684,6 +688,10 @@ class WorkPoolCreate(ActionBaseModel):
|
|
684
688
|
concurrency_limit: Optional[NonNegativeInteger] = Field(
|
685
689
|
default=None, description="A concurrency limit for the work pool."
|
686
690
|
)
|
691
|
+
storage_configuration: WorkPoolStorageConfiguration = Field(
|
692
|
+
default_factory=WorkPoolStorageConfiguration,
|
693
|
+
description="A storage configuration for the work pool.",
|
694
|
+
)
|
687
695
|
|
688
696
|
|
689
697
|
class WorkPoolUpdate(ActionBaseModel):
|
@@ -693,6 +701,10 @@ class WorkPoolUpdate(ActionBaseModel):
|
|
693
701
|
is_paused: Optional[bool] = Field(default=None)
|
694
702
|
base_job_template: Optional[dict[str, Any]] = Field(default=None)
|
695
703
|
concurrency_limit: Optional[int] = Field(default=None)
|
704
|
+
storage_configuration: Optional[WorkPoolStorageConfiguration] = Field(
|
705
|
+
default=None,
|
706
|
+
description="A storage configuration for the work pool.",
|
707
|
+
)
|
696
708
|
|
697
709
|
|
698
710
|
class WorkQueueCreate(ActionBaseModel):
|
@@ -1445,6 +1445,19 @@ class Agent(ObjectBaseModel):
|
|
1445
1445
|
)
|
1446
1446
|
|
1447
1447
|
|
1448
|
+
class WorkPoolStorageConfiguration(PrefectBaseModel):
|
1449
|
+
"""A work pool storage configuration"""
|
1450
|
+
|
1451
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(extra="forbid")
|
1452
|
+
|
1453
|
+
bundle_upload_step: Optional[dict[str, Any]] = Field(
|
1454
|
+
default=None, description="The bundle upload step for the work pool."
|
1455
|
+
)
|
1456
|
+
bundle_execution_step: Optional[dict[str, Any]] = Field(
|
1457
|
+
default=None, description="The bundle execution step for the work pool."
|
1458
|
+
)
|
1459
|
+
|
1460
|
+
|
1448
1461
|
class WorkPool(ObjectBaseModel):
|
1449
1462
|
"""An ORM representation of a work pool"""
|
1450
1463
|
|
@@ -1469,6 +1482,11 @@ class WorkPool(ObjectBaseModel):
|
|
1469
1482
|
default=None, description="The current status of the work pool."
|
1470
1483
|
)
|
1471
1484
|
|
1485
|
+
storage_configuration: WorkPoolStorageConfiguration = Field(
|
1486
|
+
default_factory=WorkPoolStorageConfiguration,
|
1487
|
+
description="The storage configuration for the work pool.",
|
1488
|
+
)
|
1489
|
+
|
1472
1490
|
# this required field has a default of None so that the custom validator
|
1473
1491
|
# below will be called and produce a more helpful error message. Because
|
1474
1492
|
# the field metadata is attached via an annotation, the default is hidden
|
prefect/deployments/runner.py
CHANGED
@@ -676,15 +676,7 @@ class RunnerDeployment(BaseModel):
|
|
676
676
|
try:
|
677
677
|
module = importlib.import_module(mod_name)
|
678
678
|
flow_file = getattr(module, "__file__", None)
|
679
|
-
except ModuleNotFoundError
|
680
|
-
# 16458 adds an identifier to the module name, so checking
|
681
|
-
# for "__prefect_loader__" (2 underscores) will not match
|
682
|
-
if "__prefect_loader_" in str(exc):
|
683
|
-
raise ValueError(
|
684
|
-
"Cannot create a RunnerDeployment from a flow that has been"
|
685
|
-
" loaded from an entrypoint. To deploy a flow via"
|
686
|
-
" entrypoint, use RunnerDeployment.from_entrypoint instead."
|
687
|
-
)
|
679
|
+
except ModuleNotFoundError:
|
688
680
|
raise ValueError(no_file_location_error)
|
689
681
|
if not flow_file:
|
690
682
|
raise ValueError(no_file_location_error)
|
prefect/docker/docker_image.py
CHANGED
@@ -64,7 +64,8 @@ class DockerImage:
|
|
64
64
|
def build(self) -> None:
|
65
65
|
full_image_name = self.reference
|
66
66
|
build_kwargs = self.build_kwargs.copy()
|
67
|
-
|
67
|
+
if "context" not in build_kwargs:
|
68
|
+
build_kwargs["context"] = Path.cwd()
|
68
69
|
build_kwargs["tag"] = full_image_name
|
69
70
|
build_kwargs["pull"] = build_kwargs.get("pull", True)
|
70
71
|
|
prefect/flow_engine.py
CHANGED
@@ -707,7 +707,11 @@ class FlowRunEngine(BaseFlowRunEngine[P, R]):
|
|
707
707
|
except Exception:
|
708
708
|
# regular exceptions are caught and re-raised to the user
|
709
709
|
raise
|
710
|
-
except (Abort, Pause):
|
710
|
+
except (Abort, Pause) as exc:
|
711
|
+
if getattr(exc, "state", None):
|
712
|
+
# we set attribute explicitly because
|
713
|
+
# internals will have already called the state change API
|
714
|
+
self.flow_run.state = exc.state
|
711
715
|
raise
|
712
716
|
except GeneratorExit:
|
713
717
|
# Do not capture generator exits as crashes
|
@@ -722,9 +726,7 @@ class FlowRunEngine(BaseFlowRunEngine[P, R]):
|
|
722
726
|
repr(self.state) if PREFECT_DEBUG_MODE else str(self.state)
|
723
727
|
)
|
724
728
|
self.logger.log(
|
725
|
-
level=logging.INFO
|
726
|
-
if self.state.is_completed()
|
727
|
-
else logging.ERROR,
|
729
|
+
level=logging.INFO,
|
728
730
|
msg=f"Finished in state {display_state}",
|
729
731
|
)
|
730
732
|
|
@@ -1277,7 +1279,11 @@ class AsyncFlowRunEngine(BaseFlowRunEngine[P, R]):
|
|
1277
1279
|
except Exception:
|
1278
1280
|
# regular exceptions are caught and re-raised to the user
|
1279
1281
|
raise
|
1280
|
-
except (Abort, Pause):
|
1282
|
+
except (Abort, Pause) as exc:
|
1283
|
+
if getattr(exc, "state", None):
|
1284
|
+
# we set attribute explicitly because
|
1285
|
+
# internals will have already called the state change API
|
1286
|
+
self.flow_run.state = exc.state
|
1281
1287
|
raise
|
1282
1288
|
except GeneratorExit:
|
1283
1289
|
# Do not capture generator exits as crashes
|
prefect/flow_runs.py
CHANGED
prefect/flows.py
CHANGED
@@ -1046,10 +1046,9 @@ class Flow(Generic[P, R]):
|
|
1046
1046
|
if not name:
|
1047
1047
|
name = self.name
|
1048
1048
|
else:
|
1049
|
-
#
|
1050
|
-
|
1051
|
-
|
1052
|
-
name = Path(name).stem
|
1049
|
+
# Only strip extension if it is a file path
|
1050
|
+
if (p := Path(name)).is_file():
|
1051
|
+
name = p.stem
|
1053
1052
|
|
1054
1053
|
runner = Runner(name=name, pause_on_shutdown=pause_on_shutdown, limit=limit)
|
1055
1054
|
deployment_id = runner.add_flow(
|
prefect/logging/loggers.py
CHANGED
@@ -146,10 +146,11 @@ def get_run_logger(
|
|
146
146
|
**kwargs,
|
147
147
|
)
|
148
148
|
elif (
|
149
|
-
get_logger("prefect.
|
150
|
-
and get_logger("prefect.
|
149
|
+
get_logger("prefect.flow_runs").disabled
|
150
|
+
and get_logger("prefect.task_runs").disabled
|
151
151
|
):
|
152
152
|
logger = logging.getLogger("null")
|
153
|
+
logger.disabled = True
|
153
154
|
else:
|
154
155
|
raise MissingContextError("There is no active flow or task run context.")
|
155
156
|
|
@@ -280,9 +281,9 @@ def disable_run_logger():
|
|
280
281
|
"""
|
281
282
|
Gets both `prefect.flow_run` and `prefect.task_run` and disables them
|
282
283
|
within the context manager. Upon exiting the context manager, both loggers
|
283
|
-
are returned to
|
284
|
+
are returned to their original state.
|
284
285
|
"""
|
285
|
-
with disable_logger("prefect.
|
286
|
+
with disable_logger("prefect.flow_runs"), disable_logger("prefect.task_runs"):
|
286
287
|
yield
|
287
288
|
|
288
289
|
|
prefect/results.py
CHANGED
@@ -552,7 +552,11 @@ class ResultStore(BaseModel):
|
|
552
552
|
if self.result_storage_block_id is None and (
|
553
553
|
_resolve_path := getattr(self.result_storage, "_resolve_path", None)
|
554
554
|
):
|
555
|
-
|
555
|
+
path_key = _resolve_path(key)
|
556
|
+
if path_key is not None:
|
557
|
+
return str(_resolve_path(key))
|
558
|
+
else:
|
559
|
+
return key
|
556
560
|
return key
|
557
561
|
|
558
562
|
@sync_compatible
|
@@ -684,7 +688,9 @@ class ResultStore(BaseModel):
|
|
684
688
|
|
685
689
|
if self.result_storage_block_id is None:
|
686
690
|
if _resolve_path := getattr(self.result_storage, "_resolve_path", None):
|
687
|
-
|
691
|
+
path_key = _resolve_path(key)
|
692
|
+
if path_key is not None:
|
693
|
+
key = str(_resolve_path(key))
|
688
694
|
|
689
695
|
return ResultRecord(
|
690
696
|
result=obj,
|
@@ -773,7 +779,7 @@ class ResultStore(BaseModel):
|
|
773
779
|
)
|
774
780
|
else Path(".").resolve()
|
775
781
|
)
|
776
|
-
base_key = str(Path(key).relative_to(basepath))
|
782
|
+
base_key = key if basepath is None else str(Path(key).relative_to(basepath))
|
777
783
|
else:
|
778
784
|
base_key = key
|
779
785
|
if (
|
prefect/runner/__init__.py
CHANGED
prefect/runner/runner.py
CHANGED
@@ -1425,7 +1425,7 @@ class Runner:
|
|
1425
1425
|
)
|
1426
1426
|
status_code = process.returncode
|
1427
1427
|
except Exception as exc:
|
1428
|
-
if not task_status._future.done():
|
1428
|
+
if not task_status._future.done(): # type: ignore
|
1429
1429
|
# This flow run was being submitted and did not start successfully
|
1430
1430
|
run_logger.exception(
|
1431
1431
|
f"Failed to start process for flow run '{flow_run.id}'."
|
prefect/runner/server.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import uuid
|
2
|
-
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Hashable, Optional
|
4
|
+
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Hashable, Optional
|
3
5
|
|
4
6
|
import uvicorn
|
5
7
|
from fastapi import APIRouter, FastAPI, HTTPException, status
|
@@ -33,7 +35,7 @@ if TYPE_CHECKING:
|
|
33
35
|
|
34
36
|
from pydantic import BaseModel
|
35
37
|
|
36
|
-
logger: "logging.Logger" = get_logger("webserver")
|
38
|
+
logger: "logging.Logger" = get_logger("runner.webserver")
|
37
39
|
|
38
40
|
RunnableEndpoint = Literal["deployment", "flow", "task"]
|
39
41
|
|
@@ -45,7 +47,7 @@ class RunnerGenericFlowRunRequest(BaseModel):
|
|
45
47
|
|
46
48
|
|
47
49
|
def perform_health_check(
|
48
|
-
runner: "Runner", delay_threshold:
|
50
|
+
runner: "Runner", delay_threshold: int | None = None
|
49
51
|
) -> Callable[..., JSONResponse]:
|
50
52
|
if delay_threshold is None:
|
51
53
|
delay_threshold = (
|
@@ -57,6 +59,9 @@ def perform_health_check(
|
|
57
59
|
now = DateTime.now("utc")
|
58
60
|
poll_delay = (now - runner.last_polled).total_seconds()
|
59
61
|
|
62
|
+
if TYPE_CHECKING:
|
63
|
+
assert delay_threshold is not None
|
64
|
+
|
60
65
|
if poll_delay > delay_threshold:
|
61
66
|
return JSONResponse(
|
62
67
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
@@ -120,7 +125,7 @@ async def _build_endpoint_for_deployment(
|
|
120
125
|
|
121
126
|
async def get_deployment_router(
|
122
127
|
runner: "Runner",
|
123
|
-
) ->
|
128
|
+
) -> tuple[APIRouter, dict[Hashable, Any]]:
|
124
129
|
router = APIRouter()
|
125
130
|
schemas: dict[Hashable, Any] = {}
|
126
131
|
async with get_client() as client:
|
@@ -216,14 +221,14 @@ def _build_generic_endpoint_for_flows(
|
|
216
221
|
# Verify that the flow we're loading is a subflow this runner is
|
217
222
|
# managing
|
218
223
|
if not _flow_in_schemas(flow, schemas):
|
219
|
-
|
224
|
+
logger.warning(
|
220
225
|
f"Flow {flow.name} is not directly managed by the runner. Please "
|
221
226
|
"include it in the runner's served flows' import namespace."
|
222
227
|
)
|
223
228
|
# Verify that the flow we're loading hasn't changed since the webserver
|
224
229
|
# was started
|
225
230
|
if _flow_schema_changed(flow, schemas):
|
226
|
-
|
231
|
+
logger.warning(
|
227
232
|
"A change in flow parameters has been detected. Please "
|
228
233
|
"restart the runner."
|
229
234
|
)
|
@@ -291,7 +296,7 @@ async def build_server(runner: "Runner") -> FastAPI:
|
|
291
296
|
return webserver
|
292
297
|
|
293
298
|
|
294
|
-
def start_webserver(runner: "Runner", log_level:
|
299
|
+
def start_webserver(runner: "Runner", log_level: str | None = None) -> None:
|
295
300
|
"""
|
296
301
|
Run a FastAPI server for a runner.
|
297
302
|
|
prefect/runner/storage.py
CHANGED
@@ -6,7 +6,6 @@ from copy import deepcopy
|
|
6
6
|
from pathlib import Path
|
7
7
|
from typing import (
|
8
8
|
Any,
|
9
|
-
Dict,
|
10
9
|
Optional,
|
11
10
|
Protocol,
|
12
11
|
TypedDict,
|
@@ -16,7 +15,7 @@ from typing import (
|
|
16
15
|
from urllib.parse import urlparse, urlsplit, urlunparse
|
17
16
|
from uuid import uuid4
|
18
17
|
|
19
|
-
import fsspec
|
18
|
+
import fsspec # pyright: ignore[reportMissingTypeStubs]
|
20
19
|
from anyio import run_process
|
21
20
|
from pydantic import SecretStr
|
22
21
|
|
@@ -79,7 +78,7 @@ class RunnerStorage(Protocol):
|
|
79
78
|
|
80
79
|
class GitCredentials(TypedDict, total=False):
|
81
80
|
username: str
|
82
|
-
access_token:
|
81
|
+
access_token: str | Secret[str]
|
83
82
|
|
84
83
|
|
85
84
|
class GitRepository:
|
@@ -117,12 +116,12 @@ class GitRepository:
|
|
117
116
|
def __init__(
|
118
117
|
self,
|
119
118
|
url: str,
|
120
|
-
credentials: Union[GitCredentials, Block,
|
121
|
-
name:
|
122
|
-
branch:
|
119
|
+
credentials: Union[GitCredentials, Block, dict[str, Any], None] = None,
|
120
|
+
name: str | None = None,
|
121
|
+
branch: str | None = None,
|
123
122
|
include_submodules: bool = False,
|
124
|
-
pull_interval:
|
125
|
-
directories:
|
123
|
+
pull_interval: int | None = 60,
|
124
|
+
directories: list[str] | None = None,
|
126
125
|
):
|
127
126
|
if credentials is None:
|
128
127
|
credentials = {}
|
@@ -198,7 +197,7 @@ class GitRepository:
|
|
198
197
|
@property
|
199
198
|
def _git_config(self) -> list[str]:
|
200
199
|
"""Build a git configuration to use when running git commands."""
|
201
|
-
config = {}
|
200
|
+
config: dict[str, str] = {}
|
202
201
|
|
203
202
|
# Submodules can be private. The url in .gitmodules
|
204
203
|
# will not include the credentials, we need to
|
@@ -220,7 +219,7 @@ class GitRepository:
|
|
220
219
|
result = await run_process(
|
221
220
|
["git", "config", "--get", "core.sparseCheckout"], cwd=self.destination
|
222
221
|
)
|
223
|
-
return result.strip().lower() == "true"
|
222
|
+
return result.stdout.decode().strip().lower() == "true"
|
224
223
|
except Exception:
|
225
224
|
return False
|
226
225
|
|
@@ -243,8 +242,7 @@ class GitRepository:
|
|
243
242
|
cwd=str(self.destination),
|
244
243
|
)
|
245
244
|
existing_repo_url = None
|
246
|
-
|
247
|
-
existing_repo_url = _strip_auth_from_url(result.stdout.decode().strip())
|
245
|
+
existing_repo_url = _strip_auth_from_url(result.stdout.decode().strip())
|
248
246
|
|
249
247
|
if existing_repo_url != self._url:
|
250
248
|
raise ValueError(
|
@@ -255,7 +253,7 @@ class GitRepository:
|
|
255
253
|
# Sparsely checkout the repository if directories are specified and the repo is not in sparse-checkout mode already
|
256
254
|
if self._directories and not await self.is_sparsely_checked_out():
|
257
255
|
await run_process(
|
258
|
-
["git", "sparse-checkout", "set"
|
256
|
+
["git", "sparse-checkout", "set", *self._directories],
|
259
257
|
cwd=self.destination,
|
260
258
|
)
|
261
259
|
|
@@ -323,7 +321,7 @@ class GitRepository:
|
|
323
321
|
if self._directories:
|
324
322
|
self._logger.debug("Will add %s", self._directories)
|
325
323
|
await run_process(
|
326
|
-
["git", "sparse-checkout", "set"
|
324
|
+
["git", "sparse-checkout", "set", *self._directories],
|
327
325
|
cwd=self.destination,
|
328
326
|
)
|
329
327
|
|
@@ -343,7 +341,7 @@ class GitRepository:
|
|
343
341
|
)
|
344
342
|
|
345
343
|
def to_pull_step(self) -> dict[str, Any]:
|
346
|
-
pull_step = {
|
344
|
+
pull_step: dict[str, Any] = {
|
347
345
|
"prefect.deployments.steps.git_clone": {
|
348
346
|
"repository": self._url,
|
349
347
|
"branch": self._branch,
|
@@ -357,13 +355,14 @@ class GitRepository:
|
|
357
355
|
pull_step["prefect.deployments.steps.git_clone"]["credentials"] = (
|
358
356
|
f"{{{{ {self._credentials.get_block_placeholder()} }}}}"
|
359
357
|
)
|
360
|
-
elif isinstance(self._credentials, dict):
|
361
|
-
if isinstance(
|
358
|
+
elif isinstance(self._credentials, dict): # pyright: ignore[reportUnnecessaryIsInstance]
|
359
|
+
if isinstance(
|
360
|
+
access_token := self._credentials.get("access_token"), Secret
|
361
|
+
):
|
362
362
|
pull_step["prefect.deployments.steps.git_clone"]["credentials"] = {
|
363
363
|
**self._credentials,
|
364
364
|
"access_token": (
|
365
|
-
"{{"
|
366
|
-
f" {self._credentials['access_token'].get_block_placeholder()} }}}}"
|
365
|
+
f"{{{{ {access_token.get_block_placeholder()} }}}}"
|
367
366
|
),
|
368
367
|
}
|
369
368
|
elif self._credentials.get("access_token") is not None:
|
@@ -455,10 +454,10 @@ class RemoteStorage:
|
|
455
454
|
|
456
455
|
def replace_blocks_with_values(obj: Any) -> Any:
|
457
456
|
if isinstance(obj, Block):
|
458
|
-
if
|
459
|
-
return
|
457
|
+
if get := getattr(obj, "get", None):
|
458
|
+
return get()
|
460
459
|
if hasattr(obj, "value"):
|
461
|
-
return obj
|
460
|
+
return getattr(obj, "value")
|
462
461
|
else:
|
463
462
|
return obj.model_dump()
|
464
463
|
return obj
|
@@ -467,7 +466,7 @@ class RemoteStorage:
|
|
467
466
|
self._settings, replace_blocks_with_values, return_data=True
|
468
467
|
)
|
469
468
|
|
470
|
-
return fsspec.filesystem(scheme, **settings_with_block_values)
|
469
|
+
return fsspec.filesystem(scheme, **settings_with_block_values) # pyright: ignore[reportUnknownMemberType] missing type stubs
|
471
470
|
|
472
471
|
def set_base_path(self, path: Path) -> None:
|
473
472
|
self._storage_base_path = path
|
@@ -513,7 +512,7 @@ class RemoteStorage:
|
|
513
512
|
try:
|
514
513
|
await from_async.wait_for_call_in_new_thread(
|
515
514
|
create_call(
|
516
|
-
self._filesystem.get,
|
515
|
+
self._filesystem.get, # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType] missing type stubs
|
517
516
|
remote_path,
|
518
517
|
str(self.destination),
|
519
518
|
recursive=True,
|
@@ -580,18 +579,14 @@ class BlockStorageAdapter:
|
|
580
579
|
self._block = block
|
581
580
|
self._pull_interval = pull_interval
|
582
581
|
self._storage_base_path = Path.cwd()
|
583
|
-
if not isinstance(block, Block):
|
582
|
+
if not isinstance(block, Block): # pyright: ignore[reportUnnecessaryIsInstance]
|
584
583
|
raise TypeError(
|
585
584
|
f"Expected a block object. Received a {type(block).__name__!r} object."
|
586
585
|
)
|
587
586
|
if not hasattr(block, "get_directory"):
|
588
587
|
raise ValueError("Provided block must have a `get_directory` method.")
|
589
588
|
|
590
|
-
self._name = (
|
591
|
-
f"{block.get_block_type_slug()}-{block._block_document_name}"
|
592
|
-
if block._block_document_name
|
593
|
-
else str(uuid4())
|
594
|
-
)
|
589
|
+
self._name = f"{block.get_block_type_slug()}-{getattr(block, '_block_document_name', uuid4())}"
|
595
590
|
|
596
591
|
def set_base_path(self, path: Path) -> None:
|
597
592
|
self._storage_base_path = path
|
@@ -610,11 +605,11 @@ class BlockStorageAdapter:
|
|
610
605
|
await self._block.get_directory(local_path=str(self.destination))
|
611
606
|
|
612
607
|
def to_pull_step(self) -> dict[str, Any]:
|
613
|
-
# Give blocks the
|
608
|
+
# Give blocks the chance to implement their own pull step
|
614
609
|
if hasattr(self._block, "get_pull_step"):
|
615
|
-
return self._block
|
610
|
+
return getattr(self._block, "get_pull_step")()
|
616
611
|
else:
|
617
|
-
if
|
612
|
+
if getattr(self._block, "_block_document_name", None) is None:
|
618
613
|
raise BlockNotSavedError(
|
619
614
|
"Block must be saved with `.save()` before it can be converted to a"
|
620
615
|
" pull step."
|
@@ -622,7 +617,7 @@ class BlockStorageAdapter:
|
|
622
617
|
return {
|
623
618
|
"prefect.deployments.steps.pull_with_block": {
|
624
619
|
"block_type_slug": self._block.get_block_type_slug(),
|
625
|
-
"block_document_name": self._block
|
620
|
+
"block_document_name": getattr(self._block, "_block_document_name"),
|
626
621
|
}
|
627
622
|
}
|
628
623
|
|
@@ -723,7 +718,9 @@ def create_storage_from_source(
|
|
723
718
|
return LocalStorage(path=source, pull_interval=pull_interval)
|
724
719
|
|
725
720
|
|
726
|
-
def _format_token_from_credentials(
|
721
|
+
def _format_token_from_credentials(
|
722
|
+
netloc: str, credentials: dict[str, Any] | GitCredentials
|
723
|
+
) -> str:
|
727
724
|
"""
|
728
725
|
Formats the credentials block for the git provider.
|
729
726
|
|
@@ -736,7 +733,10 @@ def _format_token_from_credentials(netloc: str, credentials: dict) -> str:
|
|
736
733
|
token = credentials.get("token") if credentials else None
|
737
734
|
access_token = credentials.get("access_token") if credentials else None
|
738
735
|
|
739
|
-
user_provided_token = access_token or token or password
|
736
|
+
user_provided_token: str | Secret[str] | None = access_token or token or password
|
737
|
+
|
738
|
+
if isinstance(user_provided_token, Secret):
|
739
|
+
user_provided_token = user_provided_token.get()
|
740
740
|
|
741
741
|
if not user_provided_token:
|
742
742
|
raise ValueError(
|
@@ -787,7 +787,7 @@ def _strip_auth_from_url(url: str) -> str:
|
|
787
787
|
|
788
788
|
# Construct a new netloc without the auth info
|
789
789
|
netloc = parsed.hostname
|
790
|
-
if parsed.port:
|
790
|
+
if parsed.port and netloc:
|
791
791
|
netloc += f":{parsed.port}"
|
792
792
|
|
793
793
|
# Build the sanitized URL
|