From 77d177cc331cb8cce158378e98daaae74e044428 Mon Sep 17 00:00:00 2001 From: David Parks Date: Wed, 22 May 2024 15:17:59 -0700 Subject: [PATCH] Small fix to checkout/in functions to seek(0) before reading the file on checkint (#86) --- src/braingeneers/utils/common_utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/braingeneers/utils/common_utils.py b/src/braingeneers/utils/common_utils.py index c0a4031..42353ed 100644 --- a/src/braingeneers/utils/common_utils.py +++ b/src/braingeneers/utils/common_utils.py @@ -255,15 +255,17 @@ def checkin(self, update_file: Union[str, bytes, io.IOBase]): raise TypeError('File must be a string, bytes, or file object.') if isinstance(update_file, str) or isinstance(update_file, io.StringIO): if self.isbinary: - raise ValueError( - 'Cannot check in a string or text file when checkout is specified for binary mode.') + raise ValueError('Cannot check in a string or text file when checkout is specified for binary mode.') if isinstance(update_file, bytes) or isinstance(update_file, io.BytesIO): if not self.isbinary: raise ValueError('Cannot check in bytes or a binary file when checkout is specified for text mode.') + if isinstance(update_file, io.IOBase): + update_file.seek(0) + update_str_or_bytes = update_file if not isinstance(update_file, io.IOBase) else update_file.read() mode = 'w' if not self.isbinary else 'wb' with smart_open.open(self.s3_path_str, mode=mode) as f: - f.write(update_file if not isinstance(update_file, io.IOBase) else update_file.read()) + f.write(update_str_or_bytes) def __init__(self, s3_path_str: str, isbinary: bool = False): # TODO: avoid circular import