ci: update workflow for python

This commit is contained in:
l5y
2025-09-13 11:34:18 +02:00
parent 987e166d54
commit f1f0075b65
3 changed files with 45 additions and 43 deletions
-39
View File
@@ -1,39 +0,0 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
+31
View File
@@ -0,0 +1,31 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python 3
uses: actions/setup-python@v3
- name: Install dependencies
run: |
python -m venv .venv && source .venv/bin/activate
pip install meshtastic black pytest
- name: Lint with black
run: |
black --check ./data
- name: Test with pytest
run: |
pytest
+14 -4
View File
@@ -16,6 +16,7 @@ conn = sqlite3.connect(DB, check_same_thread=False)
conn.executescript(schema)
conn.commit()
def _get(obj, key, default=None):
"""Return value for key/attribute from dicts or objects."""
if isinstance(obj, dict):
@@ -66,7 +67,8 @@ def upsert_node(node_id, n):
_get(pos, "altitude"),
json.dumps(_jsonable(n), ensure_ascii=False),
)
conn.execute("""
conn.execute(
"""
INSERT INTO nodes(node_id,num,short_name,long_name,macaddr,hw_model,role,public_key,is_unmessagable,is_favorite,
hops_away,snr,last_heard,battery_level,voltage,channel_utilization,air_util_tx,uptime_seconds,
position_time,location_source,latitude,longitude,altitude,node_json)
@@ -79,7 +81,9 @@ def upsert_node(node_id, n):
air_util_tx=excluded.air_util_tx, uptime_seconds=excluded.uptime_seconds, position_time=excluded.position_time,
location_source=excluded.location_source, latitude=excluded.latitude, longitude=excluded.longitude,
altitude=excluded.altitude, node_json=excluded.node_json
""", row)
""",
row,
)
def load_nodes_from_file(path: str | Path):
@@ -89,6 +93,7 @@ def load_nodes_from_file(path: str | Path):
upsert_node(node_id, node)
conn.commit()
def snapshot_nodes_periodically(iface: MeshInterface, every_sec=30):
time.sleep(5) # let the library sync initial node DB
while True:
@@ -100,16 +105,21 @@ def snapshot_nodes_periodically(iface: MeshInterface, every_sec=30):
print("node snapshot error:", e)
time.sleep(every_sec)
def main():
if SerialInterface is None:
raise RuntimeError("meshtastic library not installed")
iface = SerialInterface(devPath="/dev/ttyACM0")
threading.Thread(target=snapshot_nodes_periodically, args=(iface, 30), daemon=True).start()
threading.Thread(
target=snapshot_nodes_periodically, args=(iface, 30), daemon=True
).start()
print("Nodes ingestor running. Ctrl+C to stop.")
try:
while True: time.sleep(300)
while True:
time.sleep(300)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()