Skip to content

Commit

Permalink
Support s3 path for click Dir param type (#2547)
Browse files Browse the repository at this point in the history
Signed-off-by: Future-Outlier <[email protected]>
  • Loading branch information
Future-Outlier authored Jul 2, 2024
1 parent a9c1308 commit 825a50e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions flytekit/interaction/click_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ def convert(
) -> typing.Any:
if isinstance(value, ArtifactQuery):
return value
p = pathlib.Path(value)

# set remote_directory to false if running pyflyte run locally. This makes sure that the original
# directory is used and not a random one.
remote_directory = None if getattr(ctx.obj, "is_remote", False) else False
if p.exists() and p.is_dir():
return FlyteDirectory(path=value, remote_directory=remote_directory)
raise click.BadParameter(f"parameter should be a valid directory path, {value}")
if not FileAccessProvider.is_remote(value):
p = pathlib.Path(value)
if not p.exists() or not p.is_dir():
raise click.BadParameter(f"parameter should be a valid flytedirectory path, {value}")
return FlyteDirectory(path=value, remote_directory=remote_directory)


class StructuredDatasetParamType(click.ParamType):
Expand Down
8 changes: 8 additions & 0 deletions tests/flytekit/unit/interaction/test_click_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@

dummy_param = click.Option(["--dummy"], type=click.STRING, default="dummy")

def test_dir_param():
import os
m = mock.MagicMock()
current_file_directory = os.path.dirname(os.path.abspath(__file__))
l = DirParamType().convert(current_file_directory, m, m)
assert l.path == current_file_directory
r = DirParamType().convert("https://tmp/dir", m, m)
assert r.path == "https://tmp/dir"

def test_file_param():
m = mock.MagicMock()
Expand Down

0 comments on commit 825a50e

Please sign in to comment.