From 5615c317991bf6c0e4083e197e875992af1e92d8 Mon Sep 17 00:00:00 2001 From: Martin Kristiansen Date: Fri, 18 Aug 2023 10:57:18 -0400 Subject: [PATCH] isort wip --- invokeai/app/api/dependencies.py | 16 ++++----- invokeai/app/api/routers/images.py | 9 ++--- invokeai/app/api/routers/models.py | 8 ++--- invokeai/app/api/routers/sessions.py | 8 +---- invokeai/app/cli/commands.py | 10 +++--- invokeai/app/cli/completer.py | 6 ++-- invokeai/app/invocations/compel.py | 5 ++- .../controlnet_image_processors.py | 4 +-- invokeai/app/invocations/cv.py | 2 +- invokeai/app/invocations/onnx.py | 2 +- invokeai/app/invocations/param_easing.py | 1 - invokeai/app/invocations/upscale.py | 2 +- .../services/board_image_record_storage.py | 7 ++-- invokeai/app/services/board_images.py | 7 ++-- invokeai/app/services/board_record_storage.py | 10 +++--- invokeai/app/services/boards.py | 13 ++----- invokeai/app/services/default_graphs.py | 7 ++-- invokeai/app/services/events.py | 8 ++--- invokeai/app/services/image_record_storage.py | 6 +--- invokeai/app/services/images.py | 7 +--- invokeai/app/services/invocation_queue.py | 2 +- invokeai/app/services/invocation_services.py | 16 +++++---- invokeai/app/services/invocation_stats.py | 4 +-- invokeai/app/services/latent_storage.py | 2 +- .../app/services/model_manager_service.py | 35 ++++++++++--------- invokeai/app/services/models/board_record.py | 4 ++- invokeai/app/services/resource_name.py | 2 +- invokeai/app/util/controlnet_utils.py | 12 +++---- invokeai/app/util/misc.py | 1 + invokeai/app/util/model_exclude_null.py | 2 +- invokeai/app/util/step_callback.py | 8 +++-- invokeai/app/util/thumbnails.py | 1 + invokeai/frontend/install/import_images.py | 18 +++++----- invokeai/frontend/install/invokeai_update.py | 1 + invokeai/frontend/install/model_install.py | 25 ++++++------- invokeai/frontend/install/widgets.py | 11 +++--- invokeai/frontend/legacy_launch_invokeai.py | 2 +- invokeai/frontend/merge/merge_diffusers.py | 9 ++--- .../frontend/training/textual_inversion.py | 2 +- pyproject.toml | 4 +++ tests/nodes/test_graph_execution_state.py | 34 ++++++++---------- tests/nodes/test_invoker.py | 26 +++++++------- tests/nodes/test_node_graph.py | 21 ++++++++++- tests/nodes/test_nodes.py | 2 +- tests/nodes/test_sqlite.py | 3 +- tests/test_config.py | 3 +- tests/test_model_manager.py | 2 +- tests/test_path.py | 7 ++-- 48 files changed, 185 insertions(+), 212 deletions(-) diff --git a/invokeai/app/api/dependencies.py b/invokeai/app/api/dependencies.py index 39642df19b..3a54280234 100644 --- a/invokeai/app/api/dependencies.py +++ b/invokeai/app/api/dependencies.py @@ -1,13 +1,9 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) from logging import Logger -from invokeai.app.services.board_image_record_storage import ( - SqliteBoardImageRecordStorage, -) -from invokeai.app.services.board_images import ( - BoardImagesService, - BoardImagesServiceDependencies, -) + +from invokeai.app.services.board_image_record_storage import SqliteBoardImageRecordStorage +from invokeai.app.services.board_images import BoardImagesService, BoardImagesServiceDependencies from invokeai.app.services.board_record_storage import SqliteBoardRecordStorage from invokeai.app.services.boards import BoardService, BoardServiceDependencies from invokeai.app.services.config import InvokeAIAppConfig @@ -19,16 +15,16 @@ from invokeai.backend.util.logging import InvokeAILogger from invokeai.version.invokeai_version import __version__ from ..services.default_graphs import create_system_graphs -from ..services.latent_storage import DiskLatentsStorage, ForwardCacheLatentsStorage from ..services.graph import GraphExecutionState, LibraryGraph from ..services.image_file_storage import DiskImageFileStorage from ..services.invocation_queue import MemoryInvocationQueue from ..services.invocation_services import InvocationServices +from ..services.invocation_stats import InvocationStatsService from ..services.invoker import Invoker +from ..services.latent_storage import DiskLatentsStorage, ForwardCacheLatentsStorage +from ..services.model_manager_service import ModelManagerService from ..services.processor import DefaultInvocationProcessor from ..services.sqlite import SqliteItemStorage -from ..services.model_manager_service import ModelManagerService -from ..services.invocation_stats import InvocationStatsService from .events import FastAPIEventService diff --git a/invokeai/app/api/routers/images.py b/invokeai/app/api/routers/images.py index 72ce94e9cf..7e798a3658 100644 --- a/invokeai/app/api/routers/images.py +++ b/invokeai/app/api/routers/images.py @@ -1,20 +1,17 @@ import io from typing import Optional -from PIL import Image from fastapi import Body, HTTPException, Path, Query, Request, Response, UploadFile from fastapi.responses import FileResponse from fastapi.routing import APIRouter +from PIL import Image from pydantic import BaseModel, Field from invokeai.app.invocations.metadata import ImageMetadata from invokeai.app.models.image import ImageCategory, ResourceOrigin from invokeai.app.services.image_record_storage import OffsetPaginatedResults -from invokeai.app.services.models.image_record import ( - ImageDTO, - ImageRecordChanges, - ImageUrlsDTO, -) +from invokeai.app.services.models.image_record import ImageDTO, ImageRecordChanges, ImageUrlsDTO + from ..dependencies import ApiDependencies images_router = APIRouter(prefix="/v1/images", tags=["images"]) diff --git a/invokeai/app/api/routers/models.py b/invokeai/app/api/routers/models.py index b6c1edbbe1..276eda902d 100644 --- a/invokeai/app/api/routers/models.py +++ b/invokeai/app/api/routers/models.py @@ -2,7 +2,7 @@ import pathlib -from typing import Literal, List, Optional, Union +from typing import List, Literal, Optional, Union from fastapi import Body, Path, Query, Response from fastapi.routing import APIRouter @@ -10,13 +10,13 @@ from pydantic import BaseModel, parse_obj_as from starlette.exceptions import HTTPException from invokeai.backend import BaseModelType, ModelType +from invokeai.backend.model_management import MergeInterpolationMethod from invokeai.backend.model_management.models import ( OPENAPI_MODEL_CONFIGS, - SchedulerPredictionType, - ModelNotFoundException, InvalidModelException, + ModelNotFoundException, + SchedulerPredictionType, ) -from invokeai.backend.model_management import MergeInterpolationMethod from ..dependencies import ApiDependencies diff --git a/invokeai/app/api/routers/sessions.py b/invokeai/app/api/routers/sessions.py index d5624048e8..e950e46e9f 100644 --- a/invokeai/app/api/routers/sessions.py +++ b/invokeai/app/api/routers/sessions.py @@ -9,13 +9,7 @@ from pydantic.fields import Field # Importing * is bad karma but needed here for node detection from ...invocations import * # noqa: F401 F403 from ...invocations.baseinvocation import BaseInvocation -from ...services.graph import ( - Edge, - EdgeConnection, - Graph, - GraphExecutionState, - NodeAlreadyExecutedError, -) +from ...services.graph import Edge, EdgeConnection, Graph, GraphExecutionState, NodeAlreadyExecutedError from ...services.item_storage import PaginatedResults from ..dependencies import ApiDependencies diff --git a/invokeai/app/cli/commands.py b/invokeai/app/cli/commands.py index 64ea6034fc..b000abcf6a 100644 --- a/invokeai/app/cli/commands.py +++ b/invokeai/app/cli/commands.py @@ -1,16 +1,18 @@ # Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654) -from abc import ABC, abstractmethod import argparse +from abc import ABC, abstractmethod from typing import Any, Callable, Iterable, Literal, Union, get_args, get_origin, get_type_hints -from pydantic import BaseModel, Field -import networkx as nx + import matplotlib.pyplot as plt +import networkx as nx +from pydantic import BaseModel, Field import invokeai.backend.util.logging as logger + from ..invocations.baseinvocation import BaseInvocation from ..invocations.image import ImageField -from ..services.graph import GraphExecutionState, LibraryGraph, Edge +from ..services.graph import Edge, GraphExecutionState, LibraryGraph from ..services.invoker import Invoker diff --git a/invokeai/app/cli/completer.py b/invokeai/app/cli/completer.py index 086d8713d7..5aece8a058 100644 --- a/invokeai/app/cli/completer.py +++ b/invokeai/app/cli/completer.py @@ -6,15 +6,15 @@ completer object. import atexit import readline import shlex - from pathlib import Path -from typing import List, Dict, Literal, get_args, get_type_hints, get_origin +from typing import Dict, List, Literal, get_args, get_origin, get_type_hints import invokeai.backend.util.logging as logger + from ...backend import ModelManager from ..invocations.baseinvocation import BaseInvocation -from .commands import BaseCommand from ..services.invocation_services import InvocationServices +from .commands import BaseCommand # singleton object, class variable completer = None diff --git a/invokeai/app/invocations/compel.py b/invokeai/app/invocations/compel.py index 4557c57820..3fdbf9b6e9 100644 --- a/invokeai/app/invocations/compel.py +++ b/invokeai/app/invocations/compel.py @@ -5,16 +5,15 @@ from typing import List, Union import torch from compel import Compel, ReturnedEmbeddingsType from compel.prompt_parser import Blend, Conjunction, CrossAttentionControlSubstitute, FlattenedPrompt, Fragment -from invokeai.app.invocations.primitives import ConditioningField, ConditioningOutput +from invokeai.app.invocations.primitives import ConditioningField, ConditioningOutput from invokeai.backend.stable_diffusion.diffusion.shared_invokeai_diffusion import ( BasicConditioningInfo, SDXLConditioningInfo, ) -from ...backend.model_management.models import ModelType from ...backend.model_management.lora import ModelPatcher -from ...backend.model_management.models import ModelNotFoundException +from ...backend.model_management.models import ModelNotFoundException, ModelType from ...backend.stable_diffusion.diffusion import InvokeAIDiffuserComponent from ...backend.util.devices import torch_dtype from .baseinvocation import ( diff --git a/invokeai/app/invocations/controlnet_image_processors.py b/invokeai/app/invocations/controlnet_image_processors.py index 2c2eab9155..7f81c0bc7e 100644 --- a/invokeai/app/invocations/controlnet_image_processors.py +++ b/invokeai/app/invocations/controlnet_image_processors.py @@ -28,15 +28,14 @@ from pydantic import BaseModel, Field, validator from invokeai.app.invocations.primitives import ImageField, ImageOutput - from ...backend.model_management import BaseModelType from ..models.image import ImageCategory, ResourceOrigin from .baseinvocation import ( BaseInvocation, BaseInvocationOutput, FieldDescriptions, - InputField, Input, + InputField, InvocationContext, OutputField, UIType, @@ -44,7 +43,6 @@ from .baseinvocation import ( invocation_output, ) - CONTROLNET_MODE_VALUES = Literal["balanced", "more_prompt", "more_control", "unbalanced"] CONTROLNET_RESIZE_VALUES = Literal[ "just_resize", diff --git a/invokeai/app/invocations/cv.py b/invokeai/app/invocations/cv.py index 411aff8234..866b1c7894 100644 --- a/invokeai/app/invocations/cv.py +++ b/invokeai/app/invocations/cv.py @@ -4,8 +4,8 @@ import cv2 as cv import numpy from PIL import Image, ImageOps -from invokeai.app.invocations.primitives import ImageField, ImageOutput +from invokeai.app.invocations.primitives import ImageField, ImageOutput from invokeai.app.models.image import ImageCategory, ResourceOrigin from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation diff --git a/invokeai/app/invocations/onnx.py b/invokeai/app/invocations/onnx.py index d346a5f58f..213ce82a75 100644 --- a/invokeai/app/invocations/onnx.py +++ b/invokeai/app/invocations/onnx.py @@ -25,8 +25,8 @@ from .baseinvocation import ( BaseInvocation, BaseInvocationOutput, FieldDescriptions, - InputField, Input, + InputField, InvocationContext, OutputField, UIComponent, diff --git a/invokeai/app/invocations/param_easing.py b/invokeai/app/invocations/param_easing.py index 9cfe447372..7c327a6657 100644 --- a/invokeai/app/invocations/param_easing.py +++ b/invokeai/app/invocations/param_easing.py @@ -3,7 +3,6 @@ from typing import Literal, Optional import matplotlib.pyplot as plt import numpy as np - import PIL.Image from easing_functions import ( BackEaseIn, diff --git a/invokeai/app/invocations/upscale.py b/invokeai/app/invocations/upscale.py index 7dca6d9f21..9dc2eed2c1 100644 --- a/invokeai/app/invocations/upscale.py +++ b/invokeai/app/invocations/upscale.py @@ -7,8 +7,8 @@ import numpy as np from basicsr.archs.rrdbnet_arch import RRDBNet from PIL import Image from realesrgan import RealESRGANer -from invokeai.app.invocations.primitives import ImageField, ImageOutput +from invokeai.app.invocations.primitives import ImageField, ImageOutput from invokeai.app.models.image import ImageCategory, ResourceOrigin from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation diff --git a/invokeai/app/services/board_image_record_storage.py b/invokeai/app/services/board_image_record_storage.py index 03badf9866..d35f9f2179 100644 --- a/invokeai/app/services/board_image_record_storage.py +++ b/invokeai/app/services/board_image_record_storage.py @@ -1,13 +1,10 @@ -from abc import ABC, abstractmethod import sqlite3 import threading +from abc import ABC, abstractmethod from typing import Optional, cast from invokeai.app.services.image_record_storage import OffsetPaginatedResults -from invokeai.app.services.models.image_record import ( - ImageRecord, - deserialize_image_record, -) +from invokeai.app.services.models.image_record import ImageRecord, deserialize_image_record class BoardImageRecordStorageBase(ABC): diff --git a/invokeai/app/services/board_images.py b/invokeai/app/services/board_images.py index 7c6995dfc8..788722ec37 100644 --- a/invokeai/app/services/board_images.py +++ b/invokeai/app/services/board_images.py @@ -1,12 +1,9 @@ from abc import ABC, abstractmethod from logging import Logger from typing import Optional -from invokeai.app.services.board_image_record_storage import BoardImageRecordStorageBase -from invokeai.app.services.board_record_storage import ( - BoardRecord, - BoardRecordStorageBase, -) +from invokeai.app.services.board_image_record_storage import BoardImageRecordStorageBase +from invokeai.app.services.board_record_storage import BoardRecord, BoardRecordStorageBase from invokeai.app.services.image_record_storage import ImageRecordStorageBase from invokeai.app.services.models.board_record import BoardDTO from invokeai.app.services.urls import UrlServiceBase diff --git a/invokeai/app/services/board_record_storage.py b/invokeai/app/services/board_record_storage.py index 593bb3e7b9..f4876b6935 100644 --- a/invokeai/app/services/board_record_storage.py +++ b/invokeai/app/services/board_record_storage.py @@ -1,15 +1,13 @@ +import sqlite3 import threading import uuid from abc import ABC, abstractmethod from typing import Optional, Union, cast -import sqlite3 +from pydantic import BaseModel, Extra, Field + from invokeai.app.services.image_record_storage import OffsetPaginatedResults -from invokeai.app.services.models.board_record import ( - BoardRecord, - deserialize_board_record, -) -from pydantic import BaseModel, Field, Extra +from invokeai.app.services.models.board_record import BoardRecord, deserialize_board_record class BoardChanges(BaseModel, extra=Extra.forbid): diff --git a/invokeai/app/services/boards.py b/invokeai/app/services/boards.py index 53d30b2e85..e7a516da65 100644 --- a/invokeai/app/services/boards.py +++ b/invokeai/app/services/boards.py @@ -1,17 +1,10 @@ from abc import ABC, abstractmethod - from logging import Logger + from invokeai.app.services.board_image_record_storage import BoardImageRecordStorageBase from invokeai.app.services.board_images import board_record_to_dto - -from invokeai.app.services.board_record_storage import ( - BoardChanges, - BoardRecordStorageBase, -) -from invokeai.app.services.image_record_storage import ( - ImageRecordStorageBase, - OffsetPaginatedResults, -) +from invokeai.app.services.board_record_storage import BoardChanges, BoardRecordStorageBase +from invokeai.app.services.image_record_storage import ImageRecordStorageBase, OffsetPaginatedResults from invokeai.app.services.models.board_record import BoardDTO from invokeai.app.services.urls import UrlServiceBase diff --git a/invokeai/app/services/default_graphs.py b/invokeai/app/services/default_graphs.py index 5e1a594b91..2677060655 100644 --- a/invokeai/app/services/default_graphs.py +++ b/invokeai/app/services/default_graphs.py @@ -1,12 +1,11 @@ -from ..invocations.latent import LatentsToImageInvocation, DenoiseLatentsInvocation -from ..invocations.image import ImageNSFWBlurInvocation -from ..invocations.noise import NoiseInvocation from ..invocations.compel import CompelInvocation +from ..invocations.image import ImageNSFWBlurInvocation +from ..invocations.latent import DenoiseLatentsInvocation, LatentsToImageInvocation +from ..invocations.noise import NoiseInvocation from ..invocations.primitives import IntegerInvocation from .graph import Edge, EdgeConnection, ExposedNodeInput, ExposedNodeOutput, Graph, LibraryGraph from .item_storage import ItemStorageABC - default_text_to_image_graph_id = "539b2af5-2b4d-4d8c-8071-e54a3255fc74" diff --git a/invokeai/app/services/events.py b/invokeai/app/services/events.py index a266fe4f18..2bfe9b7c3d 100644 --- a/invokeai/app/services/events.py +++ b/invokeai/app/services/events.py @@ -1,14 +1,10 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) from typing import Any, Optional + from invokeai.app.models.image import ProgressImage +from invokeai.app.services.model_manager_service import BaseModelType, ModelInfo, ModelType, SubModelType from invokeai.app.util.misc import get_timestamp -from invokeai.app.services.model_manager_service import ( - BaseModelType, - ModelType, - SubModelType, - ModelInfo, -) class EventServiceBase: diff --git a/invokeai/app/services/image_record_storage.py b/invokeai/app/services/image_record_storage.py index 8f1b25b84a..b9982fcfdc 100644 --- a/invokeai/app/services/image_record_storage.py +++ b/invokeai/app/services/image_record_storage.py @@ -9,11 +9,7 @@ from pydantic import BaseModel, Field from pydantic.generics import GenericModel from invokeai.app.models.image import ImageCategory, ResourceOrigin -from invokeai.app.services.models.image_record import ( - ImageRecord, - ImageRecordChanges, - deserialize_image_record, -) +from invokeai.app.services.models.image_record import ImageRecord, ImageRecordChanges, deserialize_image_record T = TypeVar("T", bound=BaseModel) diff --git a/invokeai/app/services/images.py b/invokeai/app/services/images.py index 4d8e3d6d03..2b0a3d62a5 100644 --- a/invokeai/app/services/images.py +++ b/invokeai/app/services/images.py @@ -26,12 +26,7 @@ from invokeai.app.services.image_record_storage import ( OffsetPaginatedResults, ) from invokeai.app.services.item_storage import ItemStorageABC -from invokeai.app.services.models.image_record import ( - ImageDTO, - ImageRecord, - ImageRecordChanges, - image_record_to_dto, -) +from invokeai.app.services.models.image_record import ImageDTO, ImageRecord, ImageRecordChanges, image_record_to_dto from invokeai.app.services.resource_name import NameServiceBase from invokeai.app.services.urls import UrlServiceBase from invokeai.app.util.metadata import get_metadata_graph_from_raw_session diff --git a/invokeai/app/services/invocation_queue.py b/invokeai/app/services/invocation_queue.py index 963d500aa8..2fe5f60826 100644 --- a/invokeai/app/services/invocation_queue.py +++ b/invokeai/app/services/invocation_queue.py @@ -3,9 +3,9 @@ import time from abc import ABC, abstractmethod from queue import Queue +from typing import Optional from pydantic import BaseModel, Field -from typing import Optional class InvocationQueueItem(BaseModel): diff --git a/invokeai/app/services/invocation_services.py b/invokeai/app/services/invocation_services.py index d717087958..a4ec3573f5 100644 --- a/invokeai/app/services/invocation_services.py +++ b/invokeai/app/services/invocation_services.py @@ -1,21 +1,23 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team from __future__ import annotations + from typing import TYPE_CHECKING if TYPE_CHECKING: from logging import Logger + from invokeai.app.services.board_images import BoardImagesServiceABC from invokeai.app.services.boards import BoardServiceABC - from invokeai.app.services.images import ImageServiceABC - from invokeai.app.services.invocation_stats import InvocationStatsServiceBase - from invokeai.app.services.model_manager_service import ModelManagerServiceBase - from invokeai.app.services.events import EventServiceBase - from invokeai.app.services.latent_storage import LatentsStorageBase - from invokeai.app.services.invocation_queue import InvocationQueueABC - from invokeai.app.services.item_storage import ItemStorageABC from invokeai.app.services.config import InvokeAIAppConfig + from invokeai.app.services.events import EventServiceBase from invokeai.app.services.graph import GraphExecutionState, LibraryGraph + from invokeai.app.services.images import ImageServiceABC + from invokeai.app.services.invocation_queue import InvocationQueueABC + from invokeai.app.services.invocation_stats import InvocationStatsServiceBase from invokeai.app.services.invoker import InvocationProcessorABC + from invokeai.app.services.item_storage import ItemStorageABC + from invokeai.app.services.latent_storage import LatentsStorageBase + from invokeai.app.services.model_manager_service import ModelManagerServiceBase class InvocationServices: diff --git a/invokeai/app/services/invocation_stats.py b/invokeai/app/services/invocation_stats.py index b42d128b51..33932f73aa 100644 --- a/invokeai/app/services/invocation_stats.py +++ b/invokeai/app/services/invocation_stats.py @@ -28,22 +28,22 @@ The abstract base class for this class is InvocationStatsServiceBase. An impleme writes to the system log is stored in InvocationServices.performance_statistics. """ -import psutil import time from abc import ABC, abstractmethod from contextlib import AbstractContextManager from dataclasses import dataclass, field from typing import Dict +import psutil import torch import invokeai.backend.util.logging as logger +from invokeai.backend.model_management.model_cache import CacheStats from ..invocations.baseinvocation import BaseInvocation from .graph import GraphExecutionState from .item_storage import ItemStorageABC from .model_manager_service import ModelManagerService -from invokeai.backend.model_management.model_cache import CacheStats # size of GIG in bytes GIG = 1073741824 diff --git a/invokeai/app/services/latent_storage.py b/invokeai/app/services/latent_storage.py index 7c22ea5ba8..f0b1dc9fe7 100644 --- a/invokeai/app/services/latent_storage.py +++ b/invokeai/app/services/latent_storage.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from pathlib import Path from queue import Queue -from typing import Dict, Union, Optional +from typing import Dict, Optional, Union import torch diff --git a/invokeai/app/services/model_manager_service.py b/invokeai/app/services/model_manager_service.py index 11ebab7938..a7745a9253 100644 --- a/invokeai/app/services/model_manager_service.py +++ b/invokeai/app/services/model_manager_service.py @@ -5,27 +5,28 @@ from __future__ import annotations from abc import ABC, abstractmethod from logging import Logger from pathlib import Path -from pydantic import Field -from typing import Literal, Optional, Union, Callable, List, Tuple, TYPE_CHECKING from types import ModuleType - -from invokeai.backend.model_management import ( - ModelManager, - BaseModelType, - ModelType, - SubModelType, - ModelInfo, - AddModelResult, - SchedulerPredictionType, - ModelMerger, - MergeInterpolationMethod, - ModelNotFoundException, -) -from invokeai.backend.model_management.model_search import FindModels -from invokeai.backend.model_management.model_cache import CacheStats +from typing import TYPE_CHECKING, Callable, List, Literal, Optional, Tuple, Union import torch +from pydantic import Field + from invokeai.app.models.exceptions import CanceledException +from invokeai.backend.model_management import ( + AddModelResult, + BaseModelType, + MergeInterpolationMethod, + ModelInfo, + ModelManager, + ModelMerger, + ModelNotFoundException, + ModelType, + SchedulerPredictionType, + SubModelType, +) +from invokeai.backend.model_management.model_cache import CacheStats +from invokeai.backend.model_management.model_search import FindModels + from ...backend.util import choose_precision, choose_torch_device from .config import InvokeAIAppConfig diff --git a/invokeai/app/services/models/board_record.py b/invokeai/app/services/models/board_record.py index 53fa299faf..4b93d0ea23 100644 --- a/invokeai/app/services/models/board_record.py +++ b/invokeai/app/services/models/board_record.py @@ -1,6 +1,8 @@ -from typing import Optional, Union from datetime import datetime +from typing import Optional, Union + from pydantic import Field + from invokeai.app.util.misc import get_iso_timestamp from invokeai.app.util.model_exclude_null import BaseModelExcludeNull diff --git a/invokeai/app/services/resource_name.py b/invokeai/app/services/resource_name.py index dd5a76cfc0..c89c06edc3 100644 --- a/invokeai/app/services/resource_name.py +++ b/invokeai/app/services/resource_name.py @@ -1,6 +1,6 @@ +import uuid from abc import ABC, abstractmethod from enum import Enum, EnumMeta -import uuid class ResourceType(str, Enum, metaclass=EnumMeta): diff --git a/invokeai/app/util/controlnet_utils.py b/invokeai/app/util/controlnet_utils.py index 1578598687..8516fa8917 100644 --- a/invokeai/app/util/controlnet_utils.py +++ b/invokeai/app/util/controlnet_utils.py @@ -1,12 +1,12 @@ from typing import Union -import torch -import numpy as np -import cv2 -from PIL import Image -from diffusers.utils import PIL_INTERPOLATION -from einops import rearrange +import cv2 +import numpy as np +import torch from controlnet_aux.util import HWC3 +from diffusers.utils import PIL_INTERPOLATION +from einops import rearrange +from PIL import Image ################################################################### # Copy of scripts/lvminthin.py from Mikubill/sd-webui-controlnet diff --git a/invokeai/app/util/misc.py b/invokeai/app/util/misc.py index 8702d86c67..b42b2246b8 100644 --- a/invokeai/app/util/misc.py +++ b/invokeai/app/util/misc.py @@ -1,4 +1,5 @@ import datetime + import numpy as np diff --git a/invokeai/app/util/model_exclude_null.py b/invokeai/app/util/model_exclude_null.py index d864b8fab8..b75f127ec7 100644 --- a/invokeai/app/util/model_exclude_null.py +++ b/invokeai/app/util/model_exclude_null.py @@ -1,6 +1,6 @@ from typing import Any -from pydantic import BaseModel +from pydantic import BaseModel """ We want to exclude null values from objects that make their way to the client. diff --git a/invokeai/app/util/step_callback.py b/invokeai/app/util/step_callback.py index f6cccfb4b8..26de809d1c 100644 --- a/invokeai/app/util/step_callback.py +++ b/invokeai/app/util/step_callback.py @@ -1,11 +1,13 @@ import torch from PIL import Image + from invokeai.app.models.exceptions import CanceledException from invokeai.app.models.image import ProgressImage -from ..invocations.baseinvocation import InvocationContext -from ...backend.util.util import image_to_dataURL -from ...backend.stable_diffusion import PipelineIntermediateState + from ...backend.model_management.models import BaseModelType +from ...backend.stable_diffusion import PipelineIntermediateState +from ...backend.util.util import image_to_dataURL +from ..invocations.baseinvocation import InvocationContext def sample_to_lowres_estimated_image(samples, latent_rgb_factors, smooth_matrix=None): diff --git a/invokeai/app/util/thumbnails.py b/invokeai/app/util/thumbnails.py index 42a6fe9962..ad722f197e 100644 --- a/invokeai/app/util/thumbnails.py +++ b/invokeai/app/util/thumbnails.py @@ -1,4 +1,5 @@ import os + from PIL import Image diff --git a/invokeai/frontend/install/import_images.py b/invokeai/frontend/install/import_images.py index c0db81e141..e3f9ea84f3 100644 --- a/invokeai/frontend/install/import_images.py +++ b/invokeai/frontend/install/import_images.py @@ -6,25 +6,25 @@ # pylint: disable=broad-exception-caught """Script to import images into the new database system for 3.0.0""" -import os import datetime -import shutil -import locale -import sqlite3 -import json import glob +import json +import locale +import os import re +import shutil +import sqlite3 import uuid -import yaml +from pathlib import Path + import PIL import PIL.ImageOps import PIL.PngImagePlugin - -from pathlib import Path +import yaml from prompt_toolkit import prompt -from prompt_toolkit.shortcuts import message_dialog from prompt_toolkit.completion import PathCompleter from prompt_toolkit.key_binding import KeyBindings +from prompt_toolkit.shortcuts import message_dialog from invokeai.app.services.config import InvokeAIAppConfig diff --git a/invokeai/frontend/install/invokeai_update.py b/invokeai/frontend/install/invokeai_update.py index 45a0e8ec0a..87661da79f 100644 --- a/invokeai/frontend/install/invokeai_update.py +++ b/invokeai/frontend/install/invokeai_update.py @@ -4,6 +4,7 @@ pip install . """ import os import platform + import pkg_resources import psutil import requests diff --git a/invokeai/frontend/install/model_install.py b/invokeai/frontend/install/model_install.py index 6e4440abef..fae67df736 100644 --- a/invokeai/frontend/install/model_install.py +++ b/invokeai/frontend/install/model_install.py @@ -11,6 +11,7 @@ The work is actually done in backend code in model_install_backend.py. import argparse import curses +import logging import sys import textwrap import traceback @@ -20,34 +21,28 @@ from multiprocessing.connection import Connection, Pipe from pathlib import Path from shutil import get_terminal_size -import logging import npyscreen import torch from npyscreen import widget -from invokeai.backend.util.logging import InvokeAILogger - -from invokeai.backend.install.model_install_backend import ( - InstallSelections, - ModelInstall, - SchedulerPredictionType, -) +from invokeai.app.services.config import InvokeAIAppConfig +from invokeai.backend.install.model_install_backend import InstallSelections, ModelInstall, SchedulerPredictionType from invokeai.backend.model_management import ModelManager, ModelType from invokeai.backend.util import choose_precision, choose_torch_device +from invokeai.backend.util.logging import InvokeAILogger from invokeai.frontend.install.widgets import ( + MIN_COLS, + MIN_LINES, + BufferBox, CenteredTitleText, + CyclingForm, MultiSelectColumns, SingleSelectColumns, TextBox, - BufferBox, - set_min_terminal_size, - select_stable_diffusion_config_file, - CyclingForm, - MIN_COLS, - MIN_LINES, WindowTooSmallException, + select_stable_diffusion_config_file, + set_min_terminal_size, ) -from invokeai.app.services.config import InvokeAIAppConfig config = InvokeAIAppConfig.get_config() logger = InvokeAILogger.getLogger() diff --git a/invokeai/frontend/install/widgets.py b/invokeai/frontend/install/widgets.py index 9eefd93e09..06d5473fa3 100644 --- a/invokeai/frontend/install/widgets.py +++ b/invokeai/frontend/install/widgets.py @@ -5,16 +5,17 @@ import curses import math import os import platform -import pyperclip import struct import subprocess import sys -import npyscreen import textwrap -import npyscreen.wgmultiline as wgmultiline -from npyscreen import fmPopup -from shutil import get_terminal_size from curses import BUTTON2_CLICKED, BUTTON3_CLICKED +from shutil import get_terminal_size + +import npyscreen +import npyscreen.wgmultiline as wgmultiline +import pyperclip +from npyscreen import fmPopup # minimum size for UIs MIN_COLS = 150 diff --git a/invokeai/frontend/legacy_launch_invokeai.py b/invokeai/frontend/legacy_launch_invokeai.py index e1e7dc26ab..9e4cca7eac 100644 --- a/invokeai/frontend/legacy_launch_invokeai.py +++ b/invokeai/frontend/legacy_launch_invokeai.py @@ -1,5 +1,5 @@ -import sys import argparse +import sys def main(): diff --git a/invokeai/frontend/merge/merge_diffusers.py b/invokeai/frontend/merge/merge_diffusers.py index ada8eed644..8fa02cb49c 100644 --- a/invokeai/frontend/merge/merge_diffusers.py +++ b/invokeai/frontend/merge/merge_diffusers.py @@ -16,13 +16,8 @@ from npyscreen import widget import invokeai.backend.util.logging as logger from invokeai.app.services.config import InvokeAIAppConfig -from invokeai.backend.model_management import ( - ModelMerger, - ModelManager, - ModelType, - BaseModelType, -) -from invokeai.frontend.install.widgets import FloatTitleSlider, TextBox, SingleSelectColumns +from invokeai.backend.model_management import BaseModelType, ModelManager, ModelMerger, ModelType +from invokeai.frontend.install.widgets import FloatTitleSlider, SingleSelectColumns, TextBox config = InvokeAIAppConfig.get_config() diff --git a/invokeai/frontend/training/textual_inversion.py b/invokeai/frontend/training/textual_inversion.py index 12f4db8e7b..f3911f7e0e 100755 --- a/invokeai/frontend/training/textual_inversion.py +++ b/invokeai/frontend/training/textual_inversion.py @@ -21,8 +21,8 @@ from npyscreen import widget from omegaconf import OmegaConf import invokeai.backend.util.logging as logger - from invokeai.app.services.config import InvokeAIAppConfig + from ...backend.training import do_textual_inversion_training, parse_args TRAINING_DATA = "text-inversion-training-data" diff --git a/pyproject.toml b/pyproject.toml index c12573aed5..6cf9e3632a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -200,3 +200,7 @@ select = ["B", "C", "E", "F", "W", "T4"] [tool.black] line-length = 120 + +[tool.isort] +profile = "black" +line_length = 120 diff --git a/tests/nodes/test_graph_execution_state.py b/tests/nodes/test_graph_execution_state.py index cdb9815f83..603e0369be 100644 --- a/tests/nodes/test_graph_execution_state.py +++ b/tests/nodes/test_graph_execution_state.py @@ -1,30 +1,24 @@ -from .test_invoker import create_edge -from .test_nodes import ( +import pytest + +# This import must happen before other invoke imports or test in other files(!!) break +from .test_nodes import ( # isort: split + PromptCollectionTestInvocation, + PromptTestInvocation, TestEventService, TextToImageTestInvocation, - PromptTestInvocation, - PromptCollectionTestInvocation, -) -from invokeai.app.services.invocation_queue import MemoryInvocationQueue -from invokeai.app.services.processor import DefaultInvocationProcessor -from invokeai.app.services.sqlite import SqliteItemStorage, sqlite_memory -from invokeai.app.invocations.baseinvocation import ( - BaseInvocation, - BaseInvocationOutput, - InvocationContext, ) + +from invokeai.app.invocations.baseinvocation import BaseInvocation, BaseInvocationOutput, InvocationContext from invokeai.app.invocations.collections import RangeInvocation from invokeai.app.invocations.math import AddInvocation, MultiplyInvocation +from invokeai.app.services.graph import CollectInvocation, Graph, GraphExecutionState, IterateInvocation, LibraryGraph +from invokeai.app.services.invocation_queue import MemoryInvocationQueue from invokeai.app.services.invocation_services import InvocationServices from invokeai.app.services.invocation_stats import InvocationStatsService -from invokeai.app.services.graph import ( - Graph, - CollectInvocation, - IterateInvocation, - GraphExecutionState, - LibraryGraph, -) -import pytest +from invokeai.app.services.processor import DefaultInvocationProcessor +from invokeai.app.services.sqlite import SqliteItemStorage, sqlite_memory + +from .test_invoker import create_edge @pytest.fixture diff --git a/tests/nodes/test_invoker.py b/tests/nodes/test_invoker.py index 5985c7e8bb..aa0e29598c 100644 --- a/tests/nodes/test_invoker.py +++ b/tests/nodes/test_invoker.py @@ -1,23 +1,21 @@ +import pytest + +from invokeai.app.services.graph import Graph, GraphExecutionState, LibraryGraph +from invokeai.app.services.invocation_queue import MemoryInvocationQueue +from invokeai.app.services.invocation_services import InvocationServices +from invokeai.app.services.invocation_stats import InvocationStatsService +from invokeai.app.services.invoker import Invoker +from invokeai.app.services.processor import DefaultInvocationProcessor +from invokeai.app.services.sqlite import SqliteItemStorage, sqlite_memory + from .test_nodes import ( - TestEventService, ErrorInvocation, - TextToImageTestInvocation, PromptTestInvocation, + TestEventService, + TextToImageTestInvocation, create_edge, wait_until, ) -from invokeai.app.services.invocation_queue import MemoryInvocationQueue -from invokeai.app.services.processor import DefaultInvocationProcessor -from invokeai.app.services.sqlite import SqliteItemStorage, sqlite_memory -from invokeai.app.services.invoker import Invoker -from invokeai.app.services.invocation_services import InvocationServices -from invokeai.app.services.invocation_stats import InvocationStatsService -from invokeai.app.services.graph import ( - Graph, - GraphExecutionState, - LibraryGraph, -) -import pytest @pytest.fixture diff --git a/tests/nodes/test_node_graph.py b/tests/nodes/test_node_graph.py index 0e1be8f343..cce2fae9ed 100644 --- a/tests/nodes/test_node_graph.py +++ b/tests/nodes/test_node_graph.py @@ -1,3 +1,4 @@ +import pytest from invokeai.app.invocations.baseinvocation import ( BaseInvocation, BaseInvocationOutput, @@ -29,7 +30,25 @@ from invokeai.app.invocations.image import ShowImageInvocation from invokeai.app.invocations.math import AddInvocation, SubtractInvocation from invokeai.app.invocations.primitives import FloatInvocation, IntegerInvocation from invokeai.app.services.default_graphs import create_text_to_image -import pytest +from invokeai.app.services.graph import ( + CollectInvocation, + Edge, + EdgeConnection, + Graph, + GraphInvocation, + InvalidEdgeError, + IterateInvocation, + NodeAlreadyInGraphError, + NodeNotFoundError, + are_connections_compatible, +) + +from .test_nodes import ( + ImageToImageTestInvocation, + ListPassThroughInvocation, + PromptTestInvocation, + TextToImageTestInvocation, +) # Helpers diff --git a/tests/nodes/test_nodes.py b/tests/nodes/test_nodes.py index 26b8b2b565..3a28c53819 100644 --- a/tests/nodes/test_nodes.py +++ b/tests/nodes/test_nodes.py @@ -78,7 +78,7 @@ class PromptCollectionTestInvocation(BaseInvocation): return PromptCollectionTestInvocationOutput(collection=self.collection.copy()) -# Importing these at the top breaks previous tests +# Importing these must happen after test invocations are defined or they won't register from invokeai.app.services.events import EventServiceBase # noqa: E402 from invokeai.app.services.graph import Edge, EdgeConnection # noqa: E402 diff --git a/tests/nodes/test_sqlite.py b/tests/nodes/test_sqlite.py index a9eb542e44..91e4bd0c58 100644 --- a/tests/nodes/test_sqlite.py +++ b/tests/nodes/test_sqlite.py @@ -1,6 +1,7 @@ -from invokeai.app.services.sqlite import SqliteItemStorage, sqlite_memory from pydantic import BaseModel, Field +from invokeai.app.services.sqlite import SqliteItemStorage, sqlite_memory + class TestModel(BaseModel): id: str = Field(description="ID") diff --git a/tests/test_config.py b/tests/test_config.py index 3c1646d860..d915316a10 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -6,8 +6,6 @@ import pytest from omegaconf import OmegaConf from pydantic import ValidationError -from invokeai.app.services.config import InvokeAIAppConfig - @pytest.fixture def patch_rootdir(tmp_path: Path, monkeypatch: Any) -> None: @@ -166,6 +164,7 @@ def test_type_coercion(patch_rootdir): """ ) def test_deny_nodes(patch_rootdir): + from invokeai.app.services.config import InvokeAIAppConfig # Allow integer, string and float, but explicitly deny float allow_deny_nodes_conf = OmegaConf.create( """ diff --git a/tests/test_model_manager.py b/tests/test_model_manager.py index 4aa2c4d3b2..5a28862e1f 100644 --- a/tests/test_model_manager.py +++ b/tests/test_model_manager.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest from invokeai.app.services.config import InvokeAIAppConfig -from invokeai.backend import ModelManager, BaseModelType, ModelType, SubModelType +from invokeai.backend import BaseModelType, ModelManager, ModelType, SubModelType BASIC_MODEL_NAME = ("SDXL base", BaseModelType.StableDiffusionXL, ModelType.Main) VAE_OVERRIDE_MODEL_NAME = ("SDXL with VAE", BaseModelType.StableDiffusionXL, ModelType.Main) diff --git a/tests/test_path.py b/tests/test_path.py index 0da5f2f8dc..4c502acdcc 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -2,14 +2,15 @@ Not really a test, but a way to verify that the paths are existing and fail early if they are not. """ -import unittest import pathlib +import unittest from os import path as osp + from PIL import Image -import invokeai.frontend.web.dist as frontend -import invokeai.configs as configs import invokeai.app.assets.images as image_assets +import invokeai.configs as configs +import invokeai.frontend.web.dist as frontend class ConfigsTestCase(unittest.TestCase):