style: apply ruff auto-fixes across codebase
- Fix import sorting (isort) across all engine modules - Fix SIM105 try-except-pass patterns (contextlib.suppress) - Fix nested with statements in tests - Fix unused loop variables Run 'uv run pytest' to verify tests still pass.
This commit is contained in:
@@ -2,23 +2,33 @@
|
|||||||
Application orchestrator — boot sequence, signal handling, main loop wiring.
|
Application orchestrator — boot sequence, signal handling, main loop wiring.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import time
|
|
||||||
import signal
|
|
||||||
import atexit
|
import atexit
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
import termios
|
import termios
|
||||||
|
import time
|
||||||
import tty
|
import tty
|
||||||
|
|
||||||
from engine import config, render
|
from engine import config, render
|
||||||
from engine.terminal import (
|
|
||||||
RST, G_HI, G_MID, G_DIM, W_DIM, W_GHOST, CLR, CURSOR_OFF, CURSOR_ON, tw,
|
|
||||||
slow_print, boot_ln,
|
|
||||||
)
|
|
||||||
from engine.fetch import fetch_all, fetch_poetry, load_cache, save_cache
|
from engine.fetch import fetch_all, fetch_poetry, load_cache, save_cache
|
||||||
from engine.ntfy import NtfyPoller
|
|
||||||
from engine.mic import MicMonitor
|
from engine.mic import MicMonitor
|
||||||
|
from engine.ntfy import NtfyPoller
|
||||||
from engine.scroll import stream
|
from engine.scroll import stream
|
||||||
|
from engine.terminal import (
|
||||||
|
CLR,
|
||||||
|
CURSOR_OFF,
|
||||||
|
CURSOR_ON,
|
||||||
|
G_DIM,
|
||||||
|
G_HI,
|
||||||
|
G_MID,
|
||||||
|
RST,
|
||||||
|
W_DIM,
|
||||||
|
W_GHOST,
|
||||||
|
boot_ln,
|
||||||
|
slow_print,
|
||||||
|
tw,
|
||||||
|
)
|
||||||
|
|
||||||
TITLE = [
|
TITLE = [
|
||||||
" ███╗ ███╗ █████╗ ██╗███╗ ██╗██╗ ██╗███╗ ██╗███████╗",
|
" ███╗ ███╗ █████╗ ██╗███╗ ██╗██╗ ██╗███╗ ██╗███████╗",
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ Configuration constants, CLI flags, and glyph tables.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
_REPO_ROOT = Path(__file__).resolve().parent.parent
|
_REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||||
_FONT_EXTENSIONS = {".otf", ".ttf", ".ttc"}
|
_FONT_EXTENSIONS = {".otf", ".ttf", ".ttc"}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import random
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from engine import config
|
from engine import config
|
||||||
from engine.terminal import RST, DIM, G_LO, G_DIM, W_GHOST, C_DIM
|
|
||||||
from engine.sources import FEEDS, POETRY_SOURCES
|
from engine.sources import FEEDS, POETRY_SOURCES
|
||||||
|
from engine.terminal import C_DIM, DIM, G_DIM, G_LO, RST, W_GHOST
|
||||||
|
|
||||||
|
|
||||||
def noise(w):
|
def noise(w):
|
||||||
|
|||||||
@@ -3,19 +3,20 @@ RSS feed fetching, Project Gutenberg parsing, and headline caching.
|
|||||||
Depends on: config, sources, filter, terminal.
|
Depends on: config, sources, filter, terminal.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import re
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
|
|
||||||
from engine import config
|
from engine import config
|
||||||
|
from engine.filter import skip, strip_tags
|
||||||
from engine.sources import FEEDS, POETRY_SOURCES
|
from engine.sources import FEEDS, POETRY_SOURCES
|
||||||
from engine.filter import strip_tags, skip
|
|
||||||
from engine.terminal import boot_ln
|
from engine.terminal import boot_ln
|
||||||
|
|
||||||
|
|
||||||
# ─── SINGLE FEED ──────────────────────────────────────────
|
# ─── SINGLE FEED ──────────────────────────────────────────
|
||||||
def fetch_feed(url):
|
def fetch_feed(url):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ Gracefully degrades if sounddevice/numpy are unavailable.
|
|||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sounddevice as _sd
|
|
||||||
import numpy as _np
|
import numpy as _np
|
||||||
|
import sounddevice as _sd
|
||||||
_HAS_MIC = True
|
_HAS_MIC = True
|
||||||
except Exception:
|
except Exception:
|
||||||
_HAS_MIC = False
|
_HAS_MIC = False
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ Reusable by any visualizer:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
|
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ Font loading, text rasterization, word-wrap, gradient coloring, headline block a
|
|||||||
Depends on: config, terminal, sources, translate.
|
Depends on: config, terminal, sources, translate.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
from engine import config
|
from engine import config
|
||||||
|
from engine.sources import NO_UPPER, SCRIPT_FONTS, SOURCE_LANGS
|
||||||
from engine.terminal import RST
|
from engine.terminal import RST
|
||||||
from engine.sources import SCRIPT_FONTS, SOURCE_LANGS, NO_UPPER
|
|
||||||
from engine.translate import detect_location_language, translate_headline
|
from engine.translate import detect_location_language, translate_headline
|
||||||
|
|
||||||
# ─── GRADIENT ─────────────────────────────────────────────
|
# ─── GRADIENT ─────────────────────────────────────────────
|
||||||
@@ -62,7 +62,7 @@ def font():
|
|||||||
f"No primary font selected. Add .otf/.ttf/.ttc files to {config.FONT_DIR}."
|
f"No primary font selected. Add .otf/.ttf/.ttc files to {config.FONT_DIR}."
|
||||||
)
|
)
|
||||||
key = (config.FONT_PATH, config.FONT_INDEX, config.FONT_SZ)
|
key = (config.FONT_PATH, config.FONT_INDEX, config.FONT_SZ)
|
||||||
if _FONT_OBJ is None or _FONT_OBJ_KEY != key:
|
if _FONT_OBJ is None or key != _FONT_OBJ_KEY:
|
||||||
_FONT_OBJ = ImageFont.truetype(
|
_FONT_OBJ = ImageFont.truetype(
|
||||||
config.FONT_PATH, config.FONT_SZ, index=config.FONT_INDEX
|
config.FONT_PATH, config.FONT_SZ, index=config.FONT_INDEX
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,16 +3,23 @@ Render engine — ticker content, scroll motion, message panel, and firehose ove
|
|||||||
Depends on: config, terminal, render, effects, ntfy, mic.
|
Depends on: config, terminal, render, effects, ntfy, mic.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import random
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from engine import config
|
from engine import config
|
||||||
from engine.terminal import RST, W_COOL, CLR, tw, th
|
from engine.effects import (
|
||||||
|
fade_line,
|
||||||
|
firehose_line,
|
||||||
|
glitch_bar,
|
||||||
|
next_headline,
|
||||||
|
noise,
|
||||||
|
vis_trunc,
|
||||||
|
)
|
||||||
from engine.render import big_wrap, lr_gradient, lr_gradient_opposite, make_block
|
from engine.render import big_wrap, lr_gradient, lr_gradient_opposite, make_block
|
||||||
from engine.effects import noise, glitch_bar, fade_line, vis_trunc, next_headline, firehose_line
|
from engine.terminal import CLR, RST, W_COOL, th, tw
|
||||||
|
|
||||||
|
|
||||||
def stream(items, ntfy_poller, mic_monitor):
|
def stream(items, ntfy_poller, mic_monitor):
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ No internal dependencies.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# ─── ANSI ─────────────────────────────────────────────────
|
# ─── ANSI ─────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ Google Translate wrapper and location→language detection.
|
|||||||
Depends on: sources (for LOCATION_LANGS).
|
Depends on: sources (for LOCATION_LANGS).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
import urllib.request
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
from engine.sources import LOCATION_LANGS
|
from engine.sources import LOCATION_LANGS
|
||||||
|
|
||||||
|
|||||||
@@ -14,21 +14,25 @@ class TestTerminalDimensions:
|
|||||||
|
|
||||||
def test_tw_returns_columns(self):
|
def test_tw_returns_columns(self):
|
||||||
"""tw() returns terminal width."""
|
"""tw() returns terminal width."""
|
||||||
with patch.object(sys.stdout, "isatty", return_value=True):
|
with (
|
||||||
with patch("os.get_terminal_size") as mock_size:
|
patch.object(sys.stdout, "isatty", return_value=True),
|
||||||
mock_size.return_value = io.StringIO("columns=120")
|
patch("os.get_terminal_size") as mock_size,
|
||||||
mock_size.columns = 120
|
):
|
||||||
result = terminal.tw()
|
mock_size.return_value = io.StringIO("columns=120")
|
||||||
assert isinstance(result, int)
|
mock_size.columns = 120
|
||||||
|
result = terminal.tw()
|
||||||
|
assert isinstance(result, int)
|
||||||
|
|
||||||
def test_th_returns_lines(self):
|
def test_th_returns_lines(self):
|
||||||
"""th() returns terminal height."""
|
"""th() returns terminal height."""
|
||||||
with patch.object(sys.stdout, "isatty", return_value=True):
|
with (
|
||||||
with patch("os.get_terminal_size") as mock_size:
|
patch.object(sys.stdout, "isatty", return_value=True),
|
||||||
mock_size.return_value = io.StringIO("lines=30")
|
patch("os.get_terminal_size") as mock_size,
|
||||||
mock_size.lines = 30
|
):
|
||||||
result = terminal.th()
|
mock_size.return_value = io.StringIO("lines=30")
|
||||||
assert isinstance(result, int)
|
mock_size.lines = 30
|
||||||
|
result = terminal.th()
|
||||||
|
assert isinstance(result, int)
|
||||||
|
|
||||||
def test_tw_fallback_on_error(self):
|
def test_tw_fallback_on_error(self):
|
||||||
"""tw() falls back to 80 on error."""
|
"""tw() falls back to 80 on error."""
|
||||||
@@ -84,9 +88,11 @@ class TestTypeOut:
|
|||||||
@patch("time.sleep")
|
@patch("time.sleep")
|
||||||
def test_type_out_uses_color(self, mock_sleep):
|
def test_type_out_uses_color(self, mock_sleep):
|
||||||
"""type_out applies color codes."""
|
"""type_out applies color codes."""
|
||||||
with patch("sys.stdout", new_callable=io.StringIO):
|
with (
|
||||||
with patch("random.random", return_value=0.5):
|
patch("sys.stdout", new_callable=io.StringIO),
|
||||||
terminal.type_out("Test", color=terminal.G_HI)
|
patch("random.random", return_value=0.5),
|
||||||
|
):
|
||||||
|
terminal.type_out("Test", color=terminal.G_HI)
|
||||||
|
|
||||||
|
|
||||||
class TestSlowPrint:
|
class TestSlowPrint:
|
||||||
|
|||||||
Reference in New Issue
Block a user