From bf209663acadb695fa95787e16018bed970e34d2 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:37:10 +1000 Subject: [PATCH] tidy(app): make workflow thumbnails base class an ABC, move it to own file --- .../workflow_thumbnails_base.py | 28 +++++++++++++++++++ .../workflow_thumbnails_common.py | 25 ----------------- .../workflow_thumbnails_disk.py | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 invokeai/app/services/workflow_thumbnails/workflow_thumbnails_base.py diff --git a/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_base.py b/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_base.py new file mode 100644 index 0000000000..f2674dd3b7 --- /dev/null +++ b/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_base.py @@ -0,0 +1,28 @@ +from abc import ABC, abstractmethod +from pathlib import Path + +from PIL import Image + + +class WorkflowThumbnailServiceBase(ABC): + """Base class for workflow thumbnail services""" + + @abstractmethod + def get_path(self, workflow_id: str) -> Path: + """Gets the path to a workflow thumbnail""" + pass + + @abstractmethod + def get_url(self, workflow_id: str) -> str | None: + """Gets the URL of a workflow thumbnail""" + pass + + @abstractmethod + def save(self, workflow_id: str, image: Image.Image) -> None: + """Saves a workflow thumbnail""" + pass + + @abstractmethod + def delete(self, workflow_id: str) -> None: + """Deletes a workflow thumbnail""" + pass diff --git a/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_common.py b/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_common.py index 25174fdca4..8d124adec3 100644 --- a/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_common.py +++ b/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_common.py @@ -1,8 +1,3 @@ -from pathlib import Path - -from PIL import Image - - class WorkflowThumbnailFileNotFoundException(Exception): """Raised when a workflow thumbnail file is not found""" @@ -25,23 +20,3 @@ class WorkflowThumbnailFileDeleteException(Exception): def __init__(self, message: str = "Workflow thumbnail file cannot be deleted"): self.message = message super().__init__(self.message) - - -class WorkflowThumbnailServiceBase: - """Base class for workflow thumbnail services""" - - def get_path(self, workflow_id: str) -> Path: - """Gets the path to a workflow thumbnail""" - raise NotImplementedError - - def get_url(self, workflow_id: str) -> str | None: - """Gets the URL of a workflow thumbnail""" - raise NotImplementedError - - def save(self, workflow_id: str, image: Image.Image) -> None: - """Saves a workflow thumbnail""" - raise NotImplementedError - - def delete(self, workflow_id: str) -> None: - """Deletes a workflow thumbnail""" - raise NotImplementedError diff --git a/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_disk.py b/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_disk.py index 39e53e29a2..4e10456e26 100644 --- a/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_disk.py +++ b/invokeai/app/services/workflow_thumbnails/workflow_thumbnails_disk.py @@ -4,11 +4,11 @@ from PIL import Image from PIL.Image import Image as PILImageType from invokeai.app.services.invoker import Invoker +from invokeai.app.services.workflow_thumbnails.workflow_thumbnails_base import WorkflowThumbnailServiceBase from invokeai.app.services.workflow_thumbnails.workflow_thumbnails_common import ( WorkflowThumbnailFileDeleteException, WorkflowThumbnailFileNotFoundException, WorkflowThumbnailFileSaveException, - WorkflowThumbnailServiceBase, ) from invokeai.app.util.misc import uuid_string from invokeai.app.util.thumbnails import make_thumbnail