Skip to content

Commit 9685d4f

Browse files
authored
auto register web folder from pyproject (comfyanonymous#8478)
* auto register web folder from pyproject * need pydantic-settings as dependency
1 parent 8a4ff74 commit 9685d4f

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import latent_preview
3939
import node_helpers
4040

41+
from comfy_config import config_parser
42+
4143
def before_node_execution():
4244
comfy.model_management.throw_exception_if_processing_interrupted()
4345

@@ -2125,6 +2127,20 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes
21252127

21262128
LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir)
21272129

2130+
project_config = config_parser.extract_node_configuration(module_path)
2131+
2132+
web_dir_name = project_config.tool_comfy.web
2133+
2134+
if web_dir_name:
2135+
web_dir_path = os.path.join(module_path, web_dir_name)
2136+
2137+
if os.path.isdir(web_dir_path):
2138+
project_name = project_config.project.name
2139+
2140+
EXTENSION_WEB_DIRS[project_name] = web_dir_path
2141+
2142+
logging.info("Automatically register web folder {} for {}".format(web_dir_name, project_name))
2143+
21282144
if hasattr(module, "WEB_DIRECTORY") and getattr(module, "WEB_DIRECTORY") is not None:
21292145
web_dir = os.path.abspath(os.path.join(module_dir, getattr(module, "WEB_DIRECTORY")))
21302146
if os.path.isdir(web_dir):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ spandrel
2525
soundfile
2626
av>=14.2.0
2727
pydantic~=2.0
28+
pydantic-settings~=2.0

0 commit comments

Comments
 (0)