acoustic-carpenter-78188
10/31/2023, 12:06 AMflytectl demo cluster:
from pathlib import Path
from typing import List
from flytekit import task, workflow
from flytekit.types.directory import FlyteDirectory
@task
def create_directory() -> FlyteDirectory:
path = Path("/tmp/flytekit-testing")
path.mkdir(exist_ok=True, parents=True)
for file in ["file1.txt", "file2.txt"]:
with (path / file).open("w") as f:
f.write("hey\n")
return FlyteDirectory(path=str(path))
@task
def downstream_task(directory: FlyteDirectory) -> List[str]:
output = []
for file in Path(directory.path).glob("*"):
output.append(str(file))
print(file)
return output
@workflow
def wf() -> List[str]:
return downstream_task(bento_model=create_directory())
if __name__ == "__main__":
wf()
You'll find that the output of the downstream_task contains no filepath strings:
image▾
directory.path. Instead, I need to explicitly call directory.download() to get those files there.
Why is this a problem? Because the local and remote experiences are divergent: if I just run the tasks above with python, the files are there. But when executing remotely, now I need to change my code to .download() the files.
Potential Solutions
1. automatically download the files
2. raise an exception if the directory.path is invoked but directory.downloaded == False
3. make the local python experience equivalent to the remote one: force the user to invoke download().
4. others?
Additional context to reproduce
No response
Screenshots
No response
Are you sure this issue hasn't been raised already?
☑︎ Yes
Have you read the Code of Conduct?
☑︎ Yes
flyteorg/flyteacoustic-carpenter-78188
10/31/2023, 12:06 AMacoustic-carpenter-78188
11/02/2023, 8:36 PM