-
Notifications
You must be signed in to change notification settings - Fork 1.8k
prevent ethpm
import issues without ipfshttpclient
#2775
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -10,9 +10,6 @@ | |
from eth_utils import ( | ||
to_tuple, | ||
) | ||
from ipfshttpclient.exceptions import ( | ||
ConnectionError, | ||
) | ||
|
||
from ethpm.backends.base import ( | ||
BaseURIBackend, | ||
|
@@ -30,6 +27,12 @@ | |
RegistryURIBackend, | ||
) | ||
|
||
try: | ||
from ipfshttpclient.exceptions import ConnectionError as IpfsConnectionError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was renamed to |
||
except ImportError: | ||
pass | ||
|
||
|
||
logger = logging.getLogger("ethpm.utils.backend") | ||
|
||
ALL_URI_BACKENDS = [ | ||
|
@@ -41,6 +44,19 @@ | |
] | ||
|
||
|
||
def _handle_optional_ipfs_backend_exception(e: Exception) -> None: | ||
try: | ||
# if optional `ipfshttpclient` module is present, catch and debug if | ||
# IpfsConnectionError, else raise original exception. | ||
if isinstance(e, IpfsConnectionError): | ||
logger.debug("No local IPFS node available on port 5001.", exc_info=True) | ||
else: | ||
raise e | ||
except NameError: | ||
# if optional `ipfshttpclient` module is not present, raise original exception | ||
raise e | ||
|
||
|
||
@to_tuple | ||
def get_translatable_backends_for_uri( | ||
uri: URI, | ||
|
@@ -50,8 +66,8 @@ def get_translatable_backends_for_uri( | |
try: | ||
if backend().can_translate_uri(uri): # type: ignore | ||
yield backend | ||
except ConnectionError: | ||
logger.debug("No local IPFS node available on port 5001.", exc_info=True) | ||
except Exception as e: | ||
_handle_optional_ipfs_backend_exception(e) | ||
|
||
|
||
@to_tuple | ||
|
@@ -71,7 +87,5 @@ def get_resolvable_backends_for_uri( | |
try: | ||
if backend_class().can_resolve_uri(uri): # type: ignore | ||
yield backend_class | ||
except ConnectionError: | ||
logger.debug( | ||
"No local IPFS node available on port 5001.", exc_info=True | ||
) | ||
except Exception as e: | ||
_handle_optional_ipfs_backend_exception(e) |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
Fix ``ethpm`` import issues after making ``ipfshttpclient`` optional. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.