Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout/in bugfix #86

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/braingeneers/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading