Improve nodes handling

This commit is contained in:
doctorpangloss 2024-02-21 23:44:16 -08:00
parent be42aae9a4
commit c941ee09fc
4 changed files with 55 additions and 12 deletions

View File

@ -75,6 +75,7 @@ class Configuration(dict):
distributed_queue_worker (bool): Workers will pull requests off the AMQP URL.
distributed_queue_name (str): This name will be used by the frontends and workers to exchange prompt requests and replies. Progress updates will be prefixed by the queue name, followed by a '.', then the user ID.
external_address (str): Specifies a base URL for external addresses reported by the API, such as for image paths.
verbose (bool): Shows extra output for debugging purposes such as import errors of custom nodes.
"""
def __init__(self, **kwargs):
super().__init__()

View File

@ -1,6 +1,7 @@
from __future__ import annotations
import importlib
import logging
import os
import pkgutil
import time
@ -63,6 +64,7 @@ def _import_and_enumerate_nodes_in_module(module: types.ModuleType, print_import
except KeyboardInterrupt as interrupted:
raise interrupted
except Exception as x:
logging.error(f"{full_name} import failed", exc_info=x)
success = False
timings.append((time.perf_counter() - time_before, full_name, success))

View File

@ -1,23 +1,64 @@
from __future__ import annotations
import typing
from typing import Protocol, ClassVar, Tuple, Dict
from dataclasses import dataclass, field
from typing import TypedDict, Union, Optional, Sequence, Dict, ClassVar, Protocol, Tuple, TypeVar, Any, Literal, \
Callable
T = typing.TypeVar('T', bound='CustomNode')
T = TypeVar('T')
class NumberSpecOptions(TypedDict, total=False):
default: Union[int, float]
min: Union[int, float]
max: Union[int, float]
step: Union[int, float]
round: int
IntSpec = Dict[str, Union[
Literal["INT"],
Tuple[Literal["INT"], Dict[str, Union[int, float, str]]]
]]
FloatSpec = Dict[str, Union[
Literal["FLOAT"],
Tuple[Literal["FLOAT"], Dict[str, Union[int, float, str]]]
]]
StringSpec = Dict[str, Union[
Literal["STRING"],
Tuple[Literal["STRING"], Dict[str, str]]
]]
ChoiceSpec = Dict[str, Union[
Sequence[str], # Directly a list of choices
Tuple[Sequence[str], Dict[str, Any]] # Choices with additional specifications
]]
ComplexInputSpec = Dict[str, Any]
InputTypeSpec = Union[IntSpec, FloatSpec, StringSpec, ChoiceSpec, ComplexInputSpec]
class InputTypes(Protocol):
required: Dict[str, InputTypeSpec]
optional: Optional[Dict[str, InputTypeSpec]]
hidden: Optional[Dict[str, InputTypeSpec]]
ValidateInputsMethod = Optional[Callable[..., Union[bool, str]]]
class CustomNode(Protocol):
@classmethod
def INPUT_TYPES(cls) -> dict: ...
def INPUT_TYPES(cls) -> InputTypes: ...
RETURN_TYPES: ClassVar[typing.Sequence[str]]
RETURN_NAMES: typing.Optional[ClassVar[Tuple[str]]]
OUTPUT_IS_LIST: typing.Optional[ClassVar[typing.Sequence[bool]]]
INPUT_IS_LIST: typing.Optional[ClassVar[bool]]
# Optional method signature for VALIDATE_INPUTS
VALIDATE_INPUTS: ClassVar[ValidateInputsMethod] = None
RETURN_TYPES: ClassVar[Sequence[str]]
RETURN_NAMES: Optional[ClassVar[Tuple[str]]]
OUTPUT_IS_LIST: Optional[ClassVar[Sequence[bool]]]
INPUT_IS_LIST: Optional[ClassVar[bool]]
FUNCTION: ClassVar[str]
CATEGORY: ClassVar[str]
OUTPUT_NODE: typing.Optional[ClassVar[bool]]
OUTPUT_NODE: Optional[ClassVar[bool]]
def __call__(self) -> T:
...

View File

@ -176,9 +176,8 @@ setup(
author="",
version=version,
python_requires=">=3.9,<3.13",
# todo: figure out how to include the web directory to eventually let main live inside the package
# todo: see https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/ for more about adding plugins
packages=find_packages(exclude=[] if is_editable else ['custom_nodes']),
packages=find_packages(exclude=["tests"] + [] if is_editable else ['custom_nodes']),
package_dir={'': ''},
include_package_data=True,
install_requires=dependencies(),
setup_requires=["pip", "wheel"],