Skip to content

Commit cf91a19

Browse files
committed
- #2774: prevent ethpm import issues w/o optional ipfshttpclient dependency
1 parent d786101 commit cf91a19

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

ethpm/_utils/backend.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
from eth_utils import (
1111
to_tuple,
1212
)
13-
from ipfshttpclient.exceptions import (
14-
ConnectionError,
15-
)
1613

1714
from ethpm.backends.base import (
1815
BaseURIBackend,
@@ -30,8 +27,17 @@
3027
RegistryURIBackend,
3128
)
3229

30+
try:
31+
from ipfshttpclient.exceptions import (
32+
ConnectionError as IpfsConnectionError,
33+
)
34+
except ImportError:
35+
pass
36+
3337
logger = logging.getLogger("ethpm.utils.backend")
3438

39+
IPFS_NODE_UNAVAILABLE_MSG = "No local IPFS node available on port 5001."
40+
3541
ALL_URI_BACKENDS = [
3642
InfuraIPFSBackend,
3743
DummyIPFSBackend,
@@ -50,8 +56,8 @@ def get_translatable_backends_for_uri(
5056
try:
5157
if backend().can_translate_uri(uri): # type: ignore
5258
yield backend
53-
except ConnectionError:
54-
logger.debug("No local IPFS node available on port 5001.", exc_info=True)
59+
except IpfsConnectionError:
60+
logger.debug(IPFS_NODE_UNAVAILABLE_MSG, exc_info=True)
5561

5662

5763
@to_tuple
@@ -71,7 +77,5 @@ def get_resolvable_backends_for_uri(
7177
try:
7278
if backend_class().can_resolve_uri(uri): # type: ignore
7379
yield backend_class
74-
except ConnectionError:
75-
logger.debug(
76-
"No local IPFS node available on port 5001.", exc_info=True
77-
)
80+
except IpfsConnectionError:
81+
logger.debug(IPFS_NODE_UNAVAILABLE_MSG, exc_info=True)

ethpm/_utils/ipfs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
parse,
1010
)
1111

12-
from base58 import (
13-
b58encode,
14-
)
1512
from eth_utils import (
1613
to_text,
1714
)
@@ -24,6 +21,15 @@
2421
PBNode,
2522
)
2623

24+
try:
25+
# `ipfshttpclient` backend is optional. This is only imported if the "web3[ipfs]"
26+
# install extra is installed
27+
from base58 import (
28+
b58encode,
29+
)
30+
except ImportError:
31+
pass
32+
2733

2834
def dummy_ipfs_pin(path: Path) -> Dict[str, str]:
2935
"""

ethpm/backends/ipfs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import_string,
1616
to_bytes,
1717
)
18-
import ipfshttpclient
1918

2019
from ethpm import (
2120
get_ethpm_spec_dir,
@@ -39,6 +38,13 @@
3938
EthPMValidationError,
4039
)
4140

41+
try:
42+
# `ipfshttpclient` backend is optional. This is only imported if the "web3[ipfs]"
43+
# install extra is installed
44+
import ipfshttpclient
45+
except ImportError:
46+
pass
47+
4248

4349
class BaseIPFSBackend(BaseURIBackend):
4450
"""

0 commit comments

Comments
 (0)