Cleanup/code quality #1

Merged
froxxxy merged 9 commits from cleanup/code-quality into main 2026-07-18 17:26:22 +02:00
4 changed files with 28 additions and 18 deletions
Showing only changes of commit 0963297815 - Show all commits
+6
View File
@@ -16,9 +16,15 @@ __pycache__/
*.pyc
*.pyo
.venv/
.venv-*/
*.egg-info/
dist/
build/
.pytest_cache/
.mypy_cache/
.ruff_cache/
htmlcov/
.coverage
# OS / editor noise
.DS_Store
+5 -3
View File
@@ -92,9 +92,11 @@ def job_detail(request: Request, job_id: str) -> HTMLResponse:
paths = pipeline.job_paths(stem)
status = pipeline.read_status(stem) or {}
manifest = pipeline.read_manifest(stem) or {"variants": []}
intermediates = sorted(
p.name for p in paths.intermediates.glob(f"{stem}_*.png") if p.is_file()
) if paths.intermediates.exists() else []
intermediates = (
sorted(p.name for p in paths.intermediates.glob(f"{stem}_*.png") if p.is_file())
if paths.intermediates.exists()
else []
)
return templates.TemplateResponse(
"job.html",
+16 -12
View File
@@ -17,11 +17,12 @@ import subprocess
import sys
import time
import uuid
from collections.abc import Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import datetime, timezone
from datetime import UTC, datetime
from pathlib import Path
from typing import Any, Iterator
from typing import Any
from . import config
@@ -125,7 +126,9 @@ def load_assets() -> FilterAssets:
if not bg_names or not fg_names:
raise PipelineError("Keine gueltigen Filter in background/foreground Listen")
return FilterAssets(background_names=bg_names, foreground_names=fg_names, blend_modes=blend_modes, commands=commands)
return FilterAssets(
background_names=bg_names, foreground_names=fg_names, blend_modes=blend_modes, commands=commands
)
def run_gmic(args: list[str], output_image: Path) -> tuple[bool, str, float]:
@@ -167,7 +170,9 @@ def apply_filter(image: Path, full_command: str, output_image: Path) -> tuple[bo
return ok, err
def apply_filter_chain(image: Path, commands: tuple[str, ...], output_image: Path, tmp_dir: Path, prefix: str) -> tuple[bool, str]:
def apply_filter_chain(
image: Path, commands: tuple[str, ...], output_image: Path, tmp_dir: Path, prefix: str
) -> tuple[bool, str]:
current = image
for i, command in enumerate(commands):
target = output_image if i == len(commands) - 1 else tmp_dir / f"{prefix}_post_{i}.png"
@@ -178,11 +183,6 @@ def apply_filter_chain(image: Path, commands: tuple[str, ...], output_image: Pat
return True, ""
def blend_layers(base: Path, overlay: Path, mode: str, output_image: Path) -> tuple[bool, str]:
ok, err, _ = run_gmic([str(base), str(overlay), "blend", f"{mode},{config.BLEND_OPACITY}"], output_image)
return ok, err
def blend_layers_opacity(base: Path, overlay: Path, mode: str, opacity: str, output_image: Path) -> tuple[bool, str]:
ok, err, _ = run_gmic([str(base), str(overlay), "blend", f"{mode},{opacity}"], output_image)
return ok, err
@@ -297,7 +297,7 @@ def pick_working_filter(
def now_iso() -> str:
return datetime.now(timezone.utc).isoformat(timespec="seconds")
return datetime.now(UTC).isoformat(timespec="seconds")
_UNSAFE_STEM_RE = re.compile(r"[^\w.\-]+", re.UNICODE)
@@ -483,14 +483,18 @@ def compose_variant(
if not bg_command:
raise PipelineError(f"Unbekannter Background-Filter: {bg_name}")
else:
bg_name, bg_command = pick_working_filter(assets.background_names, assets.commands, paths.original, tmp_dir, "bg", rng)
bg_name, bg_command = pick_working_filter(
assets.background_names, assets.commands, paths.original, tmp_dir, "bg", rng
)
if fg_name:
fg_command = assets.commands.get(fg_name)
if not fg_command:
raise PipelineError(f"Unbekannter Foreground-Filter: {fg_name}")
else:
fg_name, fg_command = pick_working_filter(assets.foreground_names, assets.commands, paths.rembg, tmp_dir, "fg", rng)
fg_name, fg_command = pick_working_filter(
assets.foreground_names, assets.commands, paths.rembg, tmp_dir, "fg", rng
)
p = {
"bg_filtered": tmp_dir / f"{prefix}_bg_filtered.png",
+1 -3
View File
@@ -70,9 +70,7 @@ def _is_ignored_name(name: str) -> bool:
"""Skip Syncthing metadata/temp files and other dotfiles."""
if name.startswith("."):
return True
if name.startswith(".syncthing.") or ".syncthing." in name:
return True
return False
return bool(name.startswith(".syncthing.") or ".syncthing." in name)
def _is_stable(path: Path) -> bool: