Skip to content

Commit

Permalink
Merge branch 'release-7.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenkov committed Mar 21, 2024
2 parents 49b9b32 + 9426457 commit c986a47
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 7.0.2, 2024-03-21

* Add `__next__` method to FileLikeProxy (PR [#811](https://github.com/piskvorky/smart_open/pull/811), [@ddelange](https://github.com/ddelange))
* Fix python_requires minimum python version in setup.py (PR [#807](https://github.com/piskvorky/smart_open/pull/807), [@pressler-vsc](https://github.com/pressler-vsc))
* Add activity check to cached sftp connections (PR [#808](https://github.com/piskvorky/smart_open/pull/808), [@greg-offerfit](https://github.com/greg-offerfit))

# 7.0.1, 2024-02-26

* Do not touch botocore unless it is installed (PR [#803](https://github.com/piskvorky/smart_open/pull/803), [@ddelange](https://github.com/ddelange))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def read(fname):
'ssh': ssh_deps,
'zst': zst_deps,
},
python_requires=">=3.6,<4.0",
python_requires=">=3.7,<4.0",

test_suite="smart_open.tests",

Expand Down
10 changes: 9 additions & 1 deletion smart_open/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ def parse_uri(uri_as_string):


def open_uri(uri, mode, transport_params):
smart_open.utils.check_kwargs(open, transport_params)
# `connect_kwargs` is a legitimate param *only* for sftp, so this filters it out of validation
# (otherwise every call with this present complains it's not valid)
params_to_validate = {k: v for k, v in transport_params.items() if k != 'connect_kwargs'}
smart_open.utils.check_kwargs(open, params_to_validate)
parsed_uri = parse_uri(uri)
uri_path = parsed_uri.pop('uri_path')
parsed_uri.pop('scheme')
Expand Down Expand Up @@ -266,6 +269,11 @@ def open(path, mode='r', host=None, user=None, password=None, port=None, transpo
for attempt in range(attempts):
try:
ssh = _SSH[key]
# Validate that the cached connection is still an active connection
# and if not, refresh the connection
if not ssh.get_transport().active:
ssh.close()
ssh = _SSH[key] = _connect_ssh(host, user, port, password, transport_params)
except KeyError:
ssh = _SSH[key] = _connect_ssh(host, user, port, password, transport_params)

Expand Down
26 changes: 26 additions & 0 deletions smart_open/tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,37 @@ def test_binary_iterator(self):
expected = u"выйду ночью в поле с конём".encode('utf-8').split(b' ')
_resource('s3').Object(BUCKET_NAME, KEY_NAME).put(Body=b'\n'.join(expected))

# test the __iter__ method
with self.assertApiCalls(GetObject=1):
with smart_open.s3.open(BUCKET_NAME, KEY_NAME, 'rb') as fin:
actual = [line.rstrip() for line in fin]
self.assertEqual(expected, actual)

# test the __next__ method
with self.assertApiCalls(GetObject=1):
with smart_open.s3.open(BUCKET_NAME, KEY_NAME, 'rb') as fin:
first = next(fin).rstrip()
self.assertEqual(expected[0], first)

def test_text_iterator(self):
expected = u"выйду ночью в поле с конём".split(' ')
uri = f's3://{BUCKET_NAME}/{KEY_NAME}.gz'

with smart_open.open(uri, 'w', encoding='utf-8') as fout:
fout.write('\n'.join(expected))

# test the __iter__ method
with self.assertApiCalls(GetObject=1):
with smart_open.open(uri, 'r', encoding='utf-8') as fin:
actual = [line.rstrip() for line in fin]
self.assertEqual(expected, actual)

# test the __next__ method
with self.assertApiCalls(GetObject=1):
with smart_open.open(uri, 'r', encoding='utf-8') as fin:
first = next(fin).rstrip()
self.assertEqual(expected[0], first)

def test_defer_seek(self):
content = b'englishman\nin\nnew\nyork\n'
_resource('s3').Object(BUCKET_NAME, KEY_NAME).put(Body=content)
Expand Down
5 changes: 4 additions & 1 deletion smart_open/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def __init__(self, outer, inner):
def __exit__(self, *args, **kwargs):
"""Exit inner after exiting outer."""
try:
super().__exit__(*args, **kwargs)
return super().__exit__(*args, **kwargs)
finally:
self.__inner.__exit__(*args, **kwargs)

def __next__(self):
return self.__wrapped__.__next__()
2 changes: 1 addition & 1 deletion smart_open/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '7.0.1'
__version__ = '7.0.2'


if __name__ == '__main__':
Expand Down

0 comments on commit c986a47

Please sign in to comment.