mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-04 06:17:10 +08:00
Auto register web folder (#8505)
* auto register web folder from pyproject * need pydantic-settings as dependency * wrapped try/except for config_parser * sf
This commit is contained in:
parent
d2566eb4b2
commit
4d1c4b9797
@ -1,4 +1,4 @@
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, field_validator
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ class ComfyConfig(BaseModel):
|
|||||||
icon: str = Field(default="", alias="Icon")
|
icon: str = Field(default="", alias="Icon")
|
||||||
models: List[Model] = Field(default_factory=list, alias="Models")
|
models: List[Model] = Field(default_factory=list, alias="Models")
|
||||||
includes: List[str] = Field(default_factory=list)
|
includes: List[str] = Field(default_factory=list)
|
||||||
|
web: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class License(BaseModel):
|
class License(BaseModel):
|
||||||
@ -66,6 +67,18 @@ class ProjectConfig(BaseModel):
|
|||||||
license: License = Field(default_factory=License)
|
license: License = Field(default_factory=License)
|
||||||
urls: URLs = Field(default_factory=URLs)
|
urls: URLs = Field(default_factory=URLs)
|
||||||
|
|
||||||
|
@field_validator('license', mode='before')
|
||||||
|
@classmethod
|
||||||
|
def validate_license(cls, v):
|
||||||
|
if isinstance(v, str):
|
||||||
|
return License(text=v)
|
||||||
|
elif isinstance(v, dict):
|
||||||
|
return License(**v)
|
||||||
|
elif isinstance(v, License):
|
||||||
|
return v
|
||||||
|
else:
|
||||||
|
return License()
|
||||||
|
|
||||||
|
|
||||||
class PyProjectConfig(BaseModel):
|
class PyProjectConfig(BaseModel):
|
||||||
project: ProjectConfig = Field(default_factory=ProjectConfig)
|
project: ProjectConfig = Field(default_factory=ProjectConfig)
|
||||||
|
19
nodes.py
19
nodes.py
@ -2125,6 +2125,25 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes
|
|||||||
|
|
||||||
LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir)
|
LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from comfy_config import config_parser
|
||||||
|
|
||||||
|
project_config = config_parser.extract_node_configuration(module_path)
|
||||||
|
|
||||||
|
web_dir_name = project_config.tool_comfy.web
|
||||||
|
|
||||||
|
if web_dir_name:
|
||||||
|
web_dir_path = os.path.join(module_path, web_dir_name)
|
||||||
|
|
||||||
|
if os.path.isdir(web_dir_path):
|
||||||
|
project_name = project_config.project.name
|
||||||
|
|
||||||
|
EXTENSION_WEB_DIRS[project_name] = web_dir_path
|
||||||
|
|
||||||
|
logging.info("Automatically register web folder {} for {}".format(web_dir_name, project_name))
|
||||||
|
except Exception as e:
|
||||||
|
logging.debug(f"Unable to parse pyproject.toml due to lack dependency pydantic-settings, please run 'pip install -r requirements.txt': {e}")
|
||||||
|
|
||||||
if hasattr(module, "WEB_DIRECTORY") and getattr(module, "WEB_DIRECTORY") is not None:
|
if hasattr(module, "WEB_DIRECTORY") and getattr(module, "WEB_DIRECTORY") is not None:
|
||||||
web_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "WEB_DIRECTORY")))
|
web_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "WEB_DIRECTORY")))
|
||||||
if os.path.isdir(web_dir):
|
if os.path.isdir(web_dir):
|
||||||
|
@ -27,3 +27,4 @@ spandrel
|
|||||||
soundfile
|
soundfile
|
||||||
av>=14.2.0
|
av>=14.2.0
|
||||||
pydantic~=2.0
|
pydantic~=2.0
|
||||||
|
pydantic-settings~=2.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user