Skip to content

Use dynamic node ID when registering extension entry #8

@christian-byrne

Description

@christian-byrne

The repo name and the node ID in the pyproject use underscores:

jtydhr88/ComfyUI_frontend_vue_basic <- underscore

underscores:

name = "comfyui_frontend_vue_basic"

But when registering entry point it uses hyphens:

nodes.EXTENSION_WEB_DIRS["ComfyUI-frontend-vue-basic"] = js_dir


Maybe this is not a serious issue especially when expecting user to set ID manually, but can we still use the id from the pyproject.toml (and fallback to folder name) instead of hard-coding "ComfyUI-frontend-vue-basic"?

For example:

╭──────────────────────────────────────────────────────╮
│ Edit file                                            │
│ ╭──────────────────────────────────────────────────╮ │
│ │ __init__.py                                      │ │
│ │                                                  │ │
│ │  1  from .ComfyUIFEExampleVueBasic import NODE_  │ │
│ │    CLASS_MAPPINGS                                │ │
│ │  2  import os                                    │ │
│ │  3  import nodes                                 │ │
+ │ │  4  import tomllib                               │ │
+ │ │  5                                               │ │
+ │ │  6  def get_project_name():                      │ │
+ │ │  7      try:                                     │ │
+ │ │  8          pyproject_path = os.path.join(os.pa  │ │
+ │ │    th.dirname(os.path.realpath(__file__)), "pyp  │ │
+ │ │    roject.toml")                                 │ │
+ │ │  9          with open(pyproject_path, "rb") as   │ │
+ │ │    f:                                            │ │
+ │ │ 10              data = tomllib.load(f)           │ │
+ │ │ 11              return data["project"]["name"]   │ │
+ │ │ 12      except Exception:                        │ │
+ │ │ 13          return "ComfyUI_frontend_vue_basic"  │ │
│ │ 14                                               │ │
│ │ 15  js_dir = os.path.join(os.path.dirname(os.pa  │ │
│ │    th.realpath(__file__)), "js")                 │ │
│ │ 16                                               │ │
- │ │ 17  nodes.EXTENSION_WEB_DIRS["ComfyUI_frontend_v │ │
- │ │ ue_basic"] = js_dir                              │ │
+ │ │ 17  nodes.EXTENSION_WEB_DIRS[get_project_name()] │ │
+ │ │  = js_dir                                        │ │
│ │ 18                                               │ │
│ │ 19  __all__ = ['NODE_CLASS_MAPPINGS']            │ │
│ ╰──────────────────────────────────────────────────╯ │

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions