Skip to content

Commit

Permalink
Minor fixes: bz2file dependency, paramiko warning handling (#309)
Browse files Browse the repository at this point in the history
* move paramiko import and warning deeper into code

* improve register_compressor example

* fixup in deprecated smart_open function

multipart_upload_kwargs shouldn't contain endpoint_url.
That parameter is only for resource_kwargs.

* remove bz2file dependency, fix #300

* Revert "remove bz2file dependency, fix #300"

This reverts commit 84a008a.

* make bz2file a dependency only under Py2, fix #300

* re-raise ImportError on failure
  • Loading branch information
mpenkov committed Apr 26, 2019
1 parent 07a205f commit a5bdd65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
17 changes: 11 additions & 6 deletions setup.py
Expand Up @@ -9,6 +9,8 @@

import io
import os
import sys

from setuptools import setup, find_packages


Expand Down Expand Up @@ -41,6 +43,14 @@ def _get_version():
'google-compute-engine==2.8.12'
]

install_requires = [
'boto >= 2.32',
'requests',
'boto3',
]
if sys.version_info[0] == 2:
install_requires.append('bz2file')

setup(
name='smart_open',
version=_get_version(),
Expand All @@ -66,12 +76,7 @@ def _get_version():
license='MIT',
platforms='any',

install_requires=[
'boto >= 2.32',
'bz2file',
'requests',
'boto3',
],
install_requires=install_requires,
tests_require=tests_require,
extras_require={
'test': tests_require,
Expand Down
10 changes: 6 additions & 4 deletions smart_open/smart_open_lib.py
Expand Up @@ -81,11 +81,13 @@ def register_compressor(ext, callback):
--------
Instruct smart_open to use the identity function whenever opening a file
with a .foo extension:
with a .xz extension (see README.rst for the complete example showing I/O):
>>> def identity(file_obj, mode):
... return file_obj
>>> register_compressor('.foo', identity)
>>> def _handle_xz(file_obj, mode):
... import lzma
... return lzma.LZMAFile(filename=file_obj, mode=mode, format=lzma.FORMAT_XZ)
>>>
>>> register_compressor('.xz', _handle_xz)
"""
if not (ext and ext[0] == '.'):
Expand Down
14 changes: 9 additions & 5 deletions smart_open/ssh.py
Expand Up @@ -28,11 +28,6 @@

logger = logging.getLogger(__name__)

try:
import paramiko
except ImportError:
warnings.warn('paramiko missing, opening SSH/SCP/SFTP paths will be disabled. `pip install paramiko` to suppress')

#
# Global storage for SSH connections.
#
Expand All @@ -45,6 +40,15 @@


def _connect(hostname, username, port):
try:
import paramiko
except ImportError:
warnings.warn(
'paramiko missing, opening SSH/SCP/SFTP paths will be disabled. '
'`pip install paramiko` to suppress'
)
raise

key = (hostname, username)
ssh = _SSH.get(key)
if ssh is None:
Expand Down

0 comments on commit a5bdd65

Please sign in to comment.