Skip to content

Commit af9eb32

Browse files
committed
Merge branch 'release/1.3.4'
2 parents aef5354 + c7c4eaf commit af9eb32

9 files changed

Lines changed: 218 additions & 209 deletions

File tree

.github/workflows/test_and_publish.yml

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
name: Test code
2828
runs-on: ${{ matrix.os }}
2929
needs: is-duplicate
30-
if: ${{ needs.is-duplicate.outputs.should_skip != 'true' }}
30+
if: needs.is-duplicate.outputs.should_skip != 'true'
3131
strategy:
3232
matrix:
3333
os: [ubuntu-latest, macos-latest, windows-latest]
@@ -52,65 +52,80 @@ jobs:
5252
- name: Test with Tox
5353
run: tox
5454

55-
test-dist:
56-
name: Test distribution
57-
runs-on: ubuntu-latest
55+
build-wheels:
56+
name: Build wheels
57+
runs-on: ${{ matrix.os }}
5858
needs: is-duplicate
59-
if: ${{ needs.is-duplicate.outputs.should_skip != 'true' }}
59+
if: |
60+
needs.is-duplicate.outputs.should_skip != 'true' &&
61+
startsWith(github.ref, 'refs/heads/develop')
62+
strategy:
63+
matrix:
64+
os: [ubuntu-latest, macos-latest, windows-latest]
6065

6166
steps:
6267
- name: Check out code
6368
uses: actions/checkout@v3
6469
with:
6570
submodules: recursive
6671

