Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling to propagate dependencies for submitted flow runs #17250

Draft
wants to merge 3 commits into
base: k8s-worker-submit
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies = [
"ujson>=5.8.0,<6.0.0",
"uvicorn>=0.14.0,!=0.29.0",
"websockets>=10.4,<14.0",
"uv>=0.6.0",
]
[project.urls]
Changelog = "https://github.com/PrefectHQ/prefect/releases"
Expand Down
18 changes: 18 additions & 0 deletions src/prefect/_experimental/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import multiprocessing
import multiprocessing.context
import os
import subprocess
import sys
from typing import Any, TypedDict

import cloudpickle
import uv

from prefect.client.schemas.objects import FlowRun
from prefect.context import SettingsContext, get_settings_context, serialize_context
Expand All @@ -30,6 +32,7 @@ class SerializedBundle(TypedDict):
function: str
context: str
flow_run: dict[str, Any]
dependencies: str


def _serialize_bundle_object(obj: Any) -> str:
Expand Down Expand Up @@ -68,6 +71,15 @@ def create_bundle_for_flow_run(
"function": _serialize_bundle_object(flow),
"context": _serialize_bundle_object(context),
"flow_run": flow_run.model_dump(mode="json"),
"dependencies": subprocess.check_output(
[
uv.find_uv_bin(),
"pip",
"freeze",
]
)
.decode()
.strip(),
}


Expand Down Expand Up @@ -131,6 +143,12 @@ def execute_bundle_in_subprocess(

ctx = multiprocessing.get_context("spawn")

# Install dependencies if necessary
if dependencies := bundle.get("dependencies"):
subprocess.check_call(
[uv.find_uv_bin(), "pip", "install", *dependencies.split("\n")],
)

process = ctx.Process(
target=_extract_and_run_flow,
kwargs={
Expand Down
Loading