Skip to content

Commit 7e848b7

Browse files
authored
Add CI check for Python scripts (#2163)
* Add CI check for Python scripts * Fix variable errors * Fix websocket type * Fix import * Rename check * Fix websocket type in newly added python script * Remove duplicate run function
1 parent bfd58d1 commit 7e848b7

10 files changed

+46
-55
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Python Script Checks
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches: [ main, mf2025/main ]
7+
paths:
8+
- 'Scripts/**/*.py'
9+
10+
jobs:
11+
python-script-checks:
12+
name: Python ${{ matrix.python-version }} Syntax Check
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version:
19+
- '3.11'
20+
- '3.12'
21+
- '3.13'
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
32+
- name: Install dependencies
33+
run: |
34+
pip install --upgrade pip
35+
pip install pylint gql websockets simconnect
36+
37+
- name: Run linter on the Scripts folder
38+
run: pylint Scripts --disable=all --enable=F,E

Scripts/Winwing/fbw_a32nx_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MfColour(StrEnum):
6060

6161
class MobiFlightClient:
6262
def __init__(self, websocket_uri: str, max_retries: int = 3) -> None:
63-
self.websocket: Optional[ws_client.WebSocketClientProtocol] = None
63+
self.websocket: Optional[ws_client.ClientConnection] = None
6464
self.connected: asyncio.Event = asyncio.Event()
6565
self.websocket_uri: str = websocket_uri
6666
self.retries: int = 0

Scripts/Winwing/fenix_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def run_mobiflight_websocket_client(self):
119119
# Break and stop for that CDU
120120
break
121121
else:
122-
logging.error(f"Error on trying to connect to MobiFlight websocket interface for {self.id}. Will retry: {ex}")
122+
logging.error(f"Error on trying to connect to MobiFlight websocket interface for {self.id}. Will retry: {invalid}")
123123
except Exception as ex:
124124
logging.error(f"Error on trying to connect to MobiFlight websocket interface for {self.id}. Will retry: {ex}")
125125
self.websocket_connection = None

Scripts/Winwing/fslabs_winwing_cdu.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
async def fetch_fsl_mcdu():
4747
"""Fetch MCDU data using a persistent HTTP connection, avoiding redundant updates."""
48-
global last_mcdu_data
4948
last_fetched_data = None
5049

5150
conn = http.client.HTTPConnection("localhost", 8080, timeout=1) # Persistent connection
@@ -80,8 +79,6 @@ async def fetch_fsl_mcdu():
8079

8180
async def run_fsl_http_client():
8281
"""Measure the time it takes to send updates to MobiFlight."""
83-
global mobi_websocket_connection
84-
8582
while True:
8683
mobi_json = await data_queue.get()
8784

Scripts/Winwing/headwind_a33_winwing_cdu.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MfColour(StrEnum):
6060

6161
class MobiFlightClient:
6262
def __init__(self, websocket_uri: str, max_retries: int = 3) -> None:
63-
self.websocket: Optional[ws_client.WebSocketClientProtocol] = None
63+
self.websocket: Optional[ws_client.ClientConnection] = None
6464
self.connected: asyncio.Event = asyncio.Event()
6565
self.websocket_uri: str = websocket_uri
6666
self.retries: int = 0
@@ -420,50 +420,6 @@ async def connect_to_mcdu(self):
420420
await asyncio.sleep(5) # Wait before retry
421421
return False
422422

423-
async def run(self):
424-
"""Main processing loop"""
425-
logging.info("Starting FlyByWire SimBridge client")
426-
while True:
427-
try:
428-
# Wait for messages from the MCDU
429-
if self.fbw_websocket is None:
430-
if not await self.connect_to_mcdu():
431-
logging.info("Max SimBridge attempts reached. Waiting for new attempts.")
432-
await asyncio.sleep(
433-
10
434-
) # Wait longer between retries if we can't connect
435-
continue
436-
437-
msg = await self.fbw_websocket.recv()
438-
439-
# Process any update messages
440-
if msg.startswith("update:"):
441-
data_json = json.loads(msg[msg.index(":") + 1:])
442-
443-
for side in ("left", "right"):
444-
mobiflight = self.mobiflight.get(side)
445-
mcdu_data = data_json.get(side)
446-
if mobiflight is not None and mobiflight.is_connected():
447-
# only update if there is new data to display
448-
if (
449-
mcdu_data is not None
450-
and self.last_mcdu_data.get(side) != mcdu_data
451-
):
452-
self.last_mcdu_data[side] = mcdu_data
453-
await mobiflight.send(create_mobi_json(mcdu_data))
454-
elif mcdu_data is None:
455-
self.last_mcdu_data[side] = None
456-
# clear the display
457-
await mobiflight.send(create_mobi_json(dict()))
458-
else:
459-
# make sure we get a refresh if we later connect
460-
self.last_mcdu_data[side] = None
461-
462-
except Exception as e:
463-
logging.error(f"Error processing MCDU data: {e}")
464-
self.fbw_websocket = None
465-
await asyncio.sleep(5)
466-
467423
async def request_update(self):
468424
if self.fbw_websocket is not None:
469425
await self.fbw_websocket.send("requestUpdate")

Scripts/Winwing/ifly_737_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import asyncio
66
from typing import Dict, List, Optional, Union
7-
from websockets.client import connect
7+
from websockets.asyncio.client import connect
88
import mmap
99

1010
# WebSocket URLs

Scripts/Winwing/maddogx_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def my_dispatch_proc(self, pData, cbData, pContext):
9797

9898
class MobiFlightClient:
9999
def __init__(self, websocket_uri: str, max_retries: int = 3) -> None:
100-
self.websocket: Optional[ws_client.WebSocketClientProtocol] = None
100+
self.websocket: Optional[ws_client.ClientConnection] = None
101101
self.connected: asyncio.Event = asyncio.Event()
102102
self.websocket_uri: str = websocket_uri
103103
self.retries: int = 0

Scripts/Winwing/pmdg_737_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def my_dispatch_proc(self, pData, cbData, pContext):
7777

7878
class MobiFlightClient:
7979
def __init__(self, websocket_uri: str, max_retries: int = 3) -> None:
80-
self.websocket: Optional[ws_client.WebSocketClientProtocol] = None
80+
self.websocket: Optional[ws_client.ClientConnection] = None
8181
self.connected: asyncio.Event = asyncio.Event()
8282
self.websocket_uri: str = websocket_uri
8383
self.retries: int = 0

Scripts/Winwing/pmdg_777_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def my_dispatch_proc(self, pData, cbData, pContext):
8181

8282
class MobiFlightClient:
8383
def __init__(self, websocket_uri: str, max_retries: int = 3) -> None:
84-
self.websocket: Optional[ws_client.WebSocketClientProtocol] = None
84+
self.websocket: Optional[ws_client.ClientConnection] = None
8585
self.connected: asyncio.Event = asyncio.Event()
8686
self.websocket_uri: str = websocket_uri
8787
self.retries: int = 0

Scripts/Winwing/tfdi_md11_winwing_cdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def my_dispatch_proc(self, pData, cbData, pContext):
7878

7979
class MobiFlightClient:
8080
def __init__(self, websocket_uri: str, max_retries: int = 3) -> None:
81-
self.websocket: Optional[ws_client.WebSocketClientProtocol] = None
81+
self.websocket: Optional[ws_client.ClientConnection] = None
8282
self.connected: asyncio.Event = asyncio.Event()
8383
self.websocket_uri: str = websocket_uri
8484
self.retries: int = 0

0 commit comments

Comments
 (0)