Skip to content

Commit b7bef49

Browse files
committed
ruff
1 parent b305d8f commit b7bef49

9 files changed

Lines changed: 51 additions & 48 deletions

gambaterm/controller_input.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ def pygame_button_pressed_context(
5151
try:
5252
import pygame
5353
except ImportError:
54-
raise SystemExit(
55-
"""\
54+
raise SystemExit("""\
5655
The pygame library is not available, which is required to get controller support.
5756
Please use the following command to install gambaterm with controller support:
5857
pip3 install gambaterm[controller-support]
59-
"""
60-
)
58+
""")
6159

6260
pygame.init()
6361
pygame.joystick.init()

gambaterm/graphics_scaler.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@
2424

2525
BASELINE_ID = 1
2626
DELTA_ID = 2
27-
SIXEL_REBASELINE_THRESHOLD = float(
28-
os.environ.get("GAMBATERM_SIXEL_REBASELINE", "0.35")
29-
)
30-
KITTY_REBASELINE_THRESHOLD = float(
31-
os.environ.get("GAMBATERM_KITTY_REBASELINE", "0.35")
32-
)
27+
SIXEL_REBASELINE_THRESHOLD = float(os.environ.get("GAMBATERM_SIXEL_REBASELINE", "0.35"))
28+
KITTY_REBASELINE_THRESHOLD = float(os.environ.get("GAMBATERM_KITTY_REBASELINE", "0.35"))
3329
SCALE_MAX = int(os.environ.get("GAMBATERM_SCALE_MAX", "12"))
3430

3531

@@ -239,9 +235,7 @@ def __init__(
239235
"x1,y1,rect_w,rect_h,"
240236
"refx_kitty,refy_kitty,scale\n"
241237
)
242-
atexit.register(
243-
self.profile.dump, f"{profile_dir}/gambaterm-profile.txt"
244-
)
238+
atexit.register(self.profile.dump, f"{profile_dir}/gambaterm-profile.txt")
245239
else:
246240
self.stats_fh = open(os.devnull, "w")
247241

@@ -531,7 +525,10 @@ def encode_kitty_frame(self, video, encode_fn):
531525
rect_h = y2 - y1
532526
rect_area = rect_w * rect_h
533527

534-
if changed_pct > KITTY_REBASELINE_THRESHOLD or rect_area > total_pixels * KITTY_REBASELINE_THRESHOLD:
528+
if (
529+
changed_pct > KITTY_REBASELINE_THRESHOLD
530+
or rect_area > total_pixels * KITTY_REBASELINE_THRESHOLD
531+
):
535532
self.profile.keyframes += 1
536533
self.baseline = video.copy()
537534
rgba = to_rgba_u8(video)

gambaterm/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
from .console import GameboyColor, Console
1515
from .audio import audio_player
1616
from .colors import detect_local_color_mode, ColorMode
17-
from .remote_terminal import GraphicsProtocol, FORCE_SIXEL_BLITLESS, BAD_TEXT, does_sixel
17+
from .remote_terminal import (
18+
GraphicsProtocol,
19+
FORCE_SIXEL_BLITLESS,
20+
BAD_TEXT,
21+
does_sixel,
22+
)
1823
from .graphics_scaler import parse_autoscale
1924
from .keyboard_input import is_kitty_keyboard_protocol_supported
2025
from .input_getter import BaseInputGetter

gambaterm/run.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def run(
168168
cycle = [
169169
p
170170
for p in graphics_cycle
171-
if p is not GraphicsProtocol.TEXT or not terminal_name.startswith(BAD_TEXT)
171+
if p is not GraphicsProtocol.TEXT
172+
or not terminal_name.startswith(BAD_TEXT)
172173
]
173174
if cycle:
174175
idx = cycle.index(graphics_protocol)
@@ -180,7 +181,10 @@ def run(
180181
average_over = int(round(fps)) # frames
181182
audio_out.update_speed(console, speed)
182183
elif key.key_name in ("FOCUS_IN", "FOCUS_OUT"):
183-
if graphics_protocol is GraphicsProtocol.SIXEL and terminal_name.startswith("mlterm"):
184+
if (
185+
graphics_protocol is GraphicsProtocol.SIXEL
186+
and terminal_name.startswith("mlterm")
187+
):
184188
if scaler is not None:
185189
scaler.sixel_baseline = None
186190
elif key.key_name in ("KEY_GRAVE_ACCENT", "KEY_TILDE") or key in ("`", "~"):
@@ -312,15 +316,11 @@ def run(
312316
force_clear = False
313317
frame_data += maybe_clear_sequence
314318
if graphics_protocol is GraphicsProtocol.SIXEL:
315-
frame_data += scaler.blit_sixel(
316-
video, last_frame
317-
)
319+
frame_data += scaler.blit_sixel(video, last_frame)
318320
elif graphics_protocol is GraphicsProtocol.BLITLESS_SIXEL:
319321
frame_data += scaler.blit_sixel_blitless(video, width, height)
320322
else:
321-
frame_data += scaler.blit_kitty(
322-
video, last_frame
323-
)
323+
frame_data += scaler.blit_kitty(video, last_frame)
324324
if terminal_name.startswith(FORCE_KITTY_BLITLESS):
325325
scaler.baseline = None
326326
if sync_end:

gambaterm/ssh.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ def ssh_terminal_handler(
199199
input_source = detect_input_source(app_config, keyboard_support_detection)
200200
console_input_context: ContextManager[BaseInputGetter]
201201
if input_source is None:
202-
message = (
203-
MESSAGE_SUGGESTING_KITTY_SUPPORT
204-
+ "\n\n"
205-
+ """\
202+
message = MESSAGE_SUGGESTING_KITTY_SUPPORT + "\n\n" + """\
206203
Alternatively, X11 forwarding can be used in order to give the gambaterm-ssh
207204
server access to your keyboard, eg. `ssh -Y -p 8022 localhost`.
208205
===============================[ WARNING ]=====================================
@@ -211,7 +208,6 @@ def ssh_terminal_handler(
211208
sandbox. More information here: https://security.stackexchange.com/a/7496
212209
===============================[ WARNING ]=====================================
213210
"""
214-
)
215211
terminal.stream.write(message)
216212
terminal.stream.flush()
217213
session_logger.warning(
@@ -338,10 +334,10 @@ def __init__(
338334
users_directory: Path,
339335
executor: ThreadPoolExecutor,
340336
active_connections: dict[GambatermSSHServer, SSHServerConnection],
341-
frontend: Callable[
342-
[RemoteTerminal, AppConfig, KeyboardSupportDetection], AppConfig
343-
]
344-
| None = None,
337+
frontend: (
338+
Callable[[RemoteTerminal, AppConfig, KeyboardSupportDetection], AppConfig]
339+
| None
340+
) = None,
345341
):
346342
self._gambaterm_console_cls = console_cls
347343
self._gambaterm_namespace = namespace

tests/_frontend_ssh_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from gambaterm.main import AppConfig
1010
from gambaterm.remote_terminal import RemoteTerminal, KeyboardSupportDetection
1111

12-
1312
rom = Path(sys.argv[1])
1413

1514

tests/_frontend_telnet_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from gambaterm.main import AppConfig
1010
from gambaterm.remote_terminal import RemoteTerminal, KeyboardSupportDetection
1111

12-
1312
rom = Path(sys.argv[1])
1413

1514

tests/test_gambaterm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def test_gambaterm_ssh(
6666
ssh_config: Path, gambaterm_config: Path, color_arg: str
6767
) -> None:
6868
assert TEST_ROM.exists()
69-
command = f"gambaterm-ssh {TEST_ROM} --break-after 10 --input-file /dev/null --graphics text" + (
70-
f" {color_arg}" if color_arg else ""
69+
command = (
70+
f"gambaterm-ssh {TEST_ROM} --break-after 10 --input-file /dev/null --graphics text"
71+
+ (f" {color_arg}" if color_arg else "")
7172
)
7273
env = os.environ.copy()
7374
env["PYTHONUNBUFFERED"] = "1"
@@ -125,7 +126,8 @@ def test_gambaterm_telnet(color_arg: str) -> None:
125126
assert TEST_ROM.exists()
126127
command = (
127128
f"{sys.executable} -m gambaterm.telnet {TEST_ROM} --break-after 10"
128-
f" --input-file /dev/null --graphics text" + (f" {color_arg}" if color_arg else "")
129+
f" --input-file /dev/null --graphics text"
130+
+ (f" {color_arg}" if color_arg else "")
129131
)
130132
env = os.environ.copy()
131133
env["PYTHONUNBUFFERED"] = "1"

tests/test_graphics_renderer.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def test_sixel_rebaseline_on_large_change():
202202
assert "\033P0;1;0q" in text
203203
assert "\033\\" in text
204204

205+
205206
class TestAutoScale:
206207
@staticmethod
207208
def test_fps_below_threshold_reduces():
@@ -311,12 +312,15 @@ def test_disabled(self, value):
311312

312313
assert parse_autoscale(value).enabled is False
313314

314-
@pytest.mark.parametrize("value,seconds,fps,mbits", [
315-
("30fps", -1, 30.0, 0.0),
316-
("60s,30fps,10mb", 60, 30.0, 80.0),
317-
("1500kb", -1, 40.0, 12.0),
318-
("always,25fps", -1, 25.0, 0.0),
319-
])
315+
@pytest.mark.parametrize(
316+
"value,seconds,fps,mbits",
317+
[
318+
("30fps", -1, 30.0, 0.0),
319+
("60s,30fps,10mb", 60, 30.0, 80.0),
320+
("1500kb", -1, 40.0, 12.0),
321+
("always,25fps", -1, 25.0, 0.0),
322+
],
323+
)
320324
def test_parse(self, value, seconds, fps, mbits):
321325
from gambaterm.graphics_scaler import parse_autoscale
322326

@@ -326,11 +330,14 @@ def test_parse(self, value, seconds, fps, mbits):
326330
assert cfg.fps == fps
327331
assert cfg.bandwidth_mbits == mbits
328332

329-
@pytest.mark.parametrize("value", [
330-
"always,90s,30fps",
331-
"disabled,90s,10mb",
332-
"off,30fps",
333-
])
333+
@pytest.mark.parametrize(
334+
"value",
335+
[
336+
"always,90s,30fps",
337+
"disabled,90s,10mb",
338+
"off,30fps",
339+
],
340+
)
334341
def test_mutually_exclusive_errors(self, value):
335342
from gambaterm.graphics_scaler import parse_autoscale
336343

0 commit comments

Comments
 (0)