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
* Made outfile ephemeral

Signed-off-by: pryce-turner <[email protected]>

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

Signed-off-by: pryce-turner <[email protected]>

---------

Signed-off-by: pryce-turner <[email protected]>
Signed-off-by: mao3267 <[email protected]>
…al executions (flyteorg#2476)

* fix: Do not copy local files when using FlyteFile

Signed-off-by: ggydush <[email protected]>

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

Signed-off-by: ggydush <[email protected]>

* fix: Revert

Signed-off-by: ggydush <[email protected]>

* fix: Fix another location of should upload

Signed-off-by: ggydush <[email protected]>

* test: Fix failing test cases

Signed-off-by: ggydush <[email protected]>

* fix: Fix to still handle uploads

Signed-off-by: ggydush <[email protected]>

---------

Signed-off-by: ggydush <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
Signed-off-by: mao3267 <[email protected]>
* Validate interface variable names

Signed-off-by: ddl-rliu <[email protected]>

* Remove unused import

Signed-off-by: ddl-rliu <[email protected]>

* Fix lint error

Signed-off-by: ddl-rliu <[email protected]>

---------

Signed-off-by: ddl-rliu <[email protected]>
Signed-off-by: mao3267 <[email protected]>
- 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 <[email protected]>
Signed-off-by: mao3267 <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: mao3267 <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: mao3267 <[email protected]>
* print messages for sandbox execute and local execute

Signed-off-by: Future-Outlier <[email protected]>

* remove PR 2476 change

Signed-off-by: Future-Outlier <[email protected]>

* print execution mode in flytefile

Signed-off-by: Future-Outlier <[email protected]>

* add should upload

Signed-off-by: Future-Outlier <[email protected]>

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

Signed-off-by: Future-Outlier <[email protected]>

* bug found, need to call the function

Signed-off-by: Future-Outlier <[email protected]>

* remove comparison

Signed-off-by: Future-Outlier <[email protected]>

* use ctx.execution_state.is_local_execution()

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* fix bug

Signed-off-by: Future-Outlier <[email protected]>

* remove comments

Signed-off-by: Future-Outlier <[email protected]>

* revert is_local_execution

Signed-off-by: Future-Outlier <[email protected]>

---------

Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: mao3267 <[email protected]>
* add additional_decks support

Signed-off-by: novahow <[email protected]>

	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 <[email protected]>

	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 <[email protected]>

	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 <[email protected]>

* fix remote deck bug

Signed-off-by: novahow <[email protected]>

* fix timelinedeck and remove rendered_deck param

Signed-off-by: novahow <[email protected]>

* fix UI

Signed-off-by: novahow <[email protected]>

* fix timelinedeck test multiple time_info

Signed-off-by: novahow <[email protected]>

* nit

Signed-off-by: novahow <[email protected]>

* nit with enum

Signed-off-by: novahow <[email protected]>

* nit deck_fields

Signed-off-by: novahow <[email protected]>

* enable all decks, remove plotly dep

Signed-off-by: novahow <[email protected]>

* kevin's update

Signed-off-by: Kevin Su <[email protected]>

* nit

Signed-off-by: Kevin Su <[email protected]>

* remove chart

Signed-off-by: Kevin Su <[email protected]>

---------

Signed-off-by: novahow <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: mao3267 <[email protected]>
Future-Outlier and others added 4 commits August 1, 2024 10:10
* fix snowflake agent bug

Signed-off-by: Future-Outlier <[email protected]>

* a work version

Signed-off-by: Future-Outlier <[email protected]>

* Snowflake work version

Signed-off-by: Future-Outlier <[email protected]>

* fix secret encode

Signed-off-by: Future-Outlier <[email protected]>

* all works, I am so happy

Signed-off-by: Future-Outlier <[email protected]>

* improve additional protocol

Signed-off-by: Future-Outlier <[email protected]>

* fix tests

Signed-off-by: Future-Outlier <[email protected]>

* Fix Tests

Signed-off-by: Future-Outlier <[email protected]>

* update agent

Signed-off-by: Kevin Su <[email protected]>

* Add snowflake test

Signed-off-by: Kevin Su <[email protected]>

* nit

Signed-off-by: Kevin Su <[email protected]>

* sd

Signed-off-by: Kevin Su <[email protected]>

* snowflake loglinks

Signed-off-by: Future-Outlier <[email protected]>

* add metadata

Signed-off-by: Future-Outlier <[email protected]>

* secret

Signed-off-by: Kevin Su <[email protected]>

* nit

Signed-off-by: Kevin Su <[email protected]>

* remove table

Signed-off-by: Future-Outlier <[email protected]>

* add comment for get private key

Signed-off-by: Future-Outlier <[email protected]>

* update comments:

Signed-off-by: Future-Outlier <[email protected]>

* Fix Tests

Signed-off-by: Future-Outlier <[email protected]>

* update comments

Signed-off-by: Future-Outlier <[email protected]>

* update comments

Signed-off-by: Future-Outlier <[email protected]>

* Better Secrets

Signed-off-by: Future-Outlier <[email protected]>

* use union secret

Signed-off-by: Future-Outlier <[email protected]>

* Update Changes

Signed-off-by: Future-Outlier <[email protected]>

* use if not get_plugin().secret_requires_group()

Signed-off-by: Future-Outlier <[email protected]>

* Use Union SDK

Signed-off-by: Future-Outlier <[email protected]>

* Update

Signed-off-by: Future-Outlier <[email protected]>

* Fix Secrets

Signed-off-by: Future-Outlier <[email protected]>

* Fix Secrets

Signed-off-by: Future-Outlier <[email protected]>

* remove pacakge.json

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* add snowflake-connector-python

Signed-off-by: Future-Outlier <[email protected]>

* fix test_snowflake

Signed-off-by: Future-Outlier <[email protected]>

* Try to fix tests

Signed-off-by: Future-Outlier <[email protected]>

* fix tests

Signed-off-by: Future-Outlier <[email protected]>

* Try Fix snowflake Import

Signed-off-by: Future-Outlier <[email protected]>

* snowflake test passed

Signed-off-by: Future-Outlier <[email protected]>

---------

Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
@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
@mao3267 mao3267 force-pushed the input-through-file-and-pipe branch from aa49865 to df9b350 Compare August 3, 2024 01:41
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.

@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.