From fd4658434a4bd833d94064f49ad1056b79db4f81 Mon Sep 17 00:00:00 2001 From: Frank Schwenk Date: Sat, 18 Jul 2026 17:34:18 +0200 Subject: [PATCH] refactor: clarify module bootstrap and G'MIC output handling Import all built-in modules explicitly, remove dead ImageMagick branch, and call finalize_gmic_output in gmic_grayscale for resume parity with gmic. Co-authored-by: Cursor --- imagepipeline/core/pipeline.py | 17 +++++------------ imagepipeline/modules/gmic_grayscale.py | 3 ++- imagepipeline/modules/imagemagick_grayscale.py | 7 +------ 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/imagepipeline/core/pipeline.py b/imagepipeline/core/pipeline.py index 8bcf516..f841671 100644 --- a/imagepipeline/core/pipeline.py +++ b/imagepipeline/core/pipeline.py @@ -4,14 +4,13 @@ from collections import defaultdict from pathlib import Path from typing import Any +# Register all built-in modules (side effect of submodule imports). +import imagepipeline.modules # noqa: F401 from imagepipeline.core.exceptions import ValidationError from imagepipeline.core.runner import PipelineRunner from imagepipeline.core.step import INPUT_SOURCE, StepDefinition, StepRef from imagepipeline.modules.registry import get_module -# Import built-in modules so they register on package load. -import imagepipeline.modules.imagemagick_grayscale # noqa: F401 - class Pipeline: """Define and run an image processing pipeline.""" @@ -61,9 +60,7 @@ class Pipeline: input_refs = self._normalize_inputs(inputs) reserved = {"inputs", "input"} if reserved & set(params): - raise ValidationError( - "Do not pass 'inputs' or 'input' as module parameters" - ) + raise ValidationError("Do not pass 'inputs' or 'input' as module parameters") definition = StepDefinition( step_id=step_id, @@ -97,9 +94,7 @@ class Pipeline: def output_root(self) -> Path | None: return self._output_root - def _normalize_inputs( - self, inputs: StepRef | str | list[StepRef | str] - ) -> list[str]: + def _normalize_inputs(self, inputs: StepRef | str | list[StepRef | str]) -> list[str]: if isinstance(inputs, list): if not inputs: raise ValidationError("inputs must not be an empty list") @@ -110,9 +105,7 @@ class Pipeline: if not step_id: raise ValidationError("step_id must not be empty") if "/" in step_id or "\\" in step_id: - raise ValidationError( - f"step_id must not contain path separators: {step_id!r}" - ) + raise ValidationError(f"step_id must not contain path separators: {step_id!r}") if any(step.step_id == step_id for step in self._steps): raise ValidationError(f"Duplicate step_id: {step_id!r}") diff --git a/imagepipeline/modules/gmic_grayscale.py b/imagepipeline/modules/gmic_grayscale.py index 3561afe..6a673f6 100644 --- a/imagepipeline/modules/gmic_grayscale.py +++ b/imagepipeline/modules/gmic_grayscale.py @@ -4,7 +4,7 @@ from imagepipeline.core.context import ModuleContext from imagepipeline.core.params import Param from imagepipeline.modules.base import SubprocessModule from imagepipeline.modules.registry import register -from imagepipeline.utils.gmic import split_gmic_command +from imagepipeline.utils.gmic import finalize_gmic_output, split_gmic_command from imagepipeline.utils.subprocess import run_command @@ -35,3 +35,4 @@ class GmicGrayscale(SubprocessModule): dst = ctx.output_dir / src.name cmd = ["gmic", str(src), *split_gmic_command(gmic_command), "-output", str(dst)] run_command(cmd, timeout=self.default_timeout) + finalize_gmic_output(ctx.output_dir, dst) diff --git a/imagepipeline/modules/imagemagick_grayscale.py b/imagepipeline/modules/imagemagick_grayscale.py index aec0e75..ae741d9 100644 --- a/imagepipeline/modules/imagemagick_grayscale.py +++ b/imagepipeline/modules/imagemagick_grayscale.py @@ -1,7 +1,5 @@ from __future__ import annotations -from pathlib import Path - from imagepipeline.core.context import ModuleContext from imagepipeline.core.params import Param from imagepipeline.modules.base import SubprocessModule @@ -34,8 +32,5 @@ class ImageMagickGrayscale(SubprocessModule): for index, src in enumerate(ctx.input_paths, start=1): self.log_image(ctx, index, total, src) dst = ctx.output_dir / src.name - if command == "magick": - cmd = [command, str(src), "-colorspace", colorspace, str(dst)] - else: - cmd = [command, str(src), "-colorspace", colorspace, str(dst)] + cmd = [command, str(src), "-colorspace", colorspace, str(dst)] run_command(cmd)