style: apply ruff lint fixes and formatting to figment modules

Fixes: unused imports, import sorting, unused variable, overly broad
exception type in test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 11:09:46 -07:00
parent 4cf316c280
commit 2bfd3a01da
5 changed files with 20 additions and 21 deletions

View File

@@ -53,7 +53,11 @@ class FigmentEffect(EffectPlugin):
}, },
) )
def __init__(self, figment_dir: str | None = None, triggers: list[FigmentTrigger] | None = None): def __init__(
self,
figment_dir: str | None = None,
triggers: list[FigmentTrigger] | None = None,
):
self.config = EffectConfig( self.config = EffectConfig(
enabled=False, enabled=False,
intensity=1.0, intensity=1.0,
@@ -125,7 +129,9 @@ class FigmentEffect(EffectPlugin):
self._phase = FigmentPhase.REVEAL self._phase = FigmentPhase.REVEAL
self._progress = 0.0 self._progress = 0.0
def get_figment_state(self, frame_number: int, w: int, h: int) -> FigmentState | None: def get_figment_state(
self, frame_number: int, w: int, h: int
) -> FigmentState | None:
"""Tick the state machine and return current state, or None if idle.""" """Tick the state machine and return current state, or None if idle."""
if not self.config.enabled: if not self.config.enabled:
return None return None
@@ -178,9 +184,13 @@ class FigmentEffect(EffectPlugin):
def _handle_command(self, cmd: FigmentCommand, w: int, h: int) -> None: def _handle_command(self, cmd: FigmentCommand, w: int, h: int) -> None:
if cmd.action == FigmentAction.TRIGGER: if cmd.action == FigmentAction.TRIGGER:
self.trigger(w, h) self.trigger(w, h)
elif cmd.action == FigmentAction.SET_INTENSITY and isinstance(cmd.value, (int, float)): elif cmd.action == FigmentAction.SET_INTENSITY and isinstance(
cmd.value, (int, float)
):
self.config.intensity = float(cmd.value) self.config.intensity = float(cmd.value)
elif cmd.action == FigmentAction.SET_INTERVAL and isinstance(cmd.value, (int, float)): elif cmd.action == FigmentAction.SET_INTERVAL and isinstance(
cmd.value, (int, float)
):
self.config.params["interval_secs"] = float(cmd.value) self.config.params["interval_secs"] = float(cmd.value)
elif cmd.action == FigmentAction.SET_COLOR and isinstance(cmd.value, str): elif cmd.action == FigmentAction.SET_COLOR and isinstance(cmd.value, str):
if cmd.value in THEME_REGISTRY: if cmd.value in THEME_REGISTRY:

View File

@@ -57,9 +57,7 @@ def render_message_overlay(
else: else:
msg_rows = msg_cache[1] msg_rows = msg_cache[1]
msg_rows = msg_gradient( msg_rows = msg_gradient(msg_rows, (time.monotonic() * config.GRAD_SPEED) % 1.0)
msg_rows, (time.monotonic() * config.GRAD_SPEED) % 1.0
)
elapsed_s = int(time.monotonic() - m_ts) elapsed_s = int(time.monotonic() - m_ts)
remaining = max(0, config.MESSAGE_DISPLAY_SECS - elapsed_s) remaining = max(0, config.MESSAGE_DISPLAY_SECS - elapsed_s)
@@ -353,8 +351,6 @@ def render_figment_overlay(
if has_content: if has_content:
line_str = "".join(line_buf).rstrip() line_str = "".join(line_buf).rstrip()
if line_str.strip(): if line_str.strip():
overlay.append( overlay.append(f"\033[{scr_row};{center_col + 1}H{line_str}{RST}")
f"\033[{scr_row};{center_col + 1}H{line_str}{RST}"
)
return overlay return overlay

View File

@@ -18,8 +18,8 @@ from engine.frame import calculate_scroll_step
from engine.layers import ( from engine.layers import (
apply_glitch, apply_glitch,
process_effects, process_effects,
render_firehose,
render_figment_overlay, render_figment_overlay,
render_firehose,
render_message_overlay, render_message_overlay,
render_ticker_zone, render_ticker_zone,
) )

View File

@@ -2,17 +2,11 @@
import os import os
from enum import Enum from enum import Enum
from unittest.mock import patch
import pytest
from effects_plugins.figment import FigmentEffect, FigmentPhase, FigmentState from effects_plugins.figment import FigmentEffect, FigmentPhase, FigmentState
from engine.effects.types import EffectConfig, EffectContext from engine.effects.types import EffectConfig, EffectContext
FIXTURE_SVG = os.path.join(os.path.dirname(__file__), "fixtures", "test.svg")
FIXTURE_SVG = os.path.join(
os.path.dirname(__file__), "fixtures", "test.svg"
)
FIGMENTS_DIR = os.path.join(os.path.dirname(__file__), "fixtures") FIGMENTS_DIR = os.path.join(os.path.dirname(__file__), "fixtures")
@@ -104,12 +98,10 @@ class TestFigmentStateMachine:
assert state.phase == FigmentPhase.REVEAL assert state.phase == FigmentPhase.REVEAL
# Advance enough frames to get through all phases # Advance enough frames to get through all phases
last_state = None
for frame in range(2, 100): for frame in range(2, 100):
state = effect.get_figment_state(frame, 40, 20) state = effect.get_figment_state(frame, 40, 20)
if state is None: if state is None:
break break
last_state = state
# Should have completed the full cycle back to idle # Should have completed the full cycle back to idle
assert state is None assert state is None

View File

@@ -31,7 +31,8 @@ class TestRasterizeSvg:
def test_nonexistent_file_raises(self): def test_nonexistent_file_raises(self):
import pytest import pytest
with pytest.raises(Exception):
with pytest.raises((FileNotFoundError, OSError)):
rasterize_svg("/nonexistent/file.svg", 40, 20) rasterize_svg("/nonexistent/file.svg", 40, 20)