Skip to content

Commit 50814a7

Browse files
committed
Show error if example is run without support files. (#2189)
1 parent 5cd3ae5 commit 50814a7

File tree

11 files changed

+101
-12
lines changed

11 files changed

+101
-12
lines changed

examples/client_async.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@
2828
"""
2929
import asyncio
3030
import logging
31+
import sys
3132

32-
import helper
33+
34+
try:
35+
import helper
36+
except ImportError:
37+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
38+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
39+
for more information.")
40+
sys.exit(-1)
3341

3442
import pymodbus.client as modbusClient
3543
from pymodbus import ModbusException

examples/client_async_calls.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@
3131
"""
3232
import asyncio
3333
import logging
34+
import sys
3435

35-
import client_async
3636

37+
try:
38+
import client_async
39+
except ImportError:
40+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
41+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
42+
for more information.")
43+
sys.exit(-1)
3744

3845
_logger = logging.getLogger(__file__)
3946
_logger.setLevel("DEBUG")

examples/client_calls.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@
3030
./server_async.py
3131
"""
3232
import logging
33+
import sys
34+
35+
36+
try:
37+
import client_sync
38+
except ImportError:
39+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
40+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
41+
for more information.")
42+
sys.exit(-1)
3343

34-
import client_sync
3544

3645

3746
_logger = logging.getLogger(__file__)

examples/client_payload.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
Works out of the box together with payload_server.py
88
"""
99
import asyncio
10+
import sys
1011
from collections import OrderedDict
1112

12-
import client_async
13+
14+
try:
15+
import client_async
16+
except ImportError:
17+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
18+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
19+
for more information.")
20+
sys.exit(-1)
1321

1422
from pymodbus.constants import Endian
1523
from pymodbus.payload import BinaryPayloadBuilder, BinaryPayloadDecoder

examples/client_sync.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@
3131
3232
"""
3333
import logging
34+
import sys
3435

35-
import helper
36+
37+
try:
38+
import helper
39+
except ImportError:
40+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
41+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
42+
for more information.")
43+
sys.exit(-1)
3644

3745
import pymodbus.client as modbusClient
3846
from pymodbus import ModbusException

examples/modbus_forwarder.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
"""
1919
import asyncio
2020
import logging
21+
import sys
2122

22-
import helper
23+
24+
try:
25+
import helper
26+
except ImportError:
27+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
28+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
29+
for more information.")
30+
sys.exit(-1)
2331

2432
from pymodbus.client import ModbusTcpClient
2533
from pymodbus.datastore import ModbusServerContext

examples/server_async.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@
3434
"""
3535
import asyncio
3636
import logging
37+
import sys
3738

38-
import helper
39+
40+
try:
41+
import helper
42+
except ImportError:
43+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
44+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
45+
for more information.")
46+
sys.exit(-1)
3947

4048
from pymodbus import __version__ as pymodbus_version
4149
from pymodbus.datastore import (

examples/server_callback.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
"""
77
import asyncio
88
import logging
9+
import sys
910

10-
import server_async
11+
12+
try:
13+
import server_async
14+
except ImportError:
15+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
16+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
17+
for more information.")
18+
sys.exit(-1)
1119

1220
from pymodbus.datastore import (
1321
ModbusSequentialDataBlock,

examples/server_payload.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
"""
77
import asyncio
88
import logging
9+
import sys
10+
11+
12+
try:
13+
import server_async
14+
except ImportError:
15+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
16+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
17+
for more information.")
18+
sys.exit(-1)
919

10-
import server_async
1120

1221
from pymodbus.constants import Endian
1322
from pymodbus.datastore import (

examples/server_sync.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@
3535
a lot slower.
3636
"""
3737
import logging
38+
import sys
3839

39-
import helper
40-
import server_async
40+
41+
try:
42+
import helper
43+
import server_async
44+
except ImportError:
45+
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
46+
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
47+
for more information.")
48+
sys.exit(-1)
4149

4250
# --------------------------------------------------------------------------- #
4351
# import the various client implementations

0 commit comments

Comments
 (0)