From a48b3a0a61785a3e039ee38358a90285ca18d5df Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Fri, 23 Feb 2024 15:37:51 -0500 Subject: [PATCH] Ruff checks --- invokeai/app/api/routers/model_manager.py | 7 ++++++- invokeai/backend/model_manager/search.py | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/invokeai/app/api/routers/model_manager.py b/invokeai/app/api/routers/model_manager.py index f57f5f97b63..cc8d4ae6fef 100644 --- a/invokeai/app/api/routers/model_manager.py +++ b/invokeai/app/api/routers/model_manager.py @@ -248,8 +248,13 @@ async def list_tags() -> Set[str]: async def scan_for_models( scan_path: str = Query(description="Directory path to search for models", default=None), ) -> List[pathlib.Path]: + if not scan_path: + raise HTTPException( + status_code=400, + detail=f"The search path '{scan_path}' does not exist or is not directory", + ) path = pathlib.Path(scan_path) - if not scan_path or not path.is_dir(): + if not path.is_dir(): raise HTTPException( status_code=400, detail=f"The search path '{scan_path}' does not exist or is not directory", diff --git a/invokeai/backend/model_manager/search.py b/invokeai/backend/model_manager/search.py index 330cff4e08c..ff2e7a1a5bd 100644 --- a/invokeai/backend/model_manager/search.py +++ b/invokeai/backend/model_manager/search.py @@ -25,10 +25,10 @@ def find_main_models(model: Path) -> bool: from logging import Logger from pathlib import Path from typing import Callable, Optional, Set, Union -from invokeai.app.services.config import InvokeAIAppConfig from pydantic import BaseModel, Field +from invokeai.app.services.config import InvokeAIAppConfig from invokeai.backend.util.logging import InvokeAILogger default_logger: Logger = InvokeAILogger.get_logger() @@ -167,15 +167,15 @@ def _walk_directory(self, path: Union[Path, str], max_depth: int = 20) -> None: ): try: self.model_found(absolute_path) + return except KeyboardInterrupt: raise except Exception as e: self.logger.warning(str(e)) - finally: return for n in file_names: - if any([n.endswith(suffix) for suffix in {".ckpt", ".bin", ".pth", ".safetensors", ".pt"}]): + if n.endswith((".ckpt", ".bin", ".pth", ".safetensors", ".pt")): try: self.model_found(absolute_path / n) except KeyboardInterrupt: