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

Added alt prefix head to FlyteFile.new_remote #2601

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions flytekit/types/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,21 @@
return ""

@classmethod
def new_remote_file(cls, name: typing.Optional[str] = None) -> FlyteFile:
def new_remote_file(cls, alt: typing.Optional[str] = None, name: typing.Optional[str] = None) -> FlyteFile:
eapolinario marked this conversation as resolved.
Show resolved Hide resolved
"""
Create a new FlyteFile object with a remote path.

:param alt: If you want to specify a different prefix head than the default one, you can specify it here.
:param name: If you want to specify a different name for the file, you can specify it here.
"""
ctx = FlyteContextManager.current_context()
r = name or ctx.file_access.get_random_string()
remote_path = ctx.file_access.join(ctx.file_access.raw_output_prefix, r)
pref = ctx.file_access.raw_output_prefix

Check warning on line 191 in flytekit/types/file/file.py

View check run for this annotation

Codecov / codecov/patch

flytekit/types/file/file.py#L191

Added line #L191 was not covered by tests
if alt:
s_pref = pref.split("/")
s_pref[2] = alt
eapolinario marked this conversation as resolved.
Show resolved Hide resolved
pref = "/".join(s_pref)
Copy link
Collaborator

Choose a reason for hiding this comment

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

using / explicitly is not going to work on windows. Use os.sep instead.

remote_path = ctx.file_access.join(pref, r)

Check warning on line 196 in flytekit/types/file/file.py

View check run for this annotation

Codecov / codecov/patch

flytekit/types/file/file.py#L193-L196

Added lines #L193 - L196 were not covered by tests
return cls(path=remote_path)

@classmethod
Expand Down
6 changes: 6 additions & 0 deletions tests/flytekit/unit/types/file/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flytekit.types.file import FlyteFile
from flytekit import FlyteContextManager

def test_new_remote_alt():
ff = FlyteFile.new_remote_file(alt="my-alt-prefix")
assert "my-alt-prefix" in ff.path
Loading