Skip to content

Commit 4d1c4b9

Browse files
authored
Auto register web folder (comfyanonymous#8505)
* auto register web folder from pyproject * need pydantic-settings as dependency * wrapped try/except for config_parser * sf
1 parent d2566eb commit 4d1c4b9

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

comfy_config/types.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, Field
1+
from pydantic import BaseModel, Field, field_validator
22
from pydantic_settings import BaseSettings, SettingsConfigDict
33
from typing import List, Optional
44

@@ -50,6 +50,7 @@ class ComfyConfig(BaseModel):
5050
icon: str = Field(default="", alias="Icon")
5151
models: List[Model] = Field(default_factory=list, alias="Models")
5252
includes: List[str] = Field(default_factory=list)
53+
web: Optional[str] = None
5354

5455

5556
class License(BaseModel):
@@ -66,6 +67,18 @@ class ProjectConfig(BaseModel):
6667
license: License = Field(default_factory=License)
6768
urls: URLs = Field(default_factory=URLs)
6869

70+
@field_validator('license', mode='before')
71+
@classmethod
72+
def validate_license(cls, v):
73+
if isinstance(v, str):
74+
return License(text=v)
75+
elif isinstance(v, dict):
76+
return License(**v)
77+
elif isinstance(v, License):
78+
return v
79+
else:
80+
return License()
81+
6982

7083
class PyProjectConfig(BaseModel):
7184
project: ProjectConfig = Field(default_factory=ProjectConfig)

nodes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,25 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes
21252125

21262126
LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir)
21272127

2128+
try:
2129+
from comfy_config import config_parser
2130+
2131+
project_config = config_parser.extract_node_configuration(module_path)
2132+
2133+
web_dir_name = project_config.tool_comfy.web
2134+
2135+
if web_dir_name:
2136+
web_dir_path = os.path.join(module_path, web_dir_name)
2137+
2138+
if os.path.isdir(web_dir_path):
2139+
project_name = project_config.project.name
2140+
2141+
EXTENSION_WEB_DIRS[project_name] = web_dir_path
2142+
2143+
logging.info("Automatically register web folder {} for {}".format(web_dir_name, project_name))
2144+
except Exception as e:
2145+
logging.debug(f"Unable to parse pyproject.toml due to lack dependency pydantic-settings, please run 'pip install -r requirements.txt': {e}")
2146+
21282147
if hasattr(module, "WEB_DIRECTORY") and getattr(module, "WEB_DIRECTORY") is not None:
21292148
web_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "WEB_DIRECTORY")))
21302149
if os.path.isdir(web_dir):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ spandrel
2727
soundfile
2828
av>=14.2.0
2929
pydantic~=2.0
30+
pydantic-settings~=2.0

0 commit comments

Comments
 (0)