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

Input through file and pipe #2552

Merged
merged 102 commits into from
Aug 17, 2024
Merged

Conversation

mao3267
Copy link
Contributor

@mao3267 mao3267 commented Jul 3, 2024

Tracking issue

Related to flyteorg/flyte#5365

Why are the changes needed?

  1. We want to input multiple parameters through a single JSON/YAML file. eg. pyflyte run wf.py --inputs-file input.json
  2. We want to support input from pipe as well. eg. cat input.json | pyflyte run wf.py wf

What changes were proposed in this pull request?

  1. Add a new option --inputs-file to specify the input file.
  2. Read from file or pipe and transform into click options
  3. Add unit test (support all types, replace the input from file/pipe if there's an option specify the same parameter)

How was this patch tested?

Currently, two unit tests are performed on this feature. test_all_types_with_file_input and test_replace_file_inputs are added in tests/flytekit/unit/cli/pyflyte/test_run.py

Missing value in custom class

wf.py

from flytekit import task, workflow
from dataclasses import dataclass
import typing
from dataclasses_json import DataClassJsonMixin


@dataclass
class myclass(DataClassJsonMixin):
    i: int
    j: typing.List[int]


@task
def t1(a: myclass) -> myclass:
    return a


@workflow
def wf(a: myclass) -> myclass:
    return t1(a=a)

input.json

{
    "a": {
        "j": [1, 2, 3]
    }
}

Output:
image

Missing input parameter

wf.py

from flytekit import task, workflow

@task
def t1(a: int, b: int) -> int:
    return a + b

@workflow
def wf(a: int, b: int) -> int:
    return t1(a=a, b=b)

input.json

{
    "a": 1,
}

Output:
image

Help message

image

More tests can be added if needed.

Setup process

git clone https://github.com/mao3267/flytekit.git
git checkout input-through-file-and-pipe
make setup && pip install -e .

Screenshots

None

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed. (test_run.py)
  • All commits are signed-off.

Related PRs

#2583

Docs link

ToDo

Copy link

welcome bot commented Jul 3, 2024

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

@mao3267 mao3267 changed the title [WIP] Input through file and pipe Input through file and pipe Jul 20, 2024
@mao3267 mao3267 marked this pull request as ready for review July 21, 2024 03:22
@mao3267 mao3267 marked this pull request as draft July 21, 2024 03:23
@mao3267 mao3267 marked this pull request as ready for review July 26, 2024 06:04
@kumare3
Copy link
Contributor

kumare3 commented Jul 29, 2024

@mao3267 can you please DCO sign-off, This is awesome would love to get it merged

mao3267 and others added 14 commits July 29, 2024 10:58
Signed-off-by: mao3267 <chenvincent610@gmail.com>
…lyteorg#2527)

Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
* Made outfile ephemeral

Signed-off-by: pryce-turner <pryce.turner@gmail.com>

* Changed error handling to warn log for pipe with shell commands

Signed-off-by: pryce-turner <pryce.turner@gmail.com>

---------

Signed-off-by: pryce-turner <pryce.turner@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
…al executions (flyteorg#2476)

* fix: Do not copy local files when using FlyteFile

Signed-off-by: ggydush <greggydush@gmail.com>

* fix: Prevent copying of local files when running local execution

Signed-off-by: ggydush <greggydush@gmail.com>

* fix: Revert

Signed-off-by: ggydush <greggydush@gmail.com>

* fix: Fix another location of should upload

Signed-off-by: ggydush <greggydush@gmail.com>

* test: Fix failing test cases

Signed-off-by: ggydush <greggydush@gmail.com>

* fix: Fix to still handle uploads

Signed-off-by: ggydush <greggydush@gmail.com>

---------

Signed-off-by: ggydush <greggydush@gmail.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
* Validate interface variable names

Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com>

* Remove unused import

Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com>

* Fix lint error

Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com>

---------

Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
- Change the `inputs` and `outputs` attributes in the `Interface` class to `OrderedDict` to preserve the order.
- Write values in positional arguments to `kwargs`.
Resolves: flyteorg/flyte#5320
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Co-authored-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
* print messages for sandbox execute and local execute

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* remove PR 2476 change

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* print execution mode in flytefile

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* add should upload

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* add condition ctx.execution_state.mode != ExecutionState.Mode.TASK_EXECUTION

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* bug found, need to call the function

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* remove comparison

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* use ctx.execution_state.is_local_execution()

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* lint

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* fix bug

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* remove comments

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* revert is_local_execution

Signed-off-by: Future-Outlier <eric901201@gmail.com>

---------

Signed-off-by: Future-Outlier <eric901201@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
* add additional_decks support

Signed-off-by: novahow <b08902047@ntu.edu.tw>

	modified:   flytekit/core/base_task.py
	modified:   flytekit/core/python_function_task.py
	modified:   flytekit/core/task.py
	modified:   flytekit/deck/deck.py
	modified:   tests/flytekit/unit/core/test_flyte_file.py

* add tests and remove confusing fields

Signed-off-by: novahow <b08902047@ntu.edu.tw>

	modified:   flytekit/core/base_task.py
	modified:   flytekit/deck/deck.py
	modified:   tests/flytekit/unit/deck/test_deck.py

* add deckselector

Signed-off-by: novahow <b08902047@ntu.edu.tw>

	modified:   flytekit/core/base_task.py
	modified:   flytekit/core/context_manager.py
	modified:   flytekit/core/task.py
	modified:   flytekit/deck/deck.py
	modified:   tests/flytekit/unit/deck/test_deck.py

* make deck_selector to tuple

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* fix remote deck bug

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* fix timelinedeck and remove rendered_deck param

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* fix UI

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* fix timelinedeck test multiple time_info

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* nit

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* nit with enum

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* nit deck_fields

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* enable all decks, remove plotly dep

Signed-off-by: novahow <b08902047@ntu.edu.tw>

* kevin's update

Signed-off-by: Kevin Su <pingsutw@apache.org>

* nit

Signed-off-by: Kevin Su <pingsutw@apache.org>

* remove chart

Signed-off-by: Kevin Su <pingsutw@apache.org>

---------

Signed-off-by: novahow <b08902047@ntu.edu.tw>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Co-authored-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
…onversion of float

Signed-off-by: mao3267 <chenvincent610@gmail.com>
rdeaton-freenome and others added 6 commits August 1, 2024 10:10
* Remove use of multiprocessing from the OAuth client

Signed-off-by: Robert Deaton <robert.deaton@freenome.com>

* Lint

Signed-off-by: Robert Deaton <robert.deaton@freenome.com>

---------

Signed-off-by: Robert Deaton <robert.deaton@freenome.com>
* fix snowflake agent bug

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* a work version

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Snowflake work version

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* fix secret encode

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* all works, I am so happy

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* improve additional protocol

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* fix tests

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Fix Tests

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* update agent

Signed-off-by: Kevin Su <pingsutw@apache.org>

* Add snowflake test

Signed-off-by: Kevin Su <pingsutw@apache.org>

* nit

Signed-off-by: Kevin Su <pingsutw@apache.org>

* sd

Signed-off-by: Kevin Su <pingsutw@apache.org>

* snowflake loglinks

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* add metadata

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* secret

Signed-off-by: Kevin Su <pingsutw@apache.org>

* nit

Signed-off-by: Kevin Su <pingsutw@apache.org>

* remove table

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* add comment for get private key

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* update comments:

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Fix Tests

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* update comments

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* update comments

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Better Secrets

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* use union secret

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Update Changes

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* use if not get_plugin().secret_requires_group()

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Use Union SDK

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Update

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Fix Secrets

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Fix Secrets

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* remove pacakge.json

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* lint

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* add snowflake-connector-python

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* fix test_snowflake

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Try to fix tests

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* fix tests

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* Try Fix snowflake Import

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* snowflake test passed

Signed-off-by: Future-Outlier <eric901201@gmail.com>

---------

Signed-off-by: Future-Outlier <eric901201@gmail.com>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Co-authored-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
@mao3267 mao3267 force-pushed the input-through-file-and-pipe branch from ec52ab8 to dfecd45 Compare August 1, 2024 06:33
flytekit/clis/sdk_in_container/run.py Outdated Show resolved Hide resolved
flytekit/clis/sdk_in_container/run.py Outdated Show resolved Hide resolved
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
@mao3267 mao3267 force-pushed the input-through-file-and-pipe branch from aa49865 to df9b350 Compare August 3, 2024 01:41
Signed-off-by: mao3267 <chenvincent610@gmail.com>

Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
pingsutw
pingsutw previously approved these changes Aug 5, 2024
Copy link

codecov bot commented Aug 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.76%. Comparing base (69445ff) to head (ff92807).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2552      +/-   ##
==========================================
+ Coverage   79.24%   83.76%   +4.52%     
==========================================
  Files         196        3     -193     
  Lines       19785      154   -19631     
  Branches     4008        0    -4008     
==========================================
- Hits        15678      129   -15549     
+ Misses       3407       25    -3382     
+ Partials      700        0     -700     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…ut-through-file-and-pipe

Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
@pingsutw pingsutw merged commit a8f68d7 into flyteorg:master Aug 17, 2024
99 checks passed
Copy link

welcome bot commented Aug 17, 2024

Congrats on merging your first pull request! 🎉

@mao3267
Copy link
Contributor Author

mao3267 commented Aug 18, 2024

Thanks for the help from @pingsutw, @kumare3 and other reviewers! Glad to see it merged.

@kumare3
Copy link
Contributor

kumare3 commented Aug 18, 2024

Can we add docs for this - this is a very good and important feature for folks experimenting continuously

@pingsutw
Copy link
Member

@mao3267 yeah, thanks for the contribution. Could you help update this doc too?

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.