mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 19:47:12 +01:00
The last python file over the 250-line cap. Now that it sits at 100% line
and branch coverage, split along its natural seams:
_types.py 48 the three dataclasses, so nothing imports a sibling
merely to name a type (which would have made a cycle)
_render.py 69 the ANSI palette and the printers
_config_io.py 104 variant discovery, JSONC parsing, reads and writes
_hardware.py 106 _run and the four probes
_plan.py 156 the pure hardware -> proposed-changes functions
_optimize.py 100 the CLI entry: _apply_variant and main
Definitions were moved by line range rather than retyped. A throwaway
ast.dump identity check against HEAD confirms all 26 top-level definitions
are unchanged - formatting-blind, logic-sensitive.
The first attempt raised NameError: name '_BO' is not defined at runtime;
_BO was used by main() but missing from the _render import list. Rather than
fix that one failure alone, an AST scan over all six modules for names used
but not bound confirmed nothing else was missing.
Test imports now name the owning module; no re-export barrels. One patch
target genuinely moved - the guard-rail test patches _config_io.Path, since
that is the namespace resolving the name when _discover_variants is called
directly rather than through main().
Verified: same 98 tests pass with every module at 100% line and branch;
python3 -m python_pkg.vscode_optimizer --dry-run reproduces the same
18-change plan and writes nothing; repo-wide pytest 1846 passed at 100%;
over-cap files 36 -> 35.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
"""Render the hardware summary and the optimization plan to the terminal.
|
|
|
|
The only module that owns the ANSI colour codes, so changing the palette
|
|
touches one file.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from python_pkg.vscode_optimizer._types import _Hw, _Opt
|
|
|
|
_MIB_1024 = 1024
|
|
_B = "\033[94m"
|
|
_G = "\033[92m"
|
|
_Y = "\033[93m"
|
|
_C = "\033[96m"
|
|
_BO = "\033[1m"
|
|
_R = "\033[0m"
|
|
|
|
|
|
def _out(text: str = "") -> None:
|
|
"""Write a line to stdout."""
|
|
sys.stdout.write(text + "\n")
|
|
|
|
|
|
def _hdr(text: str) -> None:
|
|
_out(f"\n{_BO}{_B}{'─' * 60}{_R}\n{_BO}{_B} {text}{_R}\n{_BO}{_B}{'─' * 60}{_R}")
|
|
|
|
|
|
def _show_hw(hw: _Hw) -> None:
|
|
_hdr("Detected Hardware")
|
|
_out(f" {_C}CPU{_R} {hw.cpu_model}")
|
|
_out(
|
|
f" {hw.cpu_physical_cores} cores / {hw.cpu_logical_cores} threads"
|
|
f" @ {hw.cpu_max_mhz:.0f} MHz"
|
|
)
|
|
_out(f" {_C}RAM{_R} {hw.ram_total_mb // _MIB_1024} GB")
|
|
gpu = f" {_C}GPU{_R} {hw.gpu_vendor} - {hw.gpu_model}"
|
|
if hw.gpu_vram_mb:
|
|
gpu += f" ({hw.gpu_vram_mb} MB VRAM)"
|
|
_out(gpu)
|
|
_out(f" {_C}Disk{_R} {hw.disk_type.upper()}")
|
|
|
|
|
|
def _show_plan(opts: list[_Opt], new_fl: list[str], old_fl: list[str]) -> None:
|
|
_hdr("Optimization Plan")
|
|
added = [f for f in new_fl if f not in old_fl]
|
|
if added:
|
|
_out(f"\n {_BO}Electron flags to add:{_R}")
|
|
for fl in added:
|
|
_out(f" {_G}+ {fl}{_R}")
|
|
elif new_fl:
|
|
_out(f"\n {_Y}Electron GPU flags already present{_R}")
|
|
if opts:
|
|
_out(f"\n {_BO}Settings to change:{_R}")
|
|
for i, o in enumerate(opts, 1):
|
|
c = json.dumps(o.current)[:55] if o.current is not None else "-"
|
|
v = json.dumps(o.value)[:55]
|
|
_out(f"\n {_BO}{i}. {o.key}{_R}\n {o.reason}")
|
|
_out(f" {_Y}{c}{_R} -> {_G}{v}{_R}")
|
|
else:
|
|
_out(f"\n {_G}All settings already optimized{_R}")
|
|
total = len(opts) + len(added)
|
|
if total:
|
|
_out(f"\n {_BO}{total} change(s) proposed.{_R}")
|