Skip to content

run python script supports debugging, code bundling, output dir#789

Open
cosmicBboy wants to merge 6 commits intomainfrom
nielsb/run-python-script-bundle
Open

run python script supports debugging, code bundling, output dir#789
cosmicBboy wants to merge 6 commits intomainfrom
nielsb/run-python-script-bundle

Conversation

@cosmicBboy
Copy link
Contributor

This pull request introduces support for running plain Python scripts as Flyte tasks without pickling, by bundling the script and using a new ScriptTaskResolver. It also adds a new copy style (python_script) for code bundles, updates the task and environment APIs to support custom resolvers, and improves the developer experience for remote script execution and debugging. Additional minor changes update dependencies and resource specifications in example files.

Python script task support and code bundling:

  • Added ScriptTaskResolver (src/flyte/_internal/resolvers/script.py) to enable bundling and execution of plain Python scripts as Flyte tasks, avoiding pickling and enabling proper remote debugging.
  • Updated run_python_script (src/flyte/_run_python_script.py) to use the new resolver, bundle scripts with the new python_script copy style, and support VS Code debugging. [1] [2] [3] [4]
  • Introduced build_code_bundle_from_relative_paths and added "python_script" to the CopyFiles literal for selective script bundling. [1] [2]
  • Modified _Runner and remote/hybrid run logic to support the new copy style and script bundling parameters. [1] [2] [3] [4] [5]

Task and environment API enhancements:

  • Added task_resolver argument to TaskEnvironment.task and AsyncFunctionTaskTemplate, and ensured it is used during serialization and container argument construction. [1] [2] [3] [4] [5]

Developer experience and examples:

  • Added a new hello.py script example demonstrating running a plain Python script with Flyte.
  • Updated example resource specifications and dependency versions for better compatibility and GPU support. [1] [2] [3]
  • Added more arguments to VS Code debug launch configuration for improved debugging.

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
@dataclass
class PythonScriptOutput:
exit_code: int
stdout: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should capture the stdout, this is already in the logs. This can be a lot!

Copy link
Contributor Author

@cosmicBboy cosmicBboy Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note here that I'm only getting the last 1000 characters: https://github.com/flyteorg/flyte-sdk/pull/789/changes#diff-bc180013a121c671af8420075855a9a12efdcd6a01b24e90c07a6322a09001ceR75-R76

This is still useful for local debugging... user (or agent) gets stderr and stdout in the CLI, we have to think LLM-first!

class PythonScriptOutput:
exit_code: int
stdout: str
stderr: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for stderr

Copy link
Contributor Author

@cosmicBboy cosmicBboy Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note here that I'm only getting the last 1000 characters: https://github.com/flyteorg/flyte-sdk/pull/789/changes#diff-bc180013a121c671af8420075855a9a12efdcd6a01b24e90c07a6322a09001ceR75-R76

This is still useful for local debugging... user (or agent) gets stderr and stdout in the CLI, we have to think LLM-first!

__all__ = [
"CopyFiles",
"build_code_bundle",
"build_code_bundle_from_relative_paths",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this an existing function, is it used for apps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

initialize_config = common.initialize_config


@syncify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed because there are two call sites. one in the run python script path (called synchronously), the other is in _run.py:

Where it's called async

@kumare3
Copy link
Contributor

kumare3 commented Mar 13, 2026

I think we should also add support for additional files regex (as a follow up us ok), so i like the include files thing

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
@cosmicBboy
Copy link
Contributor Author

cosmicBboy commented Mar 13, 2026

I think we should also add support for additional files regex (as a follow up us ok), so i like the include files thing

yep, gonna do that in a separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants