add class methods, unit tests for flytefile and flytedirectory #2852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I feel like it is verbose to get the working directory (
flytekit.current_context().working_directory
) in a task. I find myself doing this very, very frequently, primarily to write files. I use the working directory so that files won’t get written to my local working directory during local execution.I had thought about this for a while, and the more I thought about what exactly I wanted to accomplish, I feel like it should be accomplished with a few new classmethod for
FlyteFile
/FlyteDirectory
...This task...
Should ideally be replaced with something like this:
In this case,
FlyteFile.new
will create a FlyteFile with a path of the filename inside of the working directory (current_context().working_directory
).The same goes for FlyteDirectory...
Should be replaced with:
In this case,
FlyteDirectory.new
will create the directorymy_new_directory
undercurrent_context().working_directory
, and ensure that it exists (os.makedirs(dir.path)
)Additionally, I am overloading the
__truedivide__
operator toFlyteDirectory
for convenience: