mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 16:03:03 +02:00
Split 18+ Python files that exceeded 500 lines into smaller modules with helper files (prefixed with _). All functions are re-exported from the original modules to maintain backward compatibility with test patches and external imports. Files split: - moviepy_showcase.py (1212 -> 302 + 3 helpers) - anki_generator.py (1174 -> 473 + 4 helpers) - test_analyze_chess_game.py (1152 -> 361 + 2 parts) - poker_modifier_app.py (1024 -> 263 + 2 helpers) - transcribe_fw.py (1007 -> 342 + 3 helpers) - music_generator.py (1002 -> 319 + 2 helpers) - translator.py (951 -> 442 + 2 helpers) - cinema_planner.py (893 -> 369 + 2 helpers) - lichess_bot/main.py (757 -> 495 + _game_logic.py) - test_translator.py (725 -> 289 + part2 + conftest) - test_lichess_api.py (680 -> 475 + part2) - learning_pipe.py (668 -> 375 + 2 helpers) - cache.py (655 -> 360 + _cache_decks.py) - analyze_chess_game.py (632 -> 463 + _move_analysis.py) - visualize_q02.py (609 -> 371 + helper) - repo_explorer.py (602 -> 347 + 2 helpers) - keyboard_coop/main.py (515 -> 416 + _dictionary.py) - scanning.py (501 -> 314 + _enforce_loop.py) All tests pass: 144 lichess_bot (100% branch coverage), 243 others. No new lint errors introduced.
96 lines
2.7 KiB
Python
96 lines
2.7 KiB
Python
"""Project discovery helpers and shared constants for Repo Explorer."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
from typing import cast
|
|
|
|
# Strip ANSI/VT100 escape sequences so the Text widget shows plain text
|
|
_ANSI_ESCAPE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
|
|
|
|
|
|
def _strip_ansi(text: str) -> str:
|
|
return _ANSI_ESCAPE.sub("", text)
|
|
|
|
|
|
def _find_terminal() -> list[str]:
|
|
"""Return argv prefix for the first available terminal emulator."""
|
|
candidates = [
|
|
("kitty", ["kitty", "--"]),
|
|
("alacritty", ["alacritty", "-e"]),
|
|
("konsole", ["konsole", "-e"]),
|
|
("gnome-terminal", ["gnome-terminal", "--"]),
|
|
("xfce4-terminal", ["xfce4-terminal", "-x"]),
|
|
("xterm", ["xterm", "-e"]),
|
|
]
|
|
for exe, args in candidates:
|
|
if shutil.which(exe):
|
|
return args
|
|
return []
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
|
|
|
|
IGNORED_DIRS = {
|
|
".git",
|
|
".venv",
|
|
"__pycache__",
|
|
"node_modules",
|
|
"build",
|
|
"target",
|
|
".mypy_cache",
|
|
".ruff_cache",
|
|
}
|
|
|
|
|
|
def _is_ignored(path: Path) -> bool:
|
|
return any(part in IGNORED_DIRS for part in path.parts)
|
|
|
|
|
|
def find_projects(root: Path) -> list[dict[str, object]]:
|
|
"""Return every directory under *root* that contains a run.sh."""
|
|
projects: list[dict[str, object]] = []
|
|
for run_sh in sorted(root.rglob("run.sh")):
|
|
if _is_ignored(run_sh):
|
|
continue
|
|
proj_dir = run_sh.parent
|
|
rel = proj_dir.relative_to(root)
|
|
projects.append({"path": proj_dir, "rel": rel, "name": proj_dir.name})
|
|
return projects
|
|
|
|
|
|
def _desc_from_run_sh(run_sh: Path) -> str:
|
|
"""Extract leading comment block from run.sh as a description."""
|
|
comments: list[str] = []
|
|
for line in run_sh.read_text(errors="replace").splitlines():
|
|
s = line.strip()
|
|
if s.startswith("#!"):
|
|
continue
|
|
if s.startswith("#"):
|
|
comments.append(s[1:].strip())
|
|
elif comments:
|
|
break
|
|
return " ".join(comments)[:300] if comments else ""
|
|
|
|
|
|
def get_description(project_path: Path) -> str:
|
|
"""Return a short description from README.md or leading run.sh comments."""
|
|
for readme_name in ("README.md", "README.txt", "readme.md"):
|
|
readme = project_path / readme_name
|
|
if readme.exists():
|
|
text = readme.read_text(errors="replace")
|
|
for line in text.splitlines():
|
|
stripped = line.strip().lstrip("#").strip()
|
|
if stripped:
|
|
return cast("str", stripped[:300])
|
|
|
|
run_sh = project_path / "run.sh"
|
|
if run_sh.exists():
|
|
desc = _desc_from_run_sh(run_sh)
|
|
if desc:
|
|
return desc
|
|
|
|
return "(no description)"
|