-
Notifications
You must be signed in to change notification settings - Fork 311
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
Execute launchplans declared locally and automatically adjust input params based on fixed and default values #3115
Merged
+134
−45
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ coverage.xml | |
|
||
# Version file is auto-generated by setuptools_scm | ||
flytekit/_version.py | ||
testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
from flytekit.clis.sdk_in_container.run import ( | ||
RunLevelParams, | ||
get_entities_in_file, | ||
run_command, | ||
run_command, WorkflowCommand, | ||
) | ||
from flytekit.configuration import Config, Image, ImageConfig | ||
from flytekit.core.task import task | ||
|
@@ -28,8 +28,7 @@ | |
from flytekit.remote import FlyteRemote | ||
from typing import Iterator, List | ||
from flytekit.types.iterator import JSON | ||
from flytekit import workflow | ||
|
||
from flytekit import workflow, LaunchPlan | ||
|
||
pytest.importorskip("pandas") | ||
|
||
|
@@ -205,7 +204,7 @@ def test_pyflyte_run_cli(workflow_file): | |
"--s", | ||
json.dumps({"x": {"i": 1, "a": ["h", "e"]}}), | ||
"--t", | ||
json.dumps({"i": [{"i":1,"a":["h","e"]}]}), | ||
json.dumps({"i": [{"i": 1, "a": ["h", "e"]}]}), | ||
], | ||
catch_exceptions=False, | ||
) | ||
|
@@ -293,15 +292,16 @@ def test_all_types_with_yaml_input(): | |
|
||
result = runner.invoke( | ||
pyflyte.main, | ||
["run", os.path.join(DIR_NAME, "workflow.py"), "my_wf", "--inputs-file", os.path.join(os.path.dirname(os.path.realpath(__file__)), "my_wf_input.yaml")], | ||
["run", os.path.join(DIR_NAME, "workflow.py"), "my_wf", "--inputs-file", | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "my_wf_input.yaml")], | ||
catch_exceptions=False, | ||
) | ||
assert result.exit_code == 0, result.stdout | ||
|
||
|
||
def test_all_types_with_pipe_input(monkeypatch): | ||
runner = CliRunner() | ||
input= str(json.load(open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "my_wf_input.json"),"r"))) | ||
input = str(json.load(open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "my_wf_input.json"), "r"))) | ||
monkeypatch.setattr("sys.stdin", io.StringIO(input)) | ||
result = runner.invoke( | ||
pyflyte.main, | ||
|
@@ -321,18 +321,18 @@ def test_all_types_with_pipe_input(monkeypatch): | |
"pipe_input, option_input", | ||
[ | ||
( | ||
str( | ||
json.load( | ||
open( | ||
os.path.join( | ||
os.path.dirname(os.path.realpath(__file__)), | ||
"my_wf_input.json", | ||
), | ||
"r", | ||
str( | ||
json.load( | ||
open( | ||
os.path.join( | ||
os.path.dirname(os.path.realpath(__file__)), | ||
"my_wf_input.json", | ||
), | ||
"r", | ||
) | ||
Comment on lines
+324
to
+332
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. Consider using pathlib for file operations
Consider simplifying the nested function calls by using Code suggestionCheck the AI-generated fix before applying
Code Review Run #58cf8a Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||
) | ||
) | ||
), | ||
"GREEN", | ||
), | ||
"GREEN", | ||
) | ||
], | ||
) | ||
|
@@ -579,11 +579,11 @@ def test_list_default_arguments(wf_path): | |
reason="Github macos-latest image does not have docker installed as per https://github.com/orgs/community/discussions/25777", | ||
) | ||
def test_pyflyte_run_run( | ||
mock_image, | ||
image_string, | ||
leaf_configuration_file_name, | ||
final_image_config, | ||
mock_image_spec_builder, | ||
mock_image, | ||
image_string, | ||
leaf_configuration_file_name, | ||
final_image_config, | ||
mock_image_spec_builder, | ||
): | ||
mock_image.return_value = "cr.flyte.org/flyteorg/flytekit:py3.9-latest" | ||
ImageBuildEngine.register("test", mock_image_spec_builder) | ||
|
@@ -597,10 +597,10 @@ def tk(): ... | |
image_config = ImageConfig.validate_image(None, "", image_tuple) | ||
|
||
pp = ( | ||
pathlib.Path(__file__).parent.parent.parent | ||
/ "configuration" | ||
/ "configs" | ||
/ leaf_configuration_file_name | ||
pathlib.Path(__file__).parent.parent.parent | ||
/ "configuration" | ||
/ "configs" | ||
/ leaf_configuration_file_name | ||
) | ||
|
||
obj = RunLevelParams( | ||
|
@@ -641,7 +641,7 @@ def jsons(): | |
|
||
@mock.patch("flytekit.configuration.default_images.DefaultImages.default_image") | ||
def test_pyflyte_run_with_iterator_json_type( | ||
mock_image, mock_image_spec_builder, caplog | ||
mock_image, mock_image_spec_builder, caplog | ||
): | ||
mock_image.return_value = "cr.flyte.org/flyteorg/flytekit:py3.9-latest" | ||
ImageBuildEngine.register( | ||
|
@@ -679,10 +679,10 @@ def tk_simple_iterator(x: Iterator[int] = iter([1, 2, 3])) -> Iterator[int]: | |
image_config = ImageConfig.validate_image(None, "", image_tuple) | ||
|
||
pp = ( | ||
pathlib.Path(__file__).parent.parent.parent | ||
/ "configuration" | ||
/ "configs" | ||
/ "no_images.yaml" | ||
pathlib.Path(__file__).parent.parent.parent | ||
/ "configuration" | ||
/ "configs" | ||
/ "no_images.yaml" | ||
) | ||
|
||
obj = RunLevelParams( | ||
|
@@ -796,9 +796,9 @@ def test_pyflyte_run_with_none(a_val, workflow_file): | |
[ | ||
(["--env", "MY_ENV_VAR=hello"], '["MY_ENV_VAR"]', "hello"), | ||
( | ||
["--env", "MY_ENV_VAR=hello", "--env", "ABC=42"], | ||
'["MY_ENV_VAR","ABC"]', | ||
"hello,42", | ||
["--env", "MY_ENV_VAR=hello", "--env", "ABC=42"], | ||
'["MY_ENV_VAR","ABC"]', | ||
"hello,42", | ||
), | ||
], | ||
) | ||
|
@@ -813,16 +813,16 @@ def test_pyflyte_run_with_none(a_val, workflow_file): | |
def test_envvar_local_execution(envs, envs_argument, expected_output, workflow_file): | ||
runner = CliRunner() | ||
args = ( | ||
[ | ||
"run", | ||
] | ||
+ envs | ||
+ [ | ||
workflow_file, | ||
"wf_with_env_vars", | ||
"--env_vars", | ||
] | ||
+ [envs_argument] | ||
[ | ||
"run", | ||
] | ||
+ envs | ||
+ [ | ||
workflow_file, | ||
"wf_with_env_vars", | ||
"--env_vars", | ||
] | ||
+ [envs_argument] | ||
) | ||
result = runner.invoke( | ||
pyflyte.main, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import click | ||
|
||
from flytekit import task, workflow, LaunchPlan | ||
from flytekit.clis.sdk_in_container.run import WorkflowCommand, RunLevelParams | ||
|
||
import mock | ||
import pytest | ||
|
||
|
||
@task | ||
def two_inputs(x: int, y: str) -> str: | ||
return f"{x},{y}" | ||
|
||
@workflow | ||
def two_inputs_wf(x: int, y: str) -> str: | ||
return two_inputs(x, y) | ||
|
||
lp_fixed_y_default_x = LaunchPlan.get_or_create( | ||
workflow=two_inputs_wf, | ||
name="fixed-default-inputs", | ||
fixed_inputs={"y": "hello"}, | ||
default_inputs={"x": 1} | ||
) | ||
|
||
lp_fixed_y = LaunchPlan.get_or_create( | ||
workflow=two_inputs_wf, | ||
name="fixed-y", | ||
fixed_inputs={"y": "hello"}, | ||
) | ||
|
||
lp_fixed_x = LaunchPlan.get_or_create( | ||
workflow=two_inputs_wf, | ||
name="fixed-x", | ||
fixed_inputs={"x": 1}, | ||
) | ||
|
||
lp_fixed_all = LaunchPlan.get_or_create( | ||
workflow=two_inputs_wf, | ||
name="fixed-all", | ||
fixed_inputs={"x": 1, "y": "test"}, | ||
) | ||
|
||
lp_default_x = LaunchPlan.get_or_create( | ||
name="default-inputs", | ||
workflow=two_inputs_wf, | ||
default_inputs={"x": 1} | ||
) | ||
|
||
lp_simple = LaunchPlan.get_or_create( | ||
workflow=two_inputs_wf, | ||
name="no-fixed-default", | ||
) | ||
|
||
@pytest.mark.parametrize("lp_execs", [ | ||
(lp_fixed_y_default_x, {"x": 1}), | ||
(lp_fixed_y, {"x": None}), | ||
(lp_fixed_x, {"y": None}), | ||
(lp_fixed_all, {}), | ||
(lp_default_x, {"y": None, "x": 1}), | ||
(lp_simple, {"x": None, "y": None}), | ||
]) | ||
def test_workflowcommand_create_command(lp_execs): | ||
cmd = WorkflowCommand("testfile.py") | ||
rp = RunLevelParams() | ||
ctx = click.Context(cmd, obj=rp) | ||
lp, exp_opts = lp_execs | ||
opts = cmd._create_command(ctx, "test_entity", rp, lp, "launch plan").params | ||
for o in opts: | ||
if "input" in o.name: | ||
continue | ||
assert o.name in exp_opts | ||
assert o.default == exp_opts[o.name] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The launch plan input handling logic could be extracted into a separate helper method to improve code readability and maintainability. Consider moving the logic for handling fixed and default inputs into a dedicated function.
Code suggestion
Code Review Run #58cf8a
Is this a valid issue, or was it incorrectly flagged by the Agent?