Skip to content

Commit

Permalink
Added alt prefix head to FlyteFile.new_remote
Browse files Browse the repository at this point in the history
Signed-off-by: pryce-turner <[email protected]>
  • Loading branch information
pryce-turner committed Jul 22, 2024
1 parent 551924a commit e905d31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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 @@ def extension(cls) -> str:
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:
"""
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
pref = "/".join(s_pref)
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

0 comments on commit e905d31

Please sign in to comment.