Skip to content

Commit

Permalink
Merge branch 'release/1.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
SkypLabs committed Apr 27, 2023
2 parents aef5354 + c7c4eaf commit af9eb32
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 209 deletions.
117 changes: 61 additions & 56 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
name: Test code
runs-on: ${{ matrix.os }}
needs: is-duplicate
if: ${{ needs.is-duplicate.outputs.should_skip != 'true' }}
if: needs.is-duplicate.outputs.should_skip != 'true'
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
Expand All @@ -52,65 +52,80 @@ jobs:
- name: Test with Tox
run: tox

test-dist:
name: Test distribution
runs-on: ubuntu-latest
build-wheels:
name: Build wheels
runs-on: ${{ matrix.os }}
needs: is-duplicate
if: ${{ needs.is-duplicate.outputs.should_skip != 'true' }}
if: |
needs.is-duplicate.outputs.should_skip != 'true' &&
startsWith(github.ref, 'refs/heads/develop')
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: Check out code
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Python
uses: actions/[email protected]
- name: Build wheels
uses: pypa/[email protected]

- name: Upload artefacts to GitHub
uses: actions/upload-artifact@v3
with:
python-version: '3.x'
name: dist-packages
path: wheelhouse/*.whl

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade build twine
build-sdist:
name: Build source distribution
runs-on: ubuntu-latest
needs: is-duplicate
if: |
needs.is-duplicate.outputs.should_skip != 'true' &&
startsWith(github.ref, 'refs/heads/develop')
steps:
- name: Check out code
uses: actions/checkout@v3
with:
submodules: recursive

- name: Build and test with Twine
- name: Build sdist
run: |
python -m build
twine check dist/*
pipx run build --sdist
pipx run twine check dist/*
- name: Upload artefacts to GitHub
uses: actions/upload-artifact@v3
with:
name: dist-packages
path: dist/*.tar.gz

publish-to-test-pypi:
name: Publish to TestPyPI
environment: staging
runs-on: ubuntu-latest
needs: [test-code]
needs: [test-code, build-sdist, build-wheels]
if: |
!failure() &&
startsWith(github.ref, 'refs/tags/')
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Download artefacts
uses: actions/download-artifact@v3
with:
submodules: recursive
name: dist-packages
path: dist

- name: Set up Python
uses: actions/[email protected]
- name: Publish to TestPyPI
uses: pypa/[email protected]
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade build twine
- name: Build and publish
env:
TWINE_USERNAME: '__token__'
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload --repository testpypi dist/*
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.PYPI_API_TOKEN }}
print-hash: true

publish-to-pypi:
name: Publish to PyPI
Expand All @@ -119,28 +134,18 @@ jobs:
needs: [publish-to-test-pypi]
if: |
!failure() &&
startsWith(github.ref, 'refs/tags/')
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Download artefacts
uses: actions/download-artifact@v3
with:
submodules: recursive
name: dist-packages
path: dist

- name: Set up Python
uses: actions/[email protected]
- name: Publish to test PyPI
uses: pypa/[email protected]
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade build twine
- name: Build and publish
env:
TWINE_USERNAME: '__token__'
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*
password: ${{ secrets.PYPI_API_TOKEN }}
print-hash: true
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 38b88246ccc552bffaaf54259d064beeee434539 # frozen: v4.0.1
rev: f71fa2c1f9cf5cb705f73dffe4b21f7c61470ba9 # frozen: v4.4.0
hooks:
- id: check-ast
- id: check-executables-have-shebangs
- id: check-yaml
- id: trailing-whitespace
- repo: https://github.com/PyCQA/flake8
rev: dcd740bc0ebaf2b3d43e59a0060d157c97de13f3 # frozen: 3.9.2

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 343c49ab887fa4e5724ceb86c9c3678e647c94c2 # frozen: v0.0.262
hooks:
- id: flake8
- repo: https://github.com/PyCQA/pylint
rev: 591a23adcfdd2fe20b8cfdb9e4e07772c8f454f8 # frozen: v2.10.2
- id: ruff

- repo: https://github.com/psf/black
rev: bf7a16254ec96b084a6caf3d435ec18f0f245cc7 # frozen: 23.3.0
hooks:
- id: pylint
- id: black
26 changes: 12 additions & 14 deletions examples/fsm_endpoint_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@
pip install python4yahdlc[examples]
To create a virtual serial bus, you can use socat as followed:
To create a virtual serial bus, you can use socat as follows:
::
socat -d -d pty,raw,echo=0 pty,raw,echo=0
Then, edit `ser.port` variable as needed.
Then, edit `ser.port` accordingly.
"""

# pylint: disable=invalid-name

import signal
from sys import exit as sys_exit
from sys import stderr
from time import sleep

import serial
from fysom import Fysom

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

# Serial port configuration.
# -------------------------------------------------- #
# Serial port configuration
# -------------------------------------------------- #
ser = serial.Serial()
ser.port = "/dev/pts/5"
ser.baudrate = 9600
Expand All @@ -54,7 +52,7 @@ def serial_connection(e):
e.fsm.connection_ko()


def retry_serial_connection():
def retry_serial_connection(e):
"""
Retry serial connection state.
Expand Down Expand Up @@ -90,20 +88,21 @@ def timeout_handler(signum, frame):
print("[*] Waiting for (N)ACK...")

signal.signal(signal.SIGALRM, timeout_handler)
# 1-second timeout
# 1-second timeout.
signal.alarm(1)

while True:
try:
# 200 µs
# 200 µs.
sleep(200 / 1000000.0)
_, ftype, seq_no = get_data(ser.read(ser.inWaiting()))
_, ftype, seq_no = get_data(ser.read(ser.in_waiting))
signal.alarm(0)
break
except MessageError:
# No HDLC frame detected.
pass
except TimeoutError as err:
stderr.write("[x] " + str(err) + "\n")
stderr.write(f"[x] {str(err)}\n")
e.fsm.timeout()

if ftype not in (FRAME_ACK, FRAME_NACK):
Expand Down Expand Up @@ -140,7 +139,7 @@ def pause(e):

if __name__ == "__main__":
try:
fsm = Fysom(
Fysom(
{
"initial": "init",
"events": [
Expand Down Expand Up @@ -169,6 +168,5 @@ def pause(e):
)
except KeyboardInterrupt:
print("[*] Bye!")
sys_exit(0)
finally:
ser.close()
18 changes: 8 additions & 10 deletions examples/fsm_endpoint_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@
pip install python4yahdlc[examples]
To create a virtual serial bus, you can use socat as followed:
To create a virtual serial bus, you can use socat as follows:
::
socat -d -d pty,raw,echo=0 pty,raw,echo=0
Then, edit `ser.port` variable as needed.
Then, edit `ser.port` accordingly.
"""

# pylint: disable=invalid-name

from sys import exit as sys_exit
from sys import stderr
from time import sleep

import serial
from fysom import Fysom

# pylint: disable=no-name-in-module
from yahdlc import (
FRAME_ACK,
FRAME_DATA,
Expand All @@ -37,7 +33,9 @@
get_data,
)

# -------------------------------------------------- #
# Serial port configuration
# -------------------------------------------------- #
ser = serial.Serial()
ser.port = "/dev/pts/6"
ser.baudrate = 9600
Expand All @@ -61,7 +59,7 @@ def serial_connection(e):
e.fsm.connection_ko()


def retry_serial_connection():
def retry_serial_connection(e):
"""
Retry serial connection state.
Expand All @@ -83,9 +81,10 @@ def wait_for_data(e):

while True:
try:
_, ftype, seq_no = get_data(ser.read(ser.inWaiting()))
_, ftype, seq_no = get_data(ser.read(ser.in_waiting))
break
except MessageError:
# No HDLC frame detected.
pass
except FCSError:
stderr.write("[x] Bad FCS\n")
Expand Down Expand Up @@ -127,7 +126,7 @@ def send_nack_frame(e):

if __name__ == "__main__":
try:
fsm = Fysom(
Fysom(
{
"initial": "init",
"events": [
Expand All @@ -152,6 +151,5 @@ def send_nack_frame(e):
)
except KeyboardInterrupt:
print("[*] Bye!")
sys_exit(0)
finally:
ser.close()
Loading

0 comments on commit af9eb32

Please sign in to comment.