67-
- name: Set up Python
68-
uses: actions/setup-python@v4.5.0
72+
- name: Build wheels
73+
uses: pypa/cibuildwheel@v2.12.3
74+
75+
- name: Upload artefacts to GitHub
76+
uses: actions/upload-artifact@v3
6977
with:
70-
python-version: '3.x'
78+
name: dist-packages
79+
path: wheelhouse/*.whl
7180

72-
- name: Install dependencies
73-
run: |
74-
python -m pip install --upgrade pip
75-
pip install --upgrade build twine
81+
build-sdist:
82+
name: Build source distribution
83+
runs-on: ubuntu-latest
84+
needs: is-duplicate
85+
if: |
86+
needs.is-duplicate.outputs.should_skip != 'true' &&
87+
startsWith(github.ref, 'refs/heads/develop')
88+
89+
steps:
90+
- name: Check out code
91+
uses: actions/checkout@v3
92+
with:
93+
submodules: recursive
7694

77-
- name: Build and test with Twine
95+
- name: Build sdist
7896
run: |
79-
python -m build
80-
twine check dist/*
97+
pipx run build --sdist
98+
pipx run twine check dist/*
99+
100+
- name: Upload artefacts to GitHub
101+
uses: actions/upload-artifact@v3
102+
with:
103+
name: dist-packages
104+
path: dist/*.tar.gz
81105

82106
publish-to-test-pypi:
83107
name: Publish to TestPyPI
84108
environment: staging
85109
runs-on: ubuntu-latest
86-
needs: [test-code]
110+
needs: [test-code, build-sdist, build-wheels]
87111
if: |
88112
!failure() &&
89-
startsWith(github.ref, 'refs/tags/')
113+
github.event_name == 'push' &&
114+
startsWith(github.ref, 'refs/tags/v')
90115
91116
steps:
92-
- name: Check out code
93-
uses: actions/checkout@v3
117+
- name: Download artefacts
118+
uses: actions/download-artifact@v3
94119
with:
95-
submodules: recursive
120+
name: dist-packages
121+
path: dist
96122

97-
- name: Set up Python
98-
uses: actions/setup-python@v4.5.0
123+
- name: Publish to TestPyPI
124+
uses: pypa/gh-action-pypi-publish@v1.8.5
99125
with:
100-
python-version: '3.x'
101-
102-
- name: Install dependencies
103-
run: |
104-
python -m pip install --upgrade pip
105-
pip install --upgrade build twine
106-
107-
- name: Build and publish
108-
env:
109-
TWINE_USERNAME: '__token__'
110-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
111-
run: |
112-
python -m build
113-
twine upload --repository testpypi dist/*
126+
repository-url: https://test.pypi.org/legacy/
127+
password: ${{ secrets.PYPI_API_TOKEN }}
128+
print-hash: true
114129

115130
publish-to-pypi:
116131
name: Publish to PyPI
@@ -119,28 +134,18 @@ jobs:
119134
needs: [publish-to-test-pypi]
120135
if: |
121136
!failure() &&
122-
startsWith(github.ref, 'refs/tags/')
137+
github.event_name == 'push' &&
138+
startsWith(github.ref, 'refs/tags/v')
123139
124140
steps:
125-
- name: Check out code
126-
uses: actions/checkout@v3
141+
- name: Download artefacts
142+
uses: actions/download-artifact@v3
127143
with:
128-
submodules: recursive
144+
name: dist-packages
145+
path: dist
129146

130-
- name: Set up Python
131-
uses: actions/setup-python@v4.5.0
147+
- name: Publish to test PyPI
148+
uses: pypa/gh-action-pypi-publish@v1.8.5
132149
with:
133-
python-version: '3.x'
134-
135-
- name: Install dependencies
136-
run: |
137-
python -m pip install --upgrade pip
138-
pip install --upgrade build twine
139-
140-
- name: Build and publish
141-
env:
142-
TWINE_USERNAME: '__token__'
143-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
144-
run: |
145-
python -m build
146-
twine upload dist/*
150+
password: ${{ secrets.PYPI_API_TOKEN }}
151+
print-hash: true

.pre-commit-config.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: 38b88246ccc552bffaaf54259d064beeee434539 # frozen: v4.0.1
3+
rev: f71fa2c1f9cf5cb705f73dffe4b21f7c61470ba9 # frozen: v4.4.0
44
hooks:
55
- id: check-ast
6-
- id: check-executables-have-shebangs
76
- id: check-yaml
87
- id: trailing-whitespace
9-
- repo: https://github.com/PyCQA/flake8
10-
rev: dcd740bc0ebaf2b3d43e59a0060d157c97de13f3 # frozen: 3.9.2
8+
9+
- repo: https://github.com/charliermarsh/ruff-pre-commit
10+
rev: 343c49ab887fa4e5724ceb86c9c3678e647c94c2 # frozen: v0.0.262
1111
hooks:
12-
- id: flake8
13-
- repo: https://github.com/PyCQA/pylint
14-
rev: 591a23adcfdd2fe20b8cfdb9e4e07772c8f454f8 # frozen: v2.10.2
12+
- id: ruff
13+
14+
- repo: https://github.com/psf/black
15+
rev: bf7a16254ec96b084a6caf3d435ec18f0f245cc7 # frozen: 23.3.0
1516
hooks:
16-
- id: pylint
17+
- id: black

examples/fsm_endpoint_1.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@
88
99
pip install python4yahdlc[examples]
1010
11-
To create a virtual serial bus, you can use socat as followed:
11+
To create a virtual serial bus, you can use socat as follows:
1212
1313
::
1414
1515
socat -d -d pty,raw,echo=0 pty,raw,echo=0
1616
17-
Then, edit `ser.port` variable as needed.
17+
Then, edit `ser.port` accordingly.
1818
"""
1919

20-
# pylint: disable=invalid-name
21-
2220
import signal
23-
from sys import exit as sys_exit
2421
from sys import stderr
2522
from time import sleep
2623

2724
import serial
2825
from fysom import Fysom
2926

30-
# pylint: disable=no-name-in-module
3127
from yahdlc import FRAME_ACK, FRAME_DATA, FRAME_NACK, MessageError, frame_data, get_data
3228

33-
# Serial port configuration.
29+
# -------------------------------------------------- #
30+
# Serial port configuration
31+
# -------------------------------------------------- #
3432
ser = serial.Serial()
3533
ser.port = "/dev/pts/5"
3634
ser.baudrate = 9600
@@ -54,7 +52,7 @@ def serial_connection(e):
5452
e.fsm.connection_ko()
5553

5654

57-
def retry_serial_connection():
55+
def retry_serial_connection(e):
5856
"""
5957
Retry serial connection state.
6058
@@ -90,20 +88,21 @@ def timeout_handler(signum, frame):
9088
print("[*] Waiting for (N)ACK...")
9189

9290
signal.signal(signal.SIGALRM, timeout_handler)
93-
# 1-second timeout
91+
# 1-second timeout.
9492
signal.alarm(1)
9593

9694
while True:
9795
try:
98-
# 200 µs
96+
# 200 µs.
9997
sleep(200 / 1000000.0)
100-
_, ftype, seq_no = get_data(ser.read(ser.inWaiting()))
98+
_, ftype, seq_no = get_data(ser.read(ser.in_waiting))
10199
signal.alarm(0)
102100
break
103101
except MessageError:
102+
# No HDLC frame detected.
104103
pass
105104
except TimeoutError as err:
106-
stderr.write("[x] " + str(err) + "\n")
105+
stderr.write(f"[x] {str(err)}\n")
107106
e.fsm.timeout()
108107

109108
if ftype not in (FRAME_ACK, FRAME_NACK):
@@ -140,7 +139,7 @@ def pause(e):
140139

141140
if __name__ == "__main__":
142141
try:
143-
fsm = Fysom(
142+
Fysom(
144143
{
145144
"initial": "init",
146145
"events": [
@@ -169,6 +168,5 @@ def pause(e):
169168
)
170169
except KeyboardInterrupt:
171170
print("[*] Bye!")
172-
sys_exit(0)
173171
finally:
174172
ser.close()

examples/fsm_endpoint_2.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@
88
99
pip install python4yahdlc[examples]
1010
11-
To create a virtual serial bus, you can use socat as followed:
11+
To create a virtual serial bus, you can use socat as follows:
1212
1313
::
1414
1515
socat -d -d pty,raw,echo=0 pty,raw,echo=0
1616
17-
Then, edit `ser.port` variable as needed.
17+
Then, edit `ser.port` accordingly.
1818
"""
1919

20-
# pylint: disable=invalid-name
21-
22-
from sys import exit as sys_exit
2320
from sys import stderr
2421
from time import sleep
2522

2623
import serial
2724
from fysom import Fysom
2825

29-
# pylint: disable=no-name-in-module
3026
from yahdlc import (
3127
FRAME_ACK,
3228
FRAME_DATA,
@@ -37,7 +33,9 @@
3733
get_data,
3834
)
3935

36+
# -------------------------------------------------- #
4037
# Serial port configuration
38+
# -------------------------------------------------- #
4139
ser = serial.Serial()
4240
ser.port = "/dev/pts/6"
4341
ser.baudrate = 9600
@@ -61,7 +59,7 @@ def serial_connection(e):
6159
e.fsm.connection_ko()
6260

6361

64-
def retry_serial_connection():
62+
def retry_serial_connection(e):
6563
"""
6664
Retry serial connection state.
6765
@@ -83,9 +81,10 @@ def wait_for_data(e):
8381

8482
while True:
8583
try:
86-
_, ftype, seq_no = get_data(ser.read(ser.inWaiting()))
84+
_, ftype, seq_no = get_data(ser.read(ser.in_waiting))
8785
break
8886
except MessageError:
87+
# No HDLC frame detected.
8988
pass
9089
except FCSError:
9190
stderr.write("[x] Bad FCS\n")
@@ -127,7 +126,7 @@ def send_nack_frame(e):
127126

128127
if __name__ == "__main__":
129128
try:
130-
fsm = Fysom(
129+
Fysom(
131130
{
132131
"initial": "init",
133132
"events": [
@@ -152,6 +151,5 @@ def send_nack_frame(e):
152151
)
153152
except KeyboardInterrupt:
154153
print("[*] Bye!")
155-
sys_exit(0)
156154
finally:
157155
ser.close()

0 commit comments

Comments
 (0)