Skip to content

Commit 401d252

Browse files
author
coderfromthenorth93
committed
Parse the supporting metadata and send to backend while publishing a node
1 parent 2e36f33 commit 401d252

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

comfy_cli/registry/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,18 @@ def publish_node_version(self, node_config: PyProjectConfig, token) -> PublishNo
5454
"name": node_config.tool_comfy.display_name,
5555
"license": license_json,
5656
"repository": node_config.project.urls.repository,
57+
"supported_os": node_config.project.supported_os,
58+
"supported_accelerators": node_config.project.supported_accelerators,
59+
"supported_comfyui_version": node_config.project.supported_comfyui_version,
60+
"supported_comfyui_frontend_version": node_config.project.supported_comfyui_frontend_version,
5761
},
5862
"node_version": {
5963
"version": node_config.project.version,
6064
"dependencies": node_config.project.dependencies,
65+
"supported_os": node_config.project.supported_os,
66+
"supported_accelerators": node_config.project.supported_accelerators,
67+
"supported_comfyui_version": node_config.project.supported_comfyui_version,
68+
"supported_comfyui_frontend_version": node_config.project.supported_comfyui_frontend_version,
6169
},
6270
}
6371
print(request_body)

comfy_cli/registry/config_parser.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import subprocess
34
from typing import Optional
45

@@ -87,6 +88,76 @@ def sanitize_node_name(name: str) -> str:
8788
return name
8889

8990

91+
def validate_and_extract_os_classifiers(classifiers: list) -> list:
92+
os_classifiers = [c for c in classifiers if c.startswith("Operating System :: ")]
93+
if not os_classifiers:
94+
return []
95+
96+
os_values = [c[len("Operating System :: "):] for c in os_classifiers]
97+
valid_os_prefixes = {"Microsoft", "POSIX", "MacOS", "OS Independent"}
98+
99+
for os_value in os_values:
100+
if not any(os_value.startswith(prefix) for prefix in valid_os_prefixes):
101+
typer.echo(
102+
'Warning: Invalid Operating System classifier found. Operating System classifiers must start with one of: "Microsoft", "POSIX", "MacOS", "OS Independent". '
103+
'Examples: "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Operating System :: MacOS", "Operating System :: OS Independent". '
104+
'No OS information will be populated.'
105+
)
106+
return []
107+
108+
return os_values
109+
110+
111+
def validate_and_extract_accelerator_classifiers(classifiers: list) -> list:
112+
accelerator_classifiers = [c for c in classifiers if c.startswith("Environment ::")]
113+
if not accelerator_classifiers:
114+
return []
115+
116+
accelerator_values = [c[len("Environment :: "):] for c in accelerator_classifiers]
117+
118+
valid_accelerators = {
119+
"GPU :: NVIDIA CUDA",
120+
"GPU :: AMD ROCm",
121+
"GPU :: Intel Arc",
122+
"NPU :: Huawei Ascend",
123+
"GPU :: Apple Metal",
124+
}
125+
126+
for accelerator_value in accelerator_values:
127+
if accelerator_value not in valid_accelerators:
128+
typer.echo(
129+
'Warning: Invalid Environment classifier found. Environment classifiers must be one of: '
130+
'"Environment :: GPU :: NVIDIA CUDA", "Environment :: GPU :: AMD ROCm", "Environment :: GPU :: Intel Arc", '
131+
'"Environment :: NPU :: Huawei Ascend", "Environment :: GPU :: Apple Metal". '
132+
'No accelerator information will be populated.'
133+
)
134+
return []
135+
136+
return accelerator_values
137+
138+
139+
def validate_version(version: str, field_name: str) -> str:
140+
if not version:
141+
return version
142+
143+
version_pattern = r'^(?:(==|>=|<=|!=|~=|>|<|<>|=)\s*)?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+)?)?$'
144+
145+
version_parts = [part.strip() for part in version.split(',')]
146+
for part in version_parts:
147+
if not re.match(version_pattern, part):
148+
typer.echo(
149+
f'Warning: Invalid {field_name} format: "{version}". '
150+
f'Each version part must follow the pattern: [operator][version] where operator is optional (==, >=, <=, !=, ~=, >, <, <>, =) '
151+
f'and version is in format major.minor.patch[-suffix]. '
152+
f'Multiple versions can be comma-separated. '
153+
f'Examples: ">=1.0.0", "==2.1.0-beta", "1.5.2", ">=1.0.0,<2.0.0". '
154+
f'No {field_name} will be populated.'
155+
)
156+
return ""
157+
158+
return version
159+
160+
90161
def initialize_project_config():
91162
create_comfynode_config()
92163

@@ -157,6 +228,26 @@ def extract_node_configuration(
157228
urls_data = project_data.get("urls", {})
158229
comfy_data = data.get("tool", {}).get("comfy", {})
159230

231+
dependencies = project_data.get("dependencies", [])
232+
supported_comfyui_frontend_version = ""
233+
for dep in dependencies:
234+
if isinstance(dep, str) and dep.startswith("comfyui-frontend-package"):
235+
supported_comfyui_frontend_version = dep.removeprefix("comfyui-frontend-package")
236+
break
237+
238+
# Remove the ComfyUI-frontend dependency from the dependencies list
239+
dependencies = [
240+
dep for dep in dependencies if not (isinstance(dep, str) and dep.startswith("comfyui-frontend-package"))
241+
]
242+
243+
supported_comfyui_version = data.get("tool", {}).get("requires-comfyui", "")
244+
245+
classifiers = project_data.get("classifiers", [])
246+
supported_os = validate_and_extract_os_classifiers(classifiers)
247+
supported_accelerators = validate_and_extract_accelerator_classifiers(classifiers)
248+
supported_comfyui_version = validate_version(supported_comfyui_version, "requires-comfyui")
249+
supported_comfyui_frontend_version = validate_version(supported_comfyui_frontend_version, "comfyui-frontend-package")
250+
160251
license_data = project_data.get("license", {})
161252
if isinstance(license_data, str):
162253
license = License(text=license_data)
@@ -182,14 +273,18 @@ def extract_node_configuration(
182273
description=project_data.get("description", ""),
183274
version=project_data.get("version", ""),
184275
requires_python=project_data.get("requires-python", ""),
185-
dependencies=project_data.get("dependencies", []),
276+
dependencies=dependencies,
186277
license=license,
187278
urls=URLs(
188279
homepage=urls_data.get("Homepage", ""),
189280
documentation=urls_data.get("Documentation", ""),
190281
repository=urls_data.get("Repository", ""),
191282
issues=urls_data.get("Issues", ""),
192283
),
284+
supported_os=supported_os,
285+
supported_accelerators=supported_accelerators,
286+
supported_comfyui_version=supported_comfyui_version,
287+
supported_comfyui_frontend_version=supported_comfyui_frontend_version,
193288
)
194289

195290
comfy = ComfyConfig(

comfy_cli/registry/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ class ProjectConfig:
6969
dependencies: List[str] = field(default_factory=list)
7070
license: License = field(default_factory=License)
7171
urls: URLs = field(default_factory=URLs)
72-
72+
supported_os: List[str] = field(default_factory=list)
73+
supported_accelerators: List[str] = field(default_factory=list)
74+
supported_comfyui_version: str = ""
75+
supported_comfyui_frontend_version: str = ""
7376

7477
@dataclass
7578
class PyProjectConfig:

0 commit comments

Comments
 (0)