Skip to content

Commit

Permalink
chore: ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
psychedelicious committed Feb 29, 2024
1 parent 130432c commit 26d9b75
Show file tree
Hide file tree
Showing 44 changed files with 51 additions and 19 deletions.
1 change: 1 addition & 0 deletions invokeai/app/services/config/config_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class InvokeBatch(InvokeAISettings):
...
"""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions invokeai/app/services/download/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Init file for download queue."""

from .download_base import DownloadJob, DownloadJobStatus, DownloadQueueServiceBase, UnknownJobIDException
from .download_default import DownloadQueueService, TqdmProgress

Expand Down
1 change: 1 addition & 0 deletions invokeai/app/services/model_records/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Init file for model record services."""

from .model_records_base import ( # noqa F401
DuplicateModelException,
InvalidModelException,
Expand Down
1 change: 0 additions & 1 deletion invokeai/app/services/model_records/model_records_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
configs = store.search_by_attr(base_model='sd-2', model_type='main')
"""


import json
import sqlite3
from math import ceil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class MigrateCallback(Protocol):
See :class:`Migration` for an example.
"""

def __call__(self, cursor: sqlite3.Cursor) -> None:
...
def __call__(self, cursor: sqlite3.Cursor) -> None: ...


class MigrationError(RuntimeError):
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/image_util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Initialization file for invokeai.backend.image_util methods.
"""

from .patchmatch import PatchMatch # noqa: F401
from .pngwriter import PngWriter, PromptFormatter, retrieve_metadata, write_metadata # noqa: F401
from .seamless import configure_model_padding # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/image_util/invisible_watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
wraps the invisible watermark model. It respects the global "invisible_watermark"
configuration variable, that allows the watermarking to be supressed.
"""

import cv2
import numpy as np
from imwatermark import WatermarkEncoder
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/image_util/patchmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"try_patchmatch" attribute, so that patchmatch loading can
be suppressed or deferred
"""

import numpy as np

import invokeai.backend.util.logging as logger
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/image_util/pngwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Exports function retrieve_metadata(path)
"""

import json
import os
import re
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/image_util/safety_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
wraps the safety_checker model. It respects the global "nsfw_checker"
configuration variable, that allows the checker to be supressed.
"""

import numpy as np
from PIL import Image

Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/install/check_root.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Check that the invokeai_root is correctly configured and exit if not.
"""

import sys

from invokeai.app.services.config import InvokeAIAppConfig
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/install/install_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility (backend) functions used by model_install.py"""

from logging import Logger
from pathlib import Path
from typing import Any, Dict, List, Optional
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/model_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Re-export frequently-used symbols from the Model Manager backend."""

from .config import (
AnyModel,
AnyModelConfig,
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/model_manager/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Validation errors will raise an InvalidModelConfigException error.
"""

import time
from enum import Enum
from typing import Literal, Optional, Type, Union
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# Adapted for use in InvokeAI by Lincoln Stein, July 2023
#
""" Conversion script for the Stable Diffusion checkpoints."""
"""Conversion script for the Stable Diffusion checkpoints."""

import re
from contextlib import nullcontext
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/model_manager/load/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Init file for the model loader.
"""

from importlib import import_module
from pathlib import Path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Disk-based converted model cache.
"""

from abc import ABC, abstractmethod
from pathlib import Path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
).load_model(model_config, submodel_type)
"""

import hashlib
from abc import ABC, abstractmethod
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion invokeai/backend/model_manager/load/model_loaders/lora.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2024, Lincoln D. Stein and the InvokeAI Development Team
"""Class for LoRA model loading in InvokeAI."""


from logging import Logger
from pathlib import Path
from typing import Optional, Tuple
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2024, Lincoln D. Stein and the InvokeAI Development Team
"""Class for StableDiffusion model loading in InvokeAI."""


from pathlib import Path
from typing import Optional

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2024, Lincoln D. Stein and the InvokeAI Development Team
"""Class for TI model loading in InvokeAI."""


from pathlib import Path
from typing import Optional, Tuple

Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/model_manager/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
if data.allow_commercial_use:
print("Commercial use of this model is allowed")
"""

from .fetch import CivitaiMetadataFetch, HuggingFaceMetadataFetch, ModelMetadataFetchBase
from .metadata_base import (
AnyModelRepoMetadata,
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/model_patcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2024 Ryan Dick, Lincoln D. Stein, and the InvokeAI Development Team
"""These classes implement model patching with LoRAs and Textual Inversions."""

from __future__ import annotations

import pickle
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/stable_diffusion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Initialization file for the invokeai.backend.stable_diffusion package
"""

from .diffusers_pipeline import PipelineIntermediateState, StableDiffusionGeneratorPipeline # noqa: F401
from .diffusion import InvokeAIDiffuserComponent # noqa: F401
from .diffusion.cross_attention_map_saving import AttentionMapSaver # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/stable_diffusion/diffusion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Initialization file for invokeai.models.diffusion
"""

from .cross_attention_control import InvokeAICrossAttentionMixin # noqa: F401
from .cross_attention_map_saving import AttentionMapSaver # noqa: F401
from .shared_invokeai_diffusion import InvokeAIDiffuserComponent # noqa: F401
1 change: 1 addition & 0 deletions invokeai/backend/training/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Initialization file for invokeai.backend.training
"""

from .textual_inversion_training import do_textual_inversion_training, parse_args # noqa: F401
6 changes: 3 additions & 3 deletions invokeai/backend/training/textual_inversion_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,9 @@ def do_textual_inversion_training(
# Let's make sure we don't update any embedding weights besides the newly added token
index_no_updates = torch.arange(len(tokenizer)) != placeholder_token_id
with torch.no_grad():
accelerator.unwrap_model(text_encoder).get_input_embeddings().weight[
index_no_updates
] = orig_embeds_params[index_no_updates]
accelerator.unwrap_model(text_encoder).get_input_embeddings().weight[index_no_updates] = (
orig_embeds_params[index_no_updates]
)

# Checks if the accelerator has performed an optimization step behind the scenes
if accelerator.sync_gradients:
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Initialization file for invokeai.backend.util
"""

from .attention import auto_detect_slice_size # noqa: F401
from .devices import ( # noqa: F401
CPU_DEVICE,
Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/util/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Utility routine used for autodetection of optimal slice size
for attention mechanism.
"""

import psutil
import torch

Expand Down
1 change: 1 addition & 0 deletions invokeai/backend/util/silence_warnings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Context class to silence transformers and diffusers warnings."""

import warnings
from typing import Any

Expand Down
19 changes: 11 additions & 8 deletions invokeai/backend/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,17 @@ def download_with_resume(url: str, dest: Path, access_token: str = None) -> Path
logger.error(f"ERROR DOWNLOADING {url}: {resp.text}")
return None

with open(dest, open_mode) as file, tqdm(
desc=str(dest),
initial=exist_size,
total=content_length,
unit="iB",
unit_scale=True,
unit_divisor=1000,
) as bar:
with (
open(dest, open_mode) as file,
tqdm(
desc=str(dest),
initial=exist_size,
total=content_length,
unit="iB",
unit_scale=True,
unit_divisor=1000,
) as bar,
):
for data in resp.iter_content(chunk_size=1024):
size = file.write(data)
bar.update(size)
Expand Down
1 change: 1 addition & 0 deletions invokeai/frontend/CLI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Initialization file for invokeai.frontend.CLI
"""

from .CLI import main as invokeai_command_line_interface # noqa: F401
1 change: 1 addition & 0 deletions invokeai/frontend/install/invokeai_configure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Wrapper for invokeai.backend.configure.invokeai_configure
"""

from ...backend.install.invokeai_configure import main as invokeai_configure # noqa: F401

__all__ = ["invokeai_configure"]
1 change: 1 addition & 0 deletions invokeai/frontend/install/invokeai_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Minimalist updater script. Prompts user for the tag or branch to update to and runs
pip install <path_to_git_source>.
"""

import os
import platform
from distutils.version import LooseVersion
Expand Down
1 change: 1 addition & 0 deletions invokeai/frontend/install/widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Widget class definitions used by model_select.py, merge_diffusers.py and textual_inversion.py
"""

import curses
import math
import os
Expand Down
1 change: 1 addition & 0 deletions invokeai/frontend/merge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Initialization file for invokeai.frontend.merge
"""

from .merge_diffusers import main as invokeai_merge_diffusers # noqa: F401
1 change: 1 addition & 0 deletions invokeai/frontend/merge/merge_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Copyright (c) 2023 Lincoln Stein and the InvokeAI Development Team
"""

import argparse
import curses
import re
Expand Down
1 change: 1 addition & 0 deletions invokeai/frontend/training/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Initialization file for invokeai.frontend.training
"""

from .textual_inversion import main as invokeai_textual_inversion # noqa: F401
1 change: 0 additions & 1 deletion invokeai/frontend/training/textual_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Copyright (c) 2023-24 Lincoln Stein and the InvokeAI Development Team
"""


import os
import re
import shutil
Expand Down
1 change: 1 addition & 0 deletions invokeai/version/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
initialization file for invokeai
"""

from .invokeai_version import __version__ # noqa: F401

__app_id__ = "invoke-ai/InvokeAI"
Expand Down
1 change: 1 addition & 0 deletions tests/app/services/download/test_download_queue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the queued download facility"""

import re
import time
from pathlib import Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test model metadata fetching and storage.
"""

import datetime
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions tests/backend/util/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test interaction of logging with configuration system.
"""

import io
import logging
import re
Expand Down
1 change: 1 addition & 0 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Not really a test, but a way to verify that the paths are existing
and fail early if they are not.
"""

import pathlib
import unittest
from os import path as osp
Expand Down

0 comments on commit 26d9b75

Please sign in to comment.