-
Notifications
You must be signed in to change notification settings - Fork 30
run python script supports debugging, code bundling, output dir #789
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
Changes from all commits
828ea0b
c9493a1
49d3b75
d44bae3
3e9fba9
a7efecc
930891a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """ | ||
| Run with: | ||
|
|
||
| ```bash | ||
| flyte run --follow python-script hello.py --output-dir output | ||
| ``` | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
|
|
||
| def main(): | ||
| print("Hello, world!") | ||
| os.makedirs("output", exist_ok=True) | ||
| with open("output/hello.txt", "w") as f: | ||
| f.write("Hello, file!") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,20 @@ | ||
| from ._ignore import GitIgnore, IgnoreGroup, StandardIgnore | ||
| from ._utils import CopyFiles | ||
| from .bundle import build_code_bundle, build_pkl_bundle, download_bundle | ||
| from .bundle import ( | ||
| build_code_bundle, | ||
| build_code_bundle_from_relative_paths, | ||
| build_pkl_bundle, | ||
| download_bundle, | ||
| ) | ||
|
|
||
| __all__ = ["CopyFiles", "build_code_bundle", "build_pkl_bundle", "default_ignores", "download_bundle"] | ||
| __all__ = [ | ||
| "CopyFiles", | ||
| "build_code_bundle", | ||
| "build_code_bundle_from_relative_paths", | ||
| "build_pkl_bundle", | ||
| "default_ignores", | ||
| "download_bundle", | ||
| ] | ||
|
|
||
|
|
||
| default_ignores = [GitIgnore, StandardIgnore, IgnoreGroup] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
|
|
||
| from ._ignore import Ignore, IgnoreGroup, StandardIgnore | ||
|
|
||
| CopyFiles = Literal["loaded_modules", "all", "none"] | ||
| CopyFiles = Literal["loaded_modules", "all", "none", "custom"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't follow this... what does this do? Are we adding this to the public API now? how will users specify this on the command line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eventually yes, but for now it raises an error in the CLI: https://github.com/flyteorg/flyte-sdk/pull/789/changes/BASE..930891aee1134516f04b3d53807e83d116de98e3#diff-2cf224e2941b042aea27fbca293952e864aced9d4fae51de65eb9961a8aa6482R231-R232 |
||
|
|
||
|
|
||
| def compress_scripts(source_path: str, destination: str, modules: List[ModuleType]): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Generic resolver for internal Flyte tasks. | ||
|
|
||
| Stores an import path to a task-builder function and arbitrary keyword | ||
| arguments. At runtime ``load_task`` dynamically imports the builder and | ||
| calls it with the stored kwargs, recreating a lightweight task without | ||
| pickling. This is the same mechanism used by ``run_python_script`` and | ||
| can be reused for prefetch, custom bundling, and other internal tasks. | ||
| """ | ||
|
|
||
| import importlib | ||
| from pathlib import Path | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
| from flyte._internal.resolvers.common import Resolver | ||
| from flyte._task import TaskTemplate | ||
|
|
||
|
|
||
| class InternalTaskResolver(Resolver): | ||
| """Resolve an internal task by dynamically importing its builder. | ||
|
|
||
| During serialization the resolver stores: | ||
|
|
||
| * ``task_builder`` - fully-qualified import path of a callable that | ||
| returns a :class:`TaskTemplate` (e.g. | ||
| ``"flyte._run_python_script._build_script_runner_task"``). | ||
| * Arbitrary keyword arguments forwarded to the builder. | ||
|
|
||
| At runtime :meth:`load_task` re-imports the builder and calls it with | ||
| the stored kwargs. | ||
| """ | ||
|
|
||
| def __init__(self, task_builder: str = "", **kwargs: Any): | ||
| self._task_builder = task_builder | ||
| self._kwargs = kwargs | ||
|
|
||
| @property | ||
| def import_path(self) -> str: | ||
| return "flyte._internal.resolvers.internal.InternalTaskResolver" | ||
|
|
||
| def load_task(self, loader_args: List[str]) -> TaskTemplate: | ||
| args_iter = iter(loader_args) | ||
| parsed: Dict[str, str] = dict(zip(args_iter, args_iter)) | ||
|
|
||
| builder_path = parsed.pop("task_builder") | ||
| module_path, func_name = builder_path.rsplit(".", 1) | ||
| module = importlib.import_module(module_path) | ||
| builder = getattr(module, func_name) | ||
|
|
||
| return builder(**parsed) | ||
|
|
||
| def loader_args(self, task: TaskTemplate, root_dir: Optional[Path] = None) -> List[str]: | ||
| args = ["task_builder", self._task_builder] | ||
| for key, value in self._kwargs.items(): | ||
| if value is not None: | ||
| args.extend([key, str(value)]) | ||
| return args |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep