Skip to content

Commit 9713c29

Browse files
rayrapetyanpipermerriam
authored andcommitted
Suppress ImportWarning messages (#1419)
* - use uvloop in FreeBSD * Supress ImportWarning messages
1 parent 36ddf16 commit 9713c29

File tree

7 files changed

+54
-29
lines changed

7 files changed

+54
-29
lines changed

eth/_warnings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from contextlib import contextmanager
2+
import warnings
3+
4+
5+
# TODO: drop once https://github.com/cython/cython/issues/1720 is resolved
6+
@contextmanager
7+
def catch_and_ignore_import_warning():
8+
with warnings.catch_warnings():
9+
warnings.simplefilter('ignore', category=ImportWarning)
10+
yield

eth/chains/base.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@
2828
Hash32,
2929
)
3030

31-
from eth_utils import (
32-
to_set,
33-
ValidationError,
34-
)
35-
from eth_utils.toolz import (
36-
assoc,
37-
compose,
38-
groupby,
39-
iterate,
40-
take,
41-
)
42-
4331
from eth.db.backends.base import BaseAtomicDB
4432
from eth.db.chain import (
4533
BaseChainDB,
@@ -103,6 +91,20 @@
10391
AccountState,
10492
)
10593

94+
from eth._warnings import catch_and_ignore_import_warning
95+
with catch_and_ignore_import_warning():
96+
from eth_utils import (
97+
to_set,
98+
ValidationError,
99+
)
100+
from eth_utils.toolz import (
101+
assoc,
102+
compose,
103+
groupby,
104+
iterate,
105+
take,
106+
)
107+
106108
if TYPE_CHECKING:
107109
from eth.vm.base import BaseVM # noqa: F401
108110

eth/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
Address,
33
Hash32
44
)
5-
from eth_utils import denoms
5+
6+
from eth._warnings import catch_and_ignore_import_warning
7+
with catch_and_ignore_import_warning():
8+
from eth_utils import denoms
69

710

811
ANY = 'any'

eth/db/backends/level.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
BaseDB,
1818
)
1919

20+
from eth._warnings import catch_and_ignore_import_warning
21+
2022
if TYPE_CHECKING:
21-
import plyvel # noqa: F401
23+
with catch_and_ignore_import_warning():
24+
import plyvel # noqa: F401
2225

2326

2427
class LevelDB(BaseAtomicDB):
@@ -29,7 +32,8 @@ def __init__(self, db_path: Path = None) -> None:
2932
if not db_path:
3033
raise TypeError("Please specifiy a valid path for your database.")
3134
try:
32-
import plyvel # noqa: F811
35+
with catch_and_ignore_import_warning():
36+
import plyvel # noqa: F811
3337
except ImportError:
3438
raise ImportError(
3539
"LevelDB requires the plyvel library which is not available for import."

eth/db/chain.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,11 @@
1313
TYPE_CHECKING,
1414
)
1515

16-
import rlp
17-
18-
from trie import (
19-
HexaryTrie,
20-
)
21-
2216
from eth_typing import (
2317
BlockNumber,
2418
Hash32
2519
)
2620

27-
from eth_utils import (
28-
to_list,
29-
to_tuple,
30-
ValidationError,
31-
)
32-
3321
from eth_hash.auto import keccak
3422

3523
from eth.constants import (
@@ -57,6 +45,17 @@
5745
from eth.validation import (
5846
validate_word,
5947
)
48+
from eth._warnings import catch_and_ignore_import_warning
49+
with catch_and_ignore_import_warning():
50+
import rlp
51+
from trie import (
52+
HexaryTrie,
53+
)
54+
from eth_utils import (
55+
to_list,
56+
to_tuple,
57+
ValidationError,
58+
)
6059

6160
if TYPE_CHECKING:
6261
from eth.rlp.blocks import ( # noqa: F401

p2p/nat.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
)
1919
import netifaces
2020
from p2p.service import BaseService
21-
import upnpclient
21+
22+
from eth._warnings import catch_and_ignore_import_warning
23+
with catch_and_ignore_import_warning():
24+
import upnpclient
2225

2326

2427
# UPnP discovery can take a long time, so use a loooong timeout here.

trinity/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def is_uvloop_supported() -> bool:
2121
if is_uvloop_supported():
2222
# Set `uvloop` as the default event loop
2323
import asyncio # noqa: E402
24-
import uvloop # noqa: E402
24+
25+
from eth._warnings import catch_and_ignore_import_warning
26+
with catch_and_ignore_import_warning():
27+
import uvloop # noqa: E402
28+
2529
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
2630

2731
from .main import ( # noqa: F401

0 commit comments

Comments
 (0)