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

Adds support for YAML file to pyflyte run #2583

Closed
wants to merge 2 commits into from
Closed

Conversation

kumare3
Copy link
Contributor

@kumare3 kumare3 commented Jul 16, 2024

Tracking issue

flyteorg/flyte#5365

Why are the changes needed?

To pass a yaml | json file

What changes were proposed in this pull request?

You can now pass all inputs as yaml optionally using the flag --flyte-inputs-file . It can also be a json

 pyflyte run exhaustive.py t1 --flyte-inputs-file t.yaml

Also it is possible to override certain parameters in the input file using additional args, like so

pyflyte run exhaustive.py t1 --flyte-inputs-file t.yaml --f 4.0 --e green

For the interface

@task
def t1(i: int, f: float, s: str, foo: Foo, ff: FlyteFile, fd: FlyteDirectory, e: Color, l: typing.List[int], d: typing.Dict[str, int], b: bool, j: typing.Optional[int] = None):
    pass

The yaml file t.yaml is like this

i: 10
f: 1.0
s: "hello"
foo:
  i: 10
ff: /tmp/remote.py
fd: /tmp
e: red
l:
 - 1
 - 2
 - 4
d:
  x: 1
  y: 2
b: false

TODO:

  • unit tests

Signed-off-by: Ketan Umare <kumare3@users.noreply.github.com>
Signed-off-by: Ketan Umare <kumare3@users.noreply.github.com>
new_args = []
for k, v in inputs.items():
if isinstance(v, str):
v = v
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha ya

mao3267 added a commit to mao3267/flytekit that referenced this pull request Jul 20, 2024
@mao3267 mao3267 mentioned this pull request Jul 20, 2024
3 tasks
try:
inputs = json.load(f)
except json.JSONDecodeError as e:
click.secho(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lets raise an exception here - maybe of type click.BadParameterException ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean changing the secho lines (line 797 - 803) to something like this?

raise click.BadParameter(
    message=f"Could not load the inputs file. Please make sure it is a valid JSON or YAML file."
    f"\n json error: {e},"
    f"\n yaml error: {yaml_e}",
    param_hint="--flyte-inputs-file",
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@kumare3
Copy link
Contributor Author

kumare3 commented Jul 20, 2024

Couple small nits, then lets ship it. Also can you please add some unit tests? cc @mao3267. I want to get this commit in quickly. Adding unit tests, especially the example I have and maybe another nested JSON example will help

def __init__(self, name: str, params: typing.List[click.Option], help: str, callback: typing.Callable = None):
params.append(
click.Option(
["--flyte-inputs-file"],
Copy link
Member

Choose a reason for hiding this comment

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

At this point, we are already running pyflyte run .... Can the option be called --inputs-file?

@mao3267
Copy link
Contributor

mao3267 commented Jul 21, 2024

Couple small nits, then lets ship it. Also can you please add some unit tests? cc @mao3267. I want to get this commit in quickly. Adding unit tests, especially the example I have and maybe another nested JSON example will help

Some unit tests are added in #2552 . Does the test_all_types_with_file_input in tests/flytekit/unit/cli/pyflyte/test_run.py look good? Currently it's tested on the existed workflow my_wf with json file and pipe as inputs to check if it supports all kinds of inputs. Maybe add a yaml one?

mao3267 added a commit to mao3267/flytekit that referenced this pull request Jul 29, 2024
mao3267 added a commit to mao3267/flytekit that referenced this pull request Aug 1, 2024
@kumare3
Copy link
Contributor Author

kumare3 commented Oct 9, 2024

I see that this was already merged. I am closing the PR.
we need docs for this.
cc @mao3267 can you help with the docs?
cc @neverett fyi

@kumare3 kumare3 closed this Oct 9, 2024
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.

4 participants