Add ahead-of-time compilation for cli and optimize thumbnail caching
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 46s
Python / lint-format (pull_request) Successful in 49s
Python / test (pull_request) Successful in 47s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m42s
C++ / build (pull_request) Successful in 3m7s

This commit is contained in:
2026-07-08 12:23:45 +02:00
parent ffefd3e202
commit 6d5609fe5b
7 changed files with 97 additions and 31 deletions
+16 -11
View File
@@ -1,9 +1,11 @@
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from importlib.resources import files
from importlib.resources.abc import Traversable
from pathlib import PurePosixPath
ASSETS = Path(__file__).resolve().parent.parent / "assets" / "schemes"
ASSETS: Traversable = files("zshell") / "assets" / "schemes"
@dataclass(frozen=True)
@@ -30,7 +32,7 @@ class Palette:
accent: str | None = None
def _parse_txt(path: Path) -> dict[str, str]:
def _parse_txt(path: Traversable) -> dict[str, str]:
colors: dict[str, str] = {}
for line in path.read_text().splitlines():
line = line.strip()
@@ -46,7 +48,7 @@ def _parse_txt(path: Path) -> dict[str, str]:
def _discover_schemes() -> dict[str, SchemeMeta]:
schemes: dict[str, SchemeMeta] = {}
for scheme_dir in sorted(ASSETS.iterdir()):
for scheme_dir in sorted(ASSETS.iterdir(), key=lambda p: p.name):
if not scheme_dir.is_dir() or scheme_dir.name.startswith("."):
continue
@@ -54,7 +56,7 @@ def _discover_schemes() -> dict[str, SchemeMeta]:
display_name = sid.capitalize()
variants: list[SchemeVariant] = []
for var_dir in sorted(scheme_dir.iterdir()):
for var_dir in sorted(scheme_dir.iterdir(), key=lambda p: p.name):
if not var_dir.is_dir() or var_dir.name.startswith("."):
continue
@@ -62,9 +64,10 @@ def _discover_schemes() -> dict[str, SchemeMeta]:
accents: set[str] = set()
for f in var_dir.iterdir():
if f.suffix != ".txt":
name = PurePosixPath(f.name)
if name.suffix != ".txt":
continue
stem = f.stem
stem = name.stem
if "-" in stem:
maybe_accent, maybe_mode = stem.rsplit("-", 1)
if maybe_mode in ("dark", "light"):
@@ -101,12 +104,14 @@ SCHEMES: dict[str, SchemeMeta] = _discover_schemes()
def get_palette(scheme: str, variant: str, mode: str, accent: str | None = None) -> Palette:
if scheme not in SCHEMES:
raise KeyError(f"Unknown scheme '{scheme}'. Available: {', '.join(SCHEMES)}")
raise KeyError(
f"Unknown scheme '{scheme}'. Available: {', '.join(SCHEMES)}")
meta = SCHEMES[scheme]
var_ids = {v.id for v in meta.variants}
if variant not in var_ids:
raise KeyError(f"Unknown variant '{variant}' for scheme '{scheme}'. Available: {', '.join(sorted(var_ids))}")
raise KeyError(
f"Unknown variant '{variant}' for scheme '{scheme}'. Available: {', '.join(sorted(var_ids))}")
if accent:
filename = f"{accent}-{mode}.txt"
@@ -114,10 +119,10 @@ def get_palette(scheme: str, variant: str, mode: str, accent: str | None = None)
filename = f"{mode}.txt"
txt_path = ASSETS / scheme / variant / filename
if not txt_path.exists():
if not txt_path.is_file():
txt_path = ASSETS / scheme / variant / f"{mode}.txt"
if not txt_path.exists():
if not txt_path.is_file():
var_info = next(v for v in meta.variants if v.id == variant)
raise FileNotFoundError(
f"No {mode} palette for '{scheme}:{variant}'. Available modes: {sorted(var_info.modes)}"