From 449ec2f56099221563dea78e6a42fd01a186c23f Mon Sep 17 00:00:00 2001 From: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:11:32 +0200 Subject: [PATCH 1/2] Correct FlyteFile docstring Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> --- flytekit/types/file/file.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/flytekit/types/file/file.py b/flytekit/types/file/file.py index 087cad6b5e..93b2ee2112 100644 --- a/flytekit/types/file/file.py +++ b/flytekit/types/file/file.py @@ -309,38 +309,28 @@ 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: If caching is to be used, specifies the type. + If specified, one of: "blockcache", "bytes", "mmap", "readahead", "first", or "background". + See: https://filesystem-spec.readthedocs.io/en/latest/api.html#readbuffering. + This is especially useful for large file reads. + :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 From 1880c42950a9ab958b1692e00194f5ca4302981b Mon Sep 17 00:00:00 2001 From: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:40:31 +0200 Subject: [PATCH 2/2] changes as per review Signed-off-by: Peeter Piegaze <1153481+ppiegaze@users.noreply.github.com> --- flytekit/types/file/file.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/flytekit/types/file/file.py b/flytekit/types/file/file.py index 93b2ee2112..ca1dccb927 100644 --- a/flytekit/types/file/file.py +++ b/flytekit/types/file/file.py @@ -323,10 +323,8 @@ def copy_file(ff: FlyteFile) -> FlyteFile: :param mode: Open mode. For example: 'r', 'w', 'rb', 'rt', 'wb', etc. :type mode: str - :param cache_type: If caching is to be used, specifies the type. - If specified, one of: "blockcache", "bytes", "mmap", "readahead", "first", or "background". - See: https://filesystem-spec.readthedocs.io/en/latest/api.html#readbuffering. - This is especially useful for large file reads. + :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.