Skip to content

Commit f51e4a0

Browse files
committed
Consistent ImportError messages
1 parent 86e2c67 commit f51e4a0

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

pymodbus/client/serial.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Modbus client async serial communication."""
22
import asyncio
33
import time
4-
from contextlib import suppress
54
from functools import partial
65
from typing import Any, Type
76

@@ -14,8 +13,13 @@
1413
from pymodbus.utilities import ModbusTransactionState
1514

1615

17-
with suppress(ImportError):
16+
try:
1817
import serial
18+
except ImportError:
19+
raise ImportError(
20+
"Serial client requires pyserial"
21+
'Please install with "pip install pyserial" and try again.'
22+
)
1923

2024

2125
class AsyncModbusSerialClient(ModbusBaseClient, asyncio.Protocol):

pymodbus/server/async_io.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
from pymodbus.transport import CommParams, CommType, ModbusProtocol
2424

2525

26-
with suppress(ImportError):
27-
pass
28-
29-
3026
# --------------------------------------------------------------------------- #
3127
# Protocol Handlers
3228
# --------------------------------------------------------------------------- #

pymodbus/server/reactive/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
try:
1616
from aiohttp import web
1717
except ImportError:
18-
print(
18+
raise ImportError(
1919
"Reactive server requires aiohttp. "
2020
'Please install with "pip install aiohttp" and try again.'
2121
)
22-
sys.exit(1)
2322

2423
from pymodbus import __version__ as pymodbus_version
2524
from pymodbus.datastore import ModbusServerContext, ModbusSlaveContext

pymodbus/server/simulator/http_server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
from typing import List
1010

1111

12-
with contextlib.suppress(ImportError):
12+
try:
1313
from aiohttp import web
14+
except ImportError:
15+
raise ImportError(
16+
"Simulator server requires aiohttp. "
17+
'Please install with "pip install aiohttp" and try again.'
18+
)
1419

1520
from pymodbus.datastore import ModbusServerContext, ModbusSimulatorContext
1621
from pymodbus.datastore.simulator import Label
@@ -124,8 +129,6 @@ def __init__(
124129
custom_actions_module: str = None,
125130
):
126131
"""Initialize http interface."""
127-
if not web:
128-
raise RuntimeError("aiohttp not installed!")
129132
with open(json_file, encoding="utf-8") as file:
130133
setup = json.load(file)
131134

0 commit comments

Comments
 (0)