-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Comfy-Org/rh-publish
Publish Node: Parse comfynode.toml and calls publisherNodeVersion api.
- Loading branch information
Showing
8 changed files
with
174 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .api import publish_node_version | ||
|
||
# Import specific functions from the config_parser module | ||
from .config_parser import extract_node_configuration | ||
from .types import PyProjectConfig | ||
|
||
__all__ = ["publish_node_version", "extract_node_configuration", "PyProjectConfig"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import requests | ||
import json | ||
from comfy_cli import constants | ||
from comfy_cli.registry.types import PyProjectConfig | ||
|
||
|
||
def publish_node_version(node_config: PyProjectConfig, token: str): | ||
""" | ||
Publishes a new version of a node. | ||
Args: | ||
node_config (PyProjectConfig): The node configuration. | ||
token (str): Personal access token for authentication. | ||
Returns: | ||
dict: JSON response from the API server. | ||
""" | ||
url = f"{constants.COMFY_REGISTRY_URL_ROOT}/publishers/{node_config.tool_comfy.publisher_id}/nodes/{node_config.project.name}/versions" | ||
headers = {"Content-Type": "application/json"} | ||
body = { | ||
"personal_access_token": token, | ||
"node": { | ||
"id": node_config.project.name, | ||
"description": node_config.project.description, | ||
"name": node_config.tool_comfy.display_name, | ||
"license": node_config.project.license, | ||
"repository": node_config.project.urls.repository, | ||
}, | ||
"node_version": { | ||
"version": node_config.project.version, | ||
"dependencies": node_config.project.dependencies, | ||
}, | ||
} | ||
|
||
response = requests.post(url, headers=headers, data=json.dumps(body)) | ||
# print the json of response | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
raise Exception( | ||
f"Failed to publish node version: {response.status_code} {response.text}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
from comfy_cli.registry.types import ( | ||
PyProjectConfig, | ||
ProjectConfig, | ||
URLs, | ||
Model, | ||
ComfyConfig, | ||
) | ||
|
||
|
||
def extract_node_configuration( | ||
path: str = os.path.join(os.getcwd(), "comfynode.toml"), | ||
) -> PyProjectConfig: | ||
import tomlkit | ||
|
||
with open(path, "r") as file: | ||
data = tomlkit.load(file) | ||
|
||
project_data = data.get("project", {}) | ||
urls_data = project_data.get("urls", {}) | ||
comfy_data = data.get("tool", {}).get("comfy", {}) | ||
|
||
project = ProjectConfig( | ||
name=project_data.get("name", ""), | ||
description=project_data.get("description", ""), | ||
version=project_data.get("version", ""), | ||
requires_python=project_data.get("requires-pyton", ""), | ||
dependencies=project_data.get("dependencies", []), | ||
license=project_data.get("license", ""), | ||
urls=URLs( | ||
homepage=urls_data.get("Homepage", ""), | ||
documentation=urls_data.get("Documentation", ""), | ||
repository=urls_data.get("Repository", ""), | ||
issues=urls_data.get("Issues", ""), | ||
), | ||
) | ||
|
||
comfy = ComfyConfig( | ||
publisher_id=comfy_data.get("PublisherId", ""), | ||
display_name=comfy_data.get("DisplayName", ""), | ||
icon=comfy_data.get("Icon", ""), | ||
models=[ | ||
Model(location=m["location"], model_url=m["model_url"]) | ||
for m in comfy_data.get("Models", []) | ||
], | ||
) | ||
|
||
return PyProjectConfig(project=project, tool_comfy=comfy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from dataclasses import dataclass, field | ||
from typing import List | ||
|
||
|
||
@dataclass | ||
class URLs: | ||
homepage: str = "" | ||
documentation: str = "" | ||
repository: str = "" | ||
issues: str = "" | ||
|
||
|
||
@dataclass | ||
class Model: | ||
location: str | ||
model_url: str | ||
|
||
|
||
@dataclass | ||
class ComfyConfig: | ||
publisher_id: str = "" | ||
display_name: str = "" | ||
icon: str = "" | ||
models: List[Model] = field(default_factory=list) | ||
|
||
|
||
@dataclass | ||
class ProjectConfig: | ||
name: str = "" | ||
description: str = "" | ||
version: str = "1.0.0" | ||
requires_python: str = ">= 3.9" | ||
dependencies: List[str] = field(default_factory=list) | ||
license: str = "" | ||
urls: URLs = URLs() | ||
|
||
|
||
@dataclass | ||
class PyProjectConfig: | ||
project: ProjectConfig = ProjectConfig() | ||
tool_comfy: ComfyConfig = ComfyConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ GitPython | |
requests | ||
pyyaml | ||
typing-extensions | ||
mixpanel | ||
mixpanel | ||
tomlkit |