forked from piskvorky/smart_open
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support installing smart_open without AWS dependencies (piskvorky#534)
* first pass at removing aws from core dependencies - don't export s3_iter_bucket at the top-level. We could probably still make this work, but it would be ugly. This is the only breaking change I can see - add suggestive install commands when importing a module that you don't have the deps for * add python-jose for test suite - the tests fail locally without it installed * drop eggs readme * fix flake8 errors * add tests for missing package import errors * remove type annotation from test * add s3_iter_bucket back to the main package - wrap it in a lazy-loaded warning about being deprecated in favor of importing iter_bucket from s3 - add some more tests * cleanup from review * add helpful error when opening uri of unsupported type - this isn't the prettiest, but it's still better than a generic error that something might be wrong with a link to the readme? - duplicate the schemes list inside of transport.py where the modules are registered. This way if you try to open a URI with that scheme we can show the nice "pip install smart_open[type]" error message. - add tests for transport registration and error propagation * exclude test fixtures from code cov * Apply suggestions from code review Co-authored-by: Michael Penkov <[email protected]> * cleanup from review - DRY up the missing import errors by putting the logic in transport.py - add MISSING_DEPS to transport modules that can be set to true when handling import errors. This allows the submodule to load properly (so we can inspect the scheme/s) even if it's missing required pacakges. - remove double-specified transport schemes (because of MISSING_DEPS) * cleanup from review * cleanup from review * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Michael Penkov <[email protected]>
- Loading branch information
1 parent
41a7ab6
commit efe1e9d
Showing
19 changed files
with
241 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
"""A no-op transport that registers scheme 'foo'""" | ||
import io | ||
|
||
SCHEME = "foo" | ||
open = io.open | ||
|
||
|
||
def parse_uri(uri_as_string): # pragma: no cover | ||
... | ||
|
||
|
||
def open_uri(uri_as_string, mode, transport_params): # pragma: no cover | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Transport that has missing deps""" | ||
import io | ||
|
||
|
||
try: | ||
import this_module_does_not_exist_but_we_need_it # noqa | ||
except ImportError: | ||
MISSING_DEPS = True | ||
|
||
SCHEME = "missing" | ||
open = io.open | ||
|
||
|
||
def parse_uri(uri_as_string): # pragma: no cover | ||
... | ||
|
||
|
||
def open_uri(uri_as_string, mode, transport_params): # pragma: no cover | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
"""A transport that is missing the required SCHEME/SCHEMAS attributes""" | ||
import io | ||
|
||
open = io.open | ||
|
||
|
||
def parse_uri(uri_as_string): # pragma: no cover | ||
... | ||
|
||
|
||
def open_uri(uri_as_string, mode, transport_params): # pragma: no cover | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import unittest | ||
import pytest | ||
|
||
from smart_open import open | ||
|
||
skip_tests = "SMART_OPEN_TEST_MISSING_DEPS" not in os.environ | ||
|
||
|
||
class PackageTests(unittest.TestCase): | ||
|
||
@pytest.mark.skipif(skip_tests, reason="requires missing dependencies") | ||
def test_azure_raises_helpful_error_with_missing_deps(self): | ||
with pytest.raises(ImportError, match=r"pip install smart_open\[azure\]"): | ||
open("azure://foo/bar") | ||
|
||
@pytest.mark.skipif(skip_tests, reason="requires missing dependencies") | ||
def test_aws_raises_helpful_error_with_missing_deps(self): | ||
match = r"pip install smart_open\[s3\]" | ||
with pytest.raises(ImportError, match=match): | ||
open("s3://foo/bar") | ||
# With the DRY errors in transport, this no longer gets a nice error message | ||
with pytest.raises(ImportError): | ||
from smart_open import smart_open | ||
smart_open('fake-name', profile_name="will produce an error importing s3") | ||
|
||
@pytest.mark.skipif(skip_tests, reason="requires missing dependencies") | ||
def test_gcs_raises_helpful_error_with_missing_deps(self): | ||
with pytest.raises(ImportError, match=r"pip install smart_open\[gcs\]"): | ||
open("gs://foo/bar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
import pytest | ||
import unittest | ||
|
||
from smart_open.transport import register_transport, get_transport | ||
|
||
|
||
class TransportTest(unittest.TestCase): | ||
|
||
def test_registry_requires_declared_schemes(self): | ||
with pytest.raises(ValueError): | ||
register_transport('smart_open.tests.fixtures.no_schemes_transport') | ||
|
||
def test_registry_errors_on_double_register_scheme(self): | ||
register_transport('smart_open.tests.fixtures.good_transport') | ||
with pytest.raises(AssertionError): | ||
register_transport('smart_open.tests.fixtures.good_transport') | ||
|
||
def test_registry_errors_get_transport_for_module_with_missing_deps(self): | ||
register_transport('smart_open.tests.fixtures.missing_deps_transport') | ||
with pytest.raises(ImportError): | ||
get_transport("missing") |
Oops, something went wrong.