Skip to content

Commit

Permalink
Correct FlyteFile docstring (flyteorg#2658)
Browse files Browse the repository at this point in the history
Signed-off-by: mao3267 <chenvincent610@gmail.com>
  • Loading branch information
ppiegaze authored and mao3267 committed Aug 9, 2024
1 parent 140b58f commit 78a6219
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions flytekit/types/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,38 +309,26 @@ def open(
cache_type: typing.Optional[str] = None,
cache_options: typing.Optional[typing.Dict[str, typing.Any]] = None,
):
"""
Returns a streaming File handle
"""Returns a streaming File handle
.. code-block:: python
@task
def copy_file(ff: FlyteFile) -> FlyteFile:
new_file = FlyteFile.new_remote_file(ff.name)
with ff.open("rb", cache_type="readahead", cache={}) as r:
new_file = FlyteFile.new_remote_file()
with ff.open("rb", cache_type="readahead") as r:
with new_file.open("wb") as w:
w.write(r.read())
return new_file
Alternatively,
.. code-block:: python
@task
def copy_file(ff: FlyteFile) -> FlyteFile:
new_file = FlyteFile.new_remote_file(ff.name)
with fsspec.open(f"readahead::{ff.remote_path}", "rb", readahead={}) as r:
with new_file.open("wb") as w:
w.write(r.read())
return new_file
:param mode: str Open mode like 'rb', 'rt', 'wb', ...
:param cache_type: optional str Specify if caching is to be used. Cache protocol can be ones supported by
fsspec https://filesystem-spec.readthedocs.io/en/latest/api.html#readbuffering,
especially useful for large file reads
:param cache_options: optional Dict[str, Any] Refer to fsspec caching options. This is strongly coupled to the
cache_protocol
:param mode: Open mode. For example: 'r', 'w', 'rb', 'rt', 'wb', etc.
:type mode: str
:param cache_type: Specifies the cache type. Possible values are "blockcache", "bytes", "mmap", "readahead", "first", or "background".
This is especially useful for large file reads. See https://filesystem-spec.readthedocs.io/en/latest/api.html#readbuffering.
:type cache_type: str, optional
:param cache_options: A Dict corresponding to the parameters for the chosen cache_type.
Refer to fsspec caching options above.
:type cache_options: Dict[str, Any], optional
"""
ctx = FlyteContextManager.current_context()
final_path = self.path
Expand Down

0 comments on commit 78a6219

Please sign in to comment.