feat(dev_reload): use jurigged to hot reload changes to Python source

This commit is contained in:
Kevin Turner 2023-08-17 18:48:04 -07:00
parent 498d2ecc2b
commit 654dcd453f
3 changed files with 25 additions and 7 deletions

View File

@ -1,12 +1,12 @@
# Copyright (c) 2022-2023 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
import asyncio
import logging
import socket
import sys
from inspect import signature
from pathlib import Path
import logging
import uvicorn
import socket
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
@ -14,7 +14,6 @@ from fastapi.openapi.utils import get_openapi
from fastapi.staticfiles import StaticFiles
from fastapi_events.handlers.local import local_handler
from fastapi_events.middleware import EventHandlerASGIMiddleware
from pathlib import Path
from pydantic.schema import schema
# This should come early so that modules can log their initialization properly
@ -42,9 +41,12 @@ from .invocations.baseinvocation import BaseInvocation, _InputField, _OutputFiel
import torch
# noinspection PyUnresolvedReferences
import invokeai.backend.util.hotfixes
if torch.backends.mps.is_available():
# noinspection PyUnresolvedReferences
import invokeai.backend.util.mps_fixes
# fix for windows mimetypes registry entries being borked
@ -213,6 +215,17 @@ def invoke_api():
check_invokeai_root(app_config) # note, may exit with an exception if root not set up
if app_config.dev_reload:
try:
import jurigged
except ImportError as e:
logger.error(
"Can't start `--dev_reload` because jurigged is not found; `pip install -e '.[dev]'` to include development dependencies.",
exc_info=e,
)
else:
jurigged.watch(logger=InvokeAILogger.getLogger(name="jurigged").info)
port = find_port(app_config.port)
if port != app_config.port:
logger.warn(f"Port {app_config.port} in use, using port {port}")

View File

@ -159,15 +159,17 @@ two configs are kept in separate sections of the config file:
"""
from __future__ import annotations
import argparse
import pydoc
import os
import pydoc
import sys
from argparse import ArgumentParser
from omegaconf import OmegaConf, DictConfig, ListConfig
from pathlib import Path
from typing import ClassVar, Dict, List, Literal, Union, get_origin, get_type_hints, get_args
from omegaconf import OmegaConf, DictConfig, ListConfig
from pydantic import BaseSettings, Field, parse_obj_as
from typing import ClassVar, Dict, List, Set, Literal, Union, get_origin, get_type_hints, get_args
INIT_FILE = Path("invokeai.yaml")
DB_FILE = Path("invokeai.db")
@ -418,6 +420,8 @@ class InvokeAIAppConfig(InvokeAISettings):
log_format : Literal[tuple(['plain','color','syslog','legacy'])] = Field(default="color", description='Log format. Use "plain" for text-only, "color" for colorized output, "legacy" for 2.3-style logging and "syslog" for syslog-style', category="Logging")
log_level : Literal[tuple(["debug","info","warning","error","critical"])] = Field(default="info", description="Emit logging messages at this level or higher", category="Logging")
dev_reload : bool = Field(default=False, description="Automatically reload when Python sources are changed.", category="Development")
version : bool = Field(default=False, description="Show InvokeAI version and exit", category="Other")
# fmt: on

View File

@ -93,6 +93,7 @@ dependencies = [
"mkdocs-redirects==1.2.0",
]
"dev" = [
"jurigged",
"pudb",
]
"test" = ["pytest>6.0.0", "pytest-cov", "pytest-datadir", "black"]