File tree Expand file tree Collapse file tree 3 files changed +29
-13
lines changed Expand file tree Collapse file tree 3 files changed +29
-13
lines changed Original file line number Diff line number Diff line change 10
10
from eth_utils import (
11
11
to_tuple ,
12
12
)
13
- from ipfshttpclient .exceptions import (
14
- ConnectionError ,
15
- )
16
13
17
14
from ethpm .backends .base import (
18
15
BaseURIBackend ,
30
27
RegistryURIBackend ,
31
28
)
32
29
30
+ try :
31
+ from ipfshttpclient .exceptions import (
32
+ ConnectionError as IpfsConnectionError ,
33
+ )
34
+ except ImportError :
35
+ pass
36
+
33
37
logger = logging .getLogger ("ethpm.utils.backend" )
34
38
39
+ IPFS_NODE_UNAVAILABLE_MSG = "No local IPFS node available on port 5001."
40
+
35
41
ALL_URI_BACKENDS = [
36
42
InfuraIPFSBackend ,
37
43
DummyIPFSBackend ,
@@ -50,8 +56,8 @@ def get_translatable_backends_for_uri(
50
56
try :
51
57
if backend ().can_translate_uri (uri ): # type: ignore
52
58
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 )
55
61
56
62
57
63
@to_tuple
@@ -71,7 +77,5 @@ def get_resolvable_backends_for_uri(
71
77
try :
72
78
if backend_class ().can_resolve_uri (uri ): # type: ignore
73
79
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 )
Original file line number Diff line number Diff line change 9
9
parse ,
10
10
)
11
11
12
- from base58 import (
13
- b58encode ,
14
- )
15
12
from eth_utils import (
16
13
to_text ,
17
14
)
24
21
PBNode ,
25
22
)
26
23
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
+
27
33
28
34
def dummy_ipfs_pin (path : Path ) -> Dict [str , str ]:
29
35
"""
Original file line number Diff line number Diff line change 15
15
import_string ,
16
16
to_bytes ,
17
17
)
18
- import ipfshttpclient
19
18
20
19
from ethpm import (
21
20
get_ethpm_spec_dir ,
39
38
EthPMValidationError ,
40
39
)
41
40
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
+
42
48
43
49
class BaseIPFSBackend (BaseURIBackend ):
44
50
"""
You can’t perform that action at this time.
0 commit comments