Skip to content

Commit a249961

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

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-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: 104 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,84 @@ 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+
98+
valid_os_prefixes = {"Microsoft", "POSIX", "MacOS", "OS Independent"}
99+
has_invalid_os = False
100+
101+
for os_value in os_values:
102+
if not any(os_value.startswith(prefix) for prefix in valid_os_prefixes):
103+
has_invalid_os = True
104+
break
105+
106+
if has_invalid_os:
107+
typer.echo(
108+
'Warning: Invalid Operating System classifier found. Operating System classifiers must start with one of: "Microsoft", "POSIX", "MacOS", "OS Independent". '
109+
'Examples: "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Operating System :: MacOS", "Operating System :: OS Independent". '
110+
'No OS information will be populated.'
111+
)
112+
return []
113+
else:
114+
return os_values
115+
116+
117+
def validate_and_extract_accelerator_classifiers(classifiers: list) -> list:
118+
accelerator_classifiers = [c for c in classifiers if c.startswith("Environment ::")]
119+
if not accelerator_classifiers:
120+
return []
121+
122+
accelerator_values = [c[len("Environment :: "):] for c in accelerator_classifiers]
123+
124+
valid_accelerators = {
125+
"GPU :: NVIDIA CUDA",
126+
"GPU :: AMD ROCm",
127+
"GPU :: Intel Arc",
128+
"NPU :: Huawei Ascend",
129+
"GPU :: Apple Metal",
130+
}
131+
has_invalid_accelerator = False
132+
133+
for accelerator_value in accelerator_values:
134+
if accelerator_value not in valid_accelerators:
135+
has_invalid_accelerator = True
136+
break
137+
138+
if has_invalid_accelerator:
139+
typer.echo(
140+
'Warning: Invalid Environment classifier found. Environment classifiers must be one of: '
141+
'"Environment :: GPU :: NVIDIA CUDA", "Environment :: GPU :: AMD ROCm", "Environment :: GPU :: Intel Arc", '
142+
'"Environment :: NPU :: Huawei Ascend", "Environment :: GPU :: Apple Metal". '
143+
'No accelerator information will be populated.'
144+
)
145+
return []
146+
else:
147+
return accelerator_values
148+
149+
150+
def validate_version(version: str, field_name: str) -> str:
151+
if not version:
152+
return version
153+
154+
version_pattern = r'^(?:(==|>=|<=|!=|~=|>|<|<>|=)\s*)?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+)?)?$'
155+
156+
if not re.match(version_pattern, version):
157+
typer.echo(
158+
f'Warning: Invalid {field_name} format: "{version}". '
159+
f'Version must follow the pattern: [operator][version] where operator is optional (==, >=, <=, !=, ~=, >, <, <>, =) '
160+
f'and version is in format major.minor.patch[-suffix]. '
161+
f'Examples: ">=1.0.0", "==2.1.0-beta", "1.5.2". '
162+
f'No {field_name} will be populated.'
163+
)
164+
return ""
165+
166+
return version
167+
168+
90169
def initialize_project_config():
91170
create_comfynode_config()
92171

@@ -157,6 +236,26 @@ def extract_node_configuration(
157236
urls_data = project_data.get("urls", {})
158237
comfy_data = data.get("tool", {}).get("comfy", {})
159238

239+
dependencies = project_data.get("dependencies", [])
240+
supported_comfyui_frontend_version = ""
241+
for dep in dependencies:
242+
if isinstance(dep, str) and dep.startswith("comfyui-frontend-package"):
243+
supported_comfyui_frontend_version = dep
244+
break
245+
246+
# Remove the ComfyUI-frontend dependency from the dependencies list
247+
dependencies = [
248+
dep for dep in dependencies if not (isinstance(dep, str) and dep.startswith("comfyui-frontend-package"))
249+
]
250+
251+
supported_comfyui_version = data.get("tool", {}).get("requires-comfyui", "")
252+
253+
classifiers = project_data.get("classifiers", [])
254+
supported_os = validate_and_extract_os_classifiers(classifiers)
255+
supported_accelerators = validate_and_extract_accelerator_classifiers(classifiers)
256+
supported_comfyui_version = validate_version(supported_comfyui_version, "requires-comfyui")
257+
supported_comfyui_frontend_version = validate_version(supported_comfyui_frontend_version, "comfyui-frontend-package")
258+
160259
license_data = project_data.get("license", {})
161260
if isinstance(license_data, str):
162261
license = License(text=license_data)
@@ -182,14 +281,18 @@ def extract_node_configuration(
182281
description=project_data.get("description", ""),
183282
version=project_data.get("version", ""),
184283
requires_python=project_data.get("requires-python", ""),
185-
dependencies=project_data.get("dependencies", []),
284+
dependencies=dependencies,
186285
license=license,
187286
urls=URLs(
188287
homepage=urls_data.get("Homepage", ""),
189288
documentation=urls_data.get("Documentation", ""),
190289
repository=urls_data.get("Repository", ""),
191290
issues=urls_data.get("Issues", ""),
192291
),
292+
supported_os=supported_os,
293+
supported_accelerators=supported_accelerators,
294+
supported_comfyui_version=supported_comfyui_version,
295+
supported_comfyui_frontend_version=supported_comfyui_frontend_version,
193296
)
194297

195298
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)