Skip to content

Commit e88505d

Browse files
authored
updated CI. (#1234)
1 parent 35679e2 commit e88505d

File tree

11 files changed

+628
-91
lines changed

11 files changed

+628
-91
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
name: CI
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
run_lint:
7-
description: 'Run lint'
8-
required: false
9-
default: true
10-
type: boolean
11-
run_test:
12-
description: 'Run test'
13-
required: false
14-
default: true
15-
type: boolean
164
push:
175
branches:
186
- dev
@@ -23,8 +11,9 @@ on:
2311
branches:
2412
- dev
2513
schedule:
26-
# Daily at 02:10 UTC.
27-
- cron: '10 2 * * *'
14+
# Sunday at 02:10 UTC.
15+
- cron: '10 2 * * 0'
16+
workflow_dispatch:
2817

2918

3019
jobs:
@@ -37,68 +26,65 @@ jobs:
3726
matrix:
3827
task:
3928
- name: pylint
40-
type: lint
4129
cmd: pylint --recursive=y examples pymodbus test
42-
- name: codespell
4330
type: lint
31+
- name: codespell
4432
cmd: codespell
45-
- name: bandit
4633
type: lint
34+
- name: bandit
4735
cmd: bandit -r -c bandit.yaml .
48-
- name: flake8
4936
type: lint
37+
- name: flake8
5038
cmd: flake8
51-
- name: isort
5239
type: lint
40+
- name: isort
5341
cmd: isort --check .
54-
- name: black
5542
type: lint
43+
- name: black
5644
cmd: black --check --safe --quiet examples/ pymodbus/ test/
57-
- name: docs
5845
type: lint
46+
- name: docs
5947
cmd: make -C doc/ html
48+
type: lint
6049
- name: pytest
61-
type: test
6250
cmd: pytest --cov=pymodbus --cov=test --cov-report=term-missing --cov-report=xml -v --full-trace --timeout=20
51+
type: test
6352
os:
64-
- on: ubuntu-latest
65-
activate: '. venv/bin/activate'
66-
- on: macos-latest
67-
activate: '. venv/bin/activate'
68-
no-lint: 'yes'
69-
- on: windows-latest
70-
activate: 'venv/Scripts/activate'
71-
no-lint: 'yes'
53+
- name: Linux
54+
on: ubuntu-latest
55+
lint: 'yes'
56+
- name: Macos
57+
on: macos-latest
58+
lint: 'no'
59+
- name: Windows
60+
on: windows-latest
61+
lint: 'no'
7262
python:
7363
- version: '3.8'
74-
no-lint: 'no'
64+
lint: 'yes'
7565
- version: '3.9'
76-
no-lint: 'yes'
66+
lint: 'no'
7767
- version: '3.10'
78-
no-lint: 'yes'
68+
lint: 'no'
7969
- version: pypy-3.8
80-
implementation: pypy
81-
no-lint: 'yes'
82-
- version: pypy-3.9
83-
implementation: pypy
84-
no-lint: 'yes'
70+
lint: 'no'
8571
exclude:
8672
- task:
8773
type: lint
8874
os:
89-
no-lint: 'yes'
75+
lint: 'no'
9076
- task:
9177
type: lint
9278
python:
93-
no-lint: 'yes'
79+
lint: 'no'
9480
- os:
95-
on: macos-latest
81+
name: Macos
9682
python:
97-
implementation: pypy
83+
version: pypy-3.8
9884
- os:
99-
on: windows-latest
85+
name: Windows
10086
python:
101-
implementation: pypy
87+
version: pypy-3.8
10288
steps:
10389
- name: Checkout repository
10490
uses: actions/checkout@v3
@@ -110,36 +96,13 @@ jobs:
11096

11197
- name: venv restore
11298
id: cache-venv
113-
uses: actions/cache@v3
99+
uses: syphar/restore-virtualenv@v1
114100
with:
115-
path: venv
116-
key: "venv_${{ matrix.os.on }}_${{ matrix.python.version }}_${{ hashFiles('requirements.txt') }}"
101+
requirement_files: requirements.txt
117102

118103
- name: venv create
119-
if: ${{ steps.cache-venv.outputs.cache-hit != 'true' }}
120-
run: |
121-
python -m venv venv
122-
${{ matrix.os.activate }}
123-
pip install -e . -r requirements.txt
124-
125-
- name: test
126-
if: ${{ matrix.task.type == 'test' && inputs.run_test }}
127-
run: |
128-
${{ matrix.os.activate }}
129-
${{ matrix.task.cmd }}
104+
if: steps.cache-venv.outputs.cache-hit != 'true'
105+
run: pip install -e . -r requirements.txt
130106

131-
- name: lint
132-
if: ${{ matrix.task.type == 'lint' && inputs.run_lint }}
133-
run: |
134-
${{ matrix.os.activate }}
135-
${{ matrix.task.cmd }}
136-
137-
all:
138-
name: All
139-
runs-on: ubuntu-latest
140-
needs:
141-
- integreation_test
142-
steps:
143-
- name: This
144-
run: |
145-
ls -l
107+
- name: test/lint
108+
run: ${{ matrix.task.cmd }}

.github/workflows/clean_workflow_runs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
required: false
1212
default: 6
1313
schedule:
14-
# Daily at 02:35 UTC.
15-
- cron: '35 2 * * *'
14+
# Sunday at 02:35 UTC.
15+
- cron: '35 2 * * 0'
1616

1717
jobs:
1818
del_runs:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ build/
2222
/doc/_build/
2323
/dist/
2424
/pymodbus.egg-info/
25-
/venv/
25+
venv

pymodbus/client/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ async def close(self): # pylint: disable=invalid-overridden-method
315315
"""Close connection."""
316316
if self.transport:
317317
self.transport.close()
318+
while self.transport is not None:
319+
await asyncio.sleep(0.1)
318320
self._connected = False
319321

320322
def connection_lost(self, reason):

pymodbus/client/serial.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
try:
1616
import serial
17+
1718
from serial_asyncio import create_serial_connection
1819
except ImportError:
1920
pass
@@ -76,8 +77,15 @@ def __init__(
7677

7778
async def close(self): # pylint: disable=invalid-overridden-method
7879
"""Stop connection."""
79-
if self.connected and self.protocol and self.protocol.transport:
80-
self.protocol.transport.close()
80+
81+
# prevent reconnect:
82+
self.delay_ms = 0
83+
if self.connected:
84+
if self.protocol.transport:
85+
self.protocol.transport.close()
86+
if self.protocol:
87+
await self.protocol.close()
88+
await asyncio.sleep(0.1)
8189

8290
def _create_protocol(self):
8391
"""Create protocol."""
@@ -132,7 +140,9 @@ def protocol_lost_connection(self, protocol):
132140
_logger.error("Serial: protocol is not self.protocol.")
133141

134142
self._connected_event.clear()
135-
self.protocol = None
143+
if self.protocol is not None:
144+
del self.protocol
145+
self.protocol = None
136146
# if self.host:
137147
# asyncio.asynchronous(self._reconnect())
138148
else:

pymodbus/client/tcp.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ async def connect(self): # pylint: disable=invalid-overridden-method
6868
async def close(self): # pylint: disable=invalid-overridden-method
6969
"""Stop client."""
7070

71-
# prevent reconnect.
71+
# prevent reconnect:
7272
self.delay_ms = 0
73-
74-
if self.connected and self.protocol and self.protocol.transport:
75-
self.protocol.transport.close()
73+
if self.connected:
74+
if self.protocol.transport:
75+
self.protocol.transport.close()
76+
if self.protocol:
77+
await self.protocol.close()
78+
await asyncio.sleep(0.1)
7679

7780
def _create_protocol(self):
7881
"""Create initialized protocol instance with factory function."""
@@ -130,7 +133,9 @@ def protocol_lost_connection(self, protocol):
130133
)
131134

132135
self.connected = False
133-
self.protocol = None
136+
if self.protocol is not None:
137+
del self.protocol
138+
self.protocol = None
134139
if self.delay_ms > 0:
135140
asyncio.ensure_future(self._reconnect())
136141

pymodbus/client/udp.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ async def close(self): # pylint: disable=invalid-overridden-method
8989
"""
9090
# prevent reconnect:
9191
self.delay_ms = 0
92-
93-
if self.connected and self.protocol and self.protocol.transport:
94-
self.protocol.transport.close()
92+
if self.connected:
93+
if self.protocol.transport:
94+
self.protocol.transport.close()
95+
if self.protocol:
96+
await self.protocol.close()
97+
await asyncio.sleep(0.1)
9598

9699
def _create_protocol(self, host=None, port=0):
97100
"""Create initialized protocol instance with factory function."""
@@ -157,7 +160,9 @@ def protocol_lost_connection(self, protocol):
157160
)
158161

159162
self.connected = False
160-
self.protocol = None
163+
if self.protocol is not None:
164+
del self.protocol
165+
self.protocol = None
161166
if self.delay_ms > 0:
162167
asyncio.create_task(self._reconnect())
163168
else:
@@ -201,7 +206,7 @@ def __init__(
201206
source_address: typing.Tuple[str, int] = None,
202207
**kwargs: any,
203208
) -> None:
204-
"""Initialize Asyncio Modbus UDP Client."""
209+
"""Initialize Modbus UDP Client."""
205210
super().__init__(framer=framer, **kwargs)
206211
self.params.host = host
207212
self.params.port = port

pymodbus/server/async_io.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
try:
2727
import serial
28+
2829
from serial_asyncio import create_serial_connection
2930
except ImportError:
3031
pass

0 commit comments

Comments
 (0)