Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making custom nodes installable via pip #2

Open
Chaoses-Ib opened this issue Jun 14, 2024 · 4 comments
Open

Making custom nodes installable via pip #2

Chaoses-Ib opened this issue Jun 14, 2024 · 4 comments

Comments

@Chaoses-Ib
Copy link

I noticed that this project is adding pyproject.toml to a lot of custom nodes. I'd like to ask if you are also interested in making custom nodes installable via pip. I've done some research about this and found that by using some special options in pyproject.toml, most custom nodes can be packaged and uploaded to PyPI without changing the project structure. Adding this to Comfy-PR should be simple since it's just adding more text to pyproject.toml and it's compatible with ComfyUI Registry.

For example, adding the following content to a custom node:

[project]
# CHANGE: The project name
name = "ComfyUI_Ib_CustomNodes"
version = "0.1.0"
# description = '...'
readme = "README.md"
# requires-python = ">=3.8"
# license = "MIT"
keywords = ["comfyui"]
dynamic = ["dependencies"]

[project.urls]
# CHANGE: Homepage, mostly the GitHub repository
Homepage = "https://github.com/Chaoses-Ib/ComfyUI_Ib_CustomNodes"
comfyui-legacy = "https://github.com/Chaoses-Ib/comfyui-legacy"

[build-system]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"

[tool.hatch.metadata.hooks.requirements_txt]
# CHANGE: Remove this section if there is no requirements.txt
files = ["requirements.txt"]

[tool.hatch.build.targets.sdist]
packages = ["."]

[tool.hatch.build.targets.wheel]
packages = ["."]
exclude = [
  "*.md",
  "/images",
  "/docs",
  "/examples",
  "/workflow_examples",
  "/tests",
]

[tool.hatch.build.targets.sdist.sources]
# CHANGE: Package name. Must be an valid Python id (no dashes)
"." = "ComfyUI_Ib_CustomNodes"

[tool.hatch.build.targets.wheel.sources]
# CHANGE: Same as above
"." = "ComfyUI_Ib_CustomNodes"

[project.entry-points."comfyui_legacy.custom_nodes"]
# CHANGE: Same as above
ComfyUI_Ib_CustomNodes = "ComfyUI_Ib_CustomNodes"

Then the custom node can be installed via pip:

pip install git+https://github.com/Chaoses-Ib/ComfyUI_Ib_CustomNodes.git

One problem with this is ComfyUI won't look up nodes installed via pip. This can be solved by installing a special custom node to loading them. This is already done in ComfyScript, but if you're interested, I can split the related code to a separate repo.

I've already done this change to some custom nodes, including:

@snomiao
Copy link
Member

snomiao commented Jun 14, 2024

@yoland68 Could you help me check this out?

@telamonian
Copy link
Member

@Chaoses-Ib There are already several efforts underway to do just this in ComfyUI core. My (completely unbiased, of course) preference is for comfyanonymous/ComfyUI#3608. In general, I do think it would be best to reuse as much of the existing Python machinery as possible, such as using the entry_point mechanism to do the node finding/loading. Please see also CEP 1.

@Chaoses-Ib
Copy link
Author

Nice PR. I know comfyanonymous/ComfyUI#298 has done something similar, but it has changed too many things and I'm afraid it'll never be merged. It'll be nice to see this kind of mechanism being merged one day.

In general, I do think it would be best to reuse as much of the existing Python machinery as possible

I have the same idea. That's why I'm here to ask whether you are willing to add this. I think it will be easier to first add this to custom nodes instead of changing their project structure, since that will break the old and current version of ComfyUI.

@Le09
Copy link

Le09 commented Aug 15, 2024

It would be nice to eventually have ComfyUI and custom nodes installable via pip. Right now there are a number of ways that deviate from the standard that are a bit confusing to get into. And maybe more importantly it causes a proliferation of ad-hoc solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants