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

Add support for Union[FlyteFile, FlyteDirectory] as input #2273

Merged
merged 5 commits into from
Mar 19, 2024

Conversation

pingsutw
Copy link
Member

Tracking issue

NA

Why are the changes needed?

Can not use Union[FlyteFile, FlyteDirectory] as input

What changes were proposed in this pull request?

Check the metadata in the literal before deserializing FlyteFile/FlyteDirectory

How was this patch tested?

local/remote

Setup process

import os
import tempfile
from typing import Union

from flytekit import task, workflow, ImageSpec
from flytekit.types.directory import FlyteDirectory
from flytekit.types.file import FlyteFile

new_flytekit = "git+https://github.com/flyteorg/flytekit.git@d6ae58fb1ee6a7509d15fb1022d294bc2978e1dd"
image_spec = ImageSpec(packages=[new_flytekit], registry="pingsutw", apt_packages=["git"])


@task(container_image=image_spec)
def t1() -> FlyteFile:
    temp_dir = tempfile.mkdtemp(prefix='temp_example_')
    file1_path = os.path.join(temp_dir, 'file1.txt')
    with open(file1_path, 'w') as file1:
        file1.write('Content of file1.txt')
    return file1_path


@task(container_image=image_spec)
def t2() -> FlyteDirectory:
    temp_dir = tempfile.mkdtemp(prefix='temp_example_')
    return temp_dir


@task(container_image=image_spec)
def t3() -> Union[FlyteFile, FlyteDirectory]:
    temp_dir = tempfile.mkdtemp(prefix='temp_example_')
    return temp_dir


@task(container_image=image_spec)
def res(a: Union[FlyteFile, FlyteDirectory]):
    print(a)


@workflow
def wf():
    res(a=t1())
    res(a=t2())
    res(a=t3())


if __name__ == '__main__':
    wf()

Screenshots

image

Check all the applicable boxes

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

Related PRs

NA

Docs link

NA

Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 15, 2024
Signed-off-by: Kevin Su <[email protected]>
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.31%. Comparing base (4767fd8) to head (9f7e65f).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2273      +/-   ##
==========================================
- Coverage   83.78%   83.31%   -0.48%     
==========================================
  Files         332      309      -23     
  Lines       25132    24055    -1077     
  Branches     3703     3493     -210     
==========================================
- Hits        21058    20041    -1017     
+ Misses       3449     3386      -63     
- Partials      625      628       +3     

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

@dosubot dosubot bot added the lgtm This PR has been approved by maintainer label Mar 19, 2024
@wild-endeavor wild-endeavor merged commit f45dc39 into master Mar 19, 2024
46 of 47 checks passed
fiedlerNr9 pushed a commit that referenced this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants