style: apply ruff format and extend gitignore
Ruff auto-fixes import order and line wrapping. Gitignore covers build artifacts and coverage output from future test runs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,9 +16,15 @@ __pycache__/
|
|||||||
*.pyc
|
*.pyc
|
||||||
*.pyo
|
*.pyo
|
||||||
.venv/
|
.venv/
|
||||||
|
.venv-*/
|
||||||
|
*.egg-info/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
.ruff_cache/
|
.ruff_cache/
|
||||||
|
htmlcov/
|
||||||
|
.coverage
|
||||||
|
|
||||||
# OS / editor noise
|
# OS / editor noise
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
+5
-3
@@ -92,9 +92,11 @@ def job_detail(request: Request, job_id: str) -> HTMLResponse:
|
|||||||
paths = pipeline.job_paths(stem)
|
paths = pipeline.job_paths(stem)
|
||||||
status = pipeline.read_status(stem) or {}
|
status = pipeline.read_status(stem) or {}
|
||||||
manifest = pipeline.read_manifest(stem) or {"variants": []}
|
manifest = pipeline.read_manifest(stem) or {"variants": []}
|
||||||
intermediates = sorted(
|
intermediates = (
|
||||||
p.name for p in paths.intermediates.glob(f"{stem}_*.png") if p.is_file()
|
sorted(p.name for p in paths.intermediates.glob(f"{stem}_*.png") if p.is_file())
|
||||||
) if paths.intermediates.exists() else []
|
if paths.intermediates.exists()
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"job.html",
|
"job.html",
|
||||||
|
|||||||
+16
-12
@@ -17,11 +17,12 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
from collections.abc import Iterator
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timezone
|
from datetime import UTC, datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Iterator
|
from typing import Any
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
@@ -125,7 +126,9 @@ def load_assets() -> FilterAssets:
|
|||||||
if not bg_names or not fg_names:
|
if not bg_names or not fg_names:
|
||||||
raise PipelineError("Keine gueltigen Filter in background/foreground Listen")
|
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]:
|
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
|
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
|
current = image
|
||||||
for i, command in enumerate(commands):
|
for i, command in enumerate(commands):
|
||||||
target = output_image if i == len(commands) - 1 else tmp_dir / f"{prefix}_post_{i}.png"
|
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, ""
|
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]:
|
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)
|
ok, err, _ = run_gmic([str(base), str(overlay), "blend", f"{mode},{opacity}"], output_image)
|
||||||
return ok, err
|
return ok, err
|
||||||
@@ -297,7 +297,7 @@ def pick_working_filter(
|
|||||||
|
|
||||||
|
|
||||||
def now_iso() -> str:
|
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)
|
_UNSAFE_STEM_RE = re.compile(r"[^\w.\-]+", re.UNICODE)
|
||||||
@@ -483,14 +483,18 @@ def compose_variant(
|
|||||||
if not bg_command:
|
if not bg_command:
|
||||||
raise PipelineError(f"Unbekannter Background-Filter: {bg_name}")
|
raise PipelineError(f"Unbekannter Background-Filter: {bg_name}")
|
||||||
else:
|
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:
|
if fg_name:
|
||||||
fg_command = assets.commands.get(fg_name)
|
fg_command = assets.commands.get(fg_name)
|
||||||
if not fg_command:
|
if not fg_command:
|
||||||
raise PipelineError(f"Unbekannter Foreground-Filter: {fg_name}")
|
raise PipelineError(f"Unbekannter Foreground-Filter: {fg_name}")
|
||||||
else:
|
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 = {
|
p = {
|
||||||
"bg_filtered": tmp_dir / f"{prefix}_bg_filtered.png",
|
"bg_filtered": tmp_dir / f"{prefix}_bg_filtered.png",
|
||||||
|
|||||||
+1
-3
@@ -70,9 +70,7 @@ def _is_ignored_name(name: str) -> bool:
|
|||||||
"""Skip Syncthing metadata/temp files and other dotfiles."""
|
"""Skip Syncthing metadata/temp files and other dotfiles."""
|
||||||
if name.startswith("."):
|
if name.startswith("."):
|
||||||
return True
|
return True
|
||||||
if name.startswith(".syncthing.") or ".syncthing." in name:
|
return bool(name.startswith(".syncthing.") or ".syncthing." in name)
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _is_stable(path: Path) -> bool:
|
def _is_stable(path: Path) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user