Skip to content

Commit f5f0805

Browse files
committed
pylint and format
1 parent b036cc6 commit f5f0805

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Fruit_Jam/Fruit_Jam_IRC_Client/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
22
# SPDX-License-Identifier: MIT
3+
from os import getenv
34
from displayio import Group
45
from terminalio import FONT
56
import supervisor
6-
from os import getenv
77
import audiocore
88
import board
99
import busio
@@ -57,7 +57,7 @@
5757
print("could not connect to AP, retrying: ", e)
5858
continue
5959

60-
print(f"IRC Configuration:")
60+
print("IRC Configuration:")
6161
print(f"Server: {IRC_CONFIG['server']}:{IRC_CONFIG['port']}")
6262
print(f"Nickname: {IRC_CONFIG['username']}")
6363
print(f"Channel: {IRC_CONFIG['channel']}")

Fruit_Jam/Fruit_Jam_IRC_Client/curses_irc_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
22
# SPDX-License-Identifier: MIT
3-
import adafruit_dang as curses
43
import time
4+
import adafruit_dang as curses
55

66
from irc_client import IRCClient
77

@@ -48,6 +48,7 @@ def irc_client_main(
4848
audio_interface=None,
4949
beep_wave=None,
5050
):
51+
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
5152
"""
5253
Main curses IRC client application loop.
5354
"""
@@ -98,9 +99,9 @@ def get_page(row_index):
9899
page_end = page_start + page_len
99100

100101
page = irc_client.message_buffer[page_start:page_end]
101-
# print(f"get_page({row_index}) len: {len(page)} start: {page_start} end: {page_end} rows: {window.n_rows - 2}")
102102
return page
103103

104+
# pylint: disable=too-many-nested-blocks
104105
try:
105106
# main application loop
106107
while True:
@@ -128,7 +129,7 @@ def get_page(row_index):
128129

129130
user_message_row = terminal_tilegrid.height - 1
130131
if status_bar["user_message"] is None:
131-
message = f" {irc_config['username']} | {irc_config['server']} | {irc_config['channel']}"
132+
message = f" {irc_config['username']} | {irc_config['server']} | {irc_config['channel']}" # pylint: disable=line-too-long
132133
message += " " * (terminal_tilegrid.width - len(message) - 1)
133134
line = f"{ANSI_BLACK_ON_GREY}{message}{ANSI_RESET}"
134135
else:
@@ -226,9 +227,9 @@ def get_page(row_index):
226227
else:
227228
print(f"unknown key: {k}")
228229

229-
except KeyboardInterrupt:
230+
except KeyboardInterrupt as exc:
230231
irc_client.disconnect()
231-
raise KeyboardInterrupt
232+
raise KeyboardInterrupt from exc
232233

233234

234235
def run_irc_client(

Fruit_Jam/Fruit_Jam_IRC_Client/irc_client.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: MIT
33
import time
44

5-
65
import adafruit_connection_manager
76

87
ANSI_ESCAPE_CODES = [
@@ -22,7 +21,8 @@ class IRCClient:
2221
Handles interaction with IRC Server and makes incoming messages available.
2322
2423
:param radio: The network radio to connect with.
25-
:param dict irc_config: Dictionary containing IRC configration for server, port, username and channel.
24+
:param dict irc_config: Dictionary containing IRC configration for
25+
server, port, username and channel.
2626
:param audio_interface: Optional interface to play audio from for beep messages
2727
:param beep_wave: Optional wave file to use for beep messages
2828
:param int max_line_length: Maximum characters per line to format messages into.
@@ -142,7 +142,7 @@ def update(self):
142142
# no data before timeout
143143
# print(e)
144144
if "ETIMEDOUT" not in str(e):
145-
raise RuntimeError(e)
145+
raise RuntimeError(e) from e
146146
# raise RuntimeError("Connection timed out")
147147
return updated_display_lines
148148

@@ -163,7 +163,6 @@ def send_dm(self, to_user, message):
163163
"""
164164
irc_command = f"PRIVMSG {to_user} :{message}\r\n"
165165
self.socket.send(irc_command.encode("utf-8"))
166-
# self.process_message(f":{self.config['username']}!~{self.config['username']}@localhost " + irc_command[:-2])
167166
color = self.get_color_for_user(to_user)
168167
self.message_buffer.append(f"DM out: <{color}{to_user}{ANSI_RESET}> {message}")
169168

@@ -205,7 +204,7 @@ def get_technical_name(self, nickname):
205204
if "ETIMEDOUT" in str(e):
206205
whois_resp_lines = None
207206
else:
208-
raise RuntimeError(e)
207+
raise RuntimeError(e) from e
209208

210209
if whois_resp_lines is None:
211210
return None
@@ -221,10 +220,11 @@ def get_technical_name(self, nickname):
221220

222221
whois_response = parts[2].split(" ", 1)[1]
223222
response_parts = whois_response.split(" ")
224-
showname = response_parts[0]
225223
technical_name = f"*!{response_parts[1]}@{response_parts[2]}"
226224
return technical_name
227225

226+
return None
227+
228228
def ban(self, user):
229229
"""
230230
Ban the specified user from the channel
@@ -301,13 +301,14 @@ def split_string_chunks(s, chunk_size):
301301
return chunks
302302

303303
def process_message(self, message):
304+
# pylint: disable=too-many-branches, too-many-statements
304305
"""
305306
Process an incoming IRC message
306307
:param message: The message that came from the IRC server.
307308
308309
:return lines_added: The number of lines added to the display
309310
"""
310-
311+
# pylint: disable=too-many-locals
311312
lines_added = 0
312313

313314
message = message.lstrip("\x00")
@@ -317,12 +318,12 @@ def process_message(self, message):
317318
if message.startswith("PING"):
318319
pong_response = message.replace("PING", "PONG")
319320
self.socket.send(f"{pong_response}\r\n".encode("utf-8"))
320-
print(f"Responded to PING")
321+
print("Responded to PING")
321322
return 0
322323

323324
# Parse IRC message format: :prefix COMMAND params
324325
parts = message.split(" ", 2)
325-
326+
# pylint: disable=too-many-nested-blocks
326327
if len(parts) >= 2:
327328
command = parts[1]
328329
try:
@@ -331,7 +332,7 @@ def process_message(self, message):
331332
command_num = None
332333

333334
# End of MOTD - now we can join the channel
334-
if command == "376" or command == "422": # 422 is "no MOTD"
335+
if command in {"376", "422"}: # 422 is "no MOTD"
335336
# join channel
336337
self.join()
337338

@@ -357,7 +358,7 @@ def process_message(self, message):
357358
welcome_text = welcome_text[1:]
358359

359360
print(
360-
f"'{welcome_text[0:11]}' startswith '{self.config['username']}' ? {welcome_text.startswith(self.config['username'])}"
361+
f"'{welcome_text[0:11]}' startswith '{self.config['username']}' ? {welcome_text.startswith(self.config['username'])}" # pylint: disable=line-too-long
361362
)
362363
if welcome_text.startswith(self.config["username"]):
363364
welcome_text = welcome_text.replace(
@@ -451,11 +452,13 @@ def process_message(self, message):
451452
action_user = parts[0].split("!", 1)[0][1:]
452453
mode_msg_parts = parts[2].split(" ", 2)
453454
if len(mode_msg_parts) >= 3:
454-
channel, mode, target_user = mode_msg_parts
455+
channel, mode, target_user = (
456+
mode_msg_parts # pylint: disable=unused-variable
457+
)
455458
action_user_color = self.get_color_for_user(action_user)
456459
target_user_color = self.get_color_for_user(target_user)
457460
self.message_buffer.append(
458-
f"{action_user_color}{action_user}{ANSI_RESET} sets mode {mode} on {target_user_color}{target_user}{ANSI_RESET}"
461+
f"{action_user_color}{action_user}{ANSI_RESET} sets mode {mode} on {target_user_color}{target_user}{ANSI_RESET}" # pylint: disable=line-too-long
459462
)
460463
lines_added += 1
461464

0 commit comments

Comments
 (0)