comfy-env 0.0.18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. comfy_env-0.0.18/.github/workflows/publish.yml +28 -0
  2. comfy_env-0.0.18/.gitignore +32 -0
  3. comfy_env-0.0.18/LICENSE +21 -0
  4. comfy_env-0.0.18/PKG-INFO +229 -0
  5. comfy_env-0.0.18/README.md +201 -0
  6. comfy_env-0.0.18/examples/basic_node/__init__.py +5 -0
  7. comfy_env-0.0.18/examples/basic_node/comfy-env.toml +65 -0
  8. comfy_env-0.0.18/examples/basic_node/nodes.py +157 -0
  9. comfy_env-0.0.18/examples/basic_node/worker.py +79 -0
  10. comfy_env-0.0.18/examples/decorator_node/__init__.py +9 -0
  11. comfy_env-0.0.18/examples/decorator_node/nodes.py +182 -0
  12. comfy_env-0.0.18/pyproject.toml +50 -0
  13. comfy_env-0.0.18/src/comfy_env/__init__.py +133 -0
  14. comfy_env-0.0.18/src/comfy_env/cli.py +486 -0
  15. comfy_env-0.0.18/src/comfy_env/decorator.py +427 -0
  16. comfy_env-0.0.18/src/comfy_env/env/__init__.py +47 -0
  17. comfy_env-0.0.18/src/comfy_env/env/config.py +158 -0
  18. comfy_env-0.0.18/src/comfy_env/env/config_file.py +658 -0
  19. comfy_env-0.0.18/src/comfy_env/env/cuda_gpu_detection.py +303 -0
  20. comfy_env-0.0.18/src/comfy_env/env/manager.py +674 -0
  21. comfy_env-0.0.18/src/comfy_env/env/platform/__init__.py +21 -0
  22. comfy_env-0.0.18/src/comfy_env/env/platform/base.py +96 -0
  23. comfy_env-0.0.18/src/comfy_env/env/platform/darwin.py +53 -0
  24. comfy_env-0.0.18/src/comfy_env/env/platform/linux.py +68 -0
  25. comfy_env-0.0.18/src/comfy_env/env/platform/windows.py +284 -0
  26. comfy_env-0.0.18/src/comfy_env/env/security.py +267 -0
  27. comfy_env-0.0.18/src/comfy_env/errors.py +293 -0
  28. comfy_env-0.0.18/src/comfy_env/install.py +587 -0
  29. comfy_env-0.0.18/src/comfy_env/ipc/__init__.py +55 -0
  30. comfy_env-0.0.18/src/comfy_env/ipc/bridge.py +476 -0
  31. comfy_env-0.0.18/src/comfy_env/ipc/protocol.py +265 -0
  32. comfy_env-0.0.18/src/comfy_env/ipc/tensor.py +371 -0
  33. comfy_env-0.0.18/src/comfy_env/ipc/torch_bridge.py +401 -0
  34. comfy_env-0.0.18/src/comfy_env/ipc/transport.py +318 -0
  35. comfy_env-0.0.18/src/comfy_env/ipc/worker.py +221 -0
  36. comfy_env-0.0.18/src/comfy_env/registry.py +91 -0
  37. comfy_env-0.0.18/src/comfy_env/resolver.py +388 -0
  38. comfy_env-0.0.18/src/comfy_env/stubs/__init__.py +1 -0
  39. comfy_env-0.0.18/src/comfy_env/stubs/folder_paths.py +61 -0
  40. comfy_env-0.0.18/src/comfy_env/tools.py +221 -0
  41. comfy_env-0.0.18/src/comfy_env/wheel_sources.yml +153 -0
  42. comfy_env-0.0.18/src/comfy_env/workers/__init__.py +49 -0
  43. comfy_env-0.0.18/src/comfy_env/workers/base.py +82 -0
  44. comfy_env-0.0.18/src/comfy_env/workers/pool.py +241 -0
  45. comfy_env-0.0.18/src/comfy_env/workers/tensor_utils.py +188 -0
  46. comfy_env-0.0.18/src/comfy_env/workers/torch_mp.py +389 -0
  47. comfy_env-0.0.18/src/comfy_env/workers/venv.py +903 -0
  48. comfy_env-0.0.18/untitled.txt +0 -0
@@ -0,0 +1,28 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write # Required for trusted publishing
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.11"
20
+
21
+ - name: Install build tools
22
+ run: pip install build
23
+
24
+ - name: Build package
25
+ run: python -m build
26
+
27
+ - name: Publish to PyPI
28
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.so
5
+ *.egg
6
+ *.egg-info/
7
+ dist/
8
+ build/
9
+ .eggs/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ ENV/
15
+
16
+ # IDE
17
+ .idea/
18
+ .vscode/
19
+ *.swp
20
+ *.swo
21
+
22
+ # Jupyter
23
+ .ipynb_checkpoints/
24
+
25
+ # Testing
26
+ .pytest_cache/
27
+ .coverage
28
+ htmlcov/
29
+
30
+ # OS
31
+ .DS_Store
32
+ Thumbs.db
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andrea Pozzetti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: comfy-env
3
+ Version: 0.0.18
4
+ Summary: Environment management for ComfyUI custom nodes - CUDA wheel resolution and process isolation
5
+ Project-URL: Homepage, https://github.com/PozzettiAndrea/comfy-env
6
+ Project-URL: Repository, https://github.com/PozzettiAndrea/comfy-env
7
+ Project-URL: Issues, https://github.com/PozzettiAndrea/comfy-env/issues
8
+ Author: Andrea Pozzetti
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: comfyui,cuda,environment,isolation,process,venv,wheels
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: pyyaml>=6.0
21
+ Requires-Dist: tomli>=2.0.0; python_version < '3.11'
22
+ Requires-Dist: uv>=0.4.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: mypy; extra == 'dev'
25
+ Requires-Dist: pytest; extra == 'dev'
26
+ Requires-Dist: ruff; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # comfy-env
30
+
31
+ Environment management for ComfyUI custom nodes. Provides:
32
+
33
+ 1. **CUDA Wheel Resolution** - Install pre-built CUDA wheels (nvdiffrast, pytorch3d) without compilation
34
+ 2. **Process Isolation** - Run nodes in separate Python environments with their own dependencies
35
+
36
+ ## Why?
37
+
38
+ ComfyUI custom nodes face two challenges:
39
+
40
+ **Type 1: Dependency Conflicts**
41
+ - Node A needs `torch==2.1.0` with CUDA 11.8
42
+ - Node B needs `torch==2.8.0` with CUDA 12.8
43
+
44
+ **Type 2: CUDA Package Installation**
45
+ - Users don't have compilers installed
46
+ - Building from source takes forever
47
+ - pip install fails with cryptic errors
48
+
49
+ This package solves both problems.
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ pip install comfy-env
55
+ ```
56
+
57
+ Requires [uv](https://github.com/astral-sh/uv) for fast environment creation:
58
+
59
+ ```bash
60
+ curl -LsSf https://astral.sh/uv/install.sh | sh
61
+ ```
62
+
63
+ ## Quick Start
64
+
65
+ ### In-Place Installation (Type 2 - CUDA Wheels)
66
+
67
+ Create a `comfy-env.toml` in your node directory:
68
+
69
+ ```toml
70
+ [env]
71
+ name = "my-node"
72
+ python = "3.10"
73
+ cuda = "auto"
74
+
75
+ [packages]
76
+ requirements = ["transformers>=4.56", "pillow"]
77
+ no_deps = ["nvdiffrast==0.4.0", "pytorch3d>=0.7.8"]
78
+
79
+ [sources]
80
+ wheel_sources = ["https://github.com/PozzettiAndrea/nvdiffrast-full-wheels/releases/download/"]
81
+ ```
82
+
83
+ Then in your `__init__.py`:
84
+
85
+ ```python
86
+ from comfy_env import install
87
+
88
+ # Install CUDA wheels into current environment
89
+ install()
90
+ ```
91
+
92
+ ### Process Isolation (Type 1 - Separate Venv)
93
+
94
+ For nodes that need completely separate dependencies:
95
+
96
+ ```python
97
+ from comfy_env import isolated
98
+
99
+ @isolated(env="my-node")
100
+ class MyNode:
101
+ FUNCTION = "process"
102
+ RETURN_TYPES = ("IMAGE",)
103
+
104
+ def process(self, image):
105
+ # Runs in isolated subprocess with its own venv
106
+ import conflicting_package
107
+ return (result,)
108
+ ```
109
+
110
+ ## CLI
111
+
112
+ ```bash
113
+ # Show detected environment
114
+ comfy-env info
115
+
116
+ # Install from config
117
+ comfy-env install
118
+
119
+ # Dry run (show what would be installed)
120
+ comfy-env install --dry-run
121
+
122
+ # Resolve wheel URLs without installing
123
+ comfy-env resolve nvdiffrast==0.4.0
124
+
125
+ # Verify installation
126
+ comfy-env doctor
127
+ ```
128
+
129
+ ## Configuration
130
+
131
+ ### comfy-env.toml
132
+
133
+ ```toml
134
+ [env]
135
+ name = "my-node" # Unique name for caching
136
+ python = "3.10" # Python version
137
+ cuda = "auto" # "auto", "12.8", "12.4", or null
138
+
139
+ [packages]
140
+ requirements = [ # Regular pip packages
141
+ "transformers>=4.56",
142
+ "pillow",
143
+ ]
144
+ no_deps = [ # CUDA packages (installed with --no-deps)
145
+ "nvdiffrast==0.4.0",
146
+ "pytorch3d>=0.7.8",
147
+ ]
148
+
149
+ [sources]
150
+ wheel_sources = [ # GitHub releases with pre-built wheels
151
+ "https://github.com/.../releases/download/",
152
+ ]
153
+ index_urls = [ # Extra pip index URLs
154
+ "https://pypi.org/simple/",
155
+ ]
156
+
157
+ [worker] # For isolation mode
158
+ package = "worker" # worker/__main__.py
159
+ ```
160
+
161
+ ### Template Variables
162
+
163
+ Wheel URLs support these template variables:
164
+
165
+ | Variable | Example | Description |
166
+ |----------|---------|-------------|
167
+ | `{cuda_version}` | `12.8` | Full CUDA version |
168
+ | `{cuda_short}` | `128` | CUDA without dot |
169
+ | `{torch_version}` | `2.8.0` | PyTorch version |
170
+ | `{torch_mm}` | `28` | PyTorch major.minor |
171
+ | `{py_version}` | `3.10` | Python version |
172
+ | `{py_short}` | `310` | Python without dot |
173
+ | `{platform}` | `linux_x86_64` | Platform tag |
174
+
175
+ ## API Reference
176
+
177
+ ### install()
178
+
179
+ ```python
180
+ from comfy_env import install
181
+
182
+ # Auto-discover config
183
+ install()
184
+
185
+ # Explicit config
186
+ install(config="comfy-env.toml")
187
+
188
+ # Isolated mode (creates separate venv)
189
+ install(mode="isolated")
190
+
191
+ # Dry run
192
+ install(dry_run=True)
193
+ ```
194
+
195
+ ### WheelResolver
196
+
197
+ ```python
198
+ from comfy_env import RuntimeEnv, WheelResolver
199
+
200
+ env = RuntimeEnv.detect()
201
+ resolver = WheelResolver()
202
+
203
+ url = resolver.resolve("nvdiffrast", "0.4.0", env)
204
+ print(url) # https://github.com/.../nvdiffrast-0.4.0+cu128torch28-...whl
205
+ ```
206
+
207
+ ### Workers (for isolation)
208
+
209
+ ```python
210
+ from comfy_env import TorchMPWorker
211
+
212
+ # Same-venv isolation (zero-copy tensors)
213
+ worker = TorchMPWorker()
214
+ result = worker.call(my_function, image=tensor)
215
+ ```
216
+
217
+ ## GPU Detection
218
+
219
+ ```python
220
+ from comfy_env import detect_cuda_version, get_gpu_summary
221
+
222
+ cuda = detect_cuda_version() # "12.8", "12.4", or None
223
+ print(get_gpu_summary())
224
+ # GPU 0: NVIDIA GeForce RTX 5090 (sm_120) [Blackwell - CUDA 12.8]
225
+ ```
226
+
227
+ ## License
228
+
229
+ MIT - see LICENSE file.
@@ -0,0 +1,201 @@
1
+ # comfy-env
2
+
3
+ Environment management for ComfyUI custom nodes. Provides:
4
+
5
+ 1. **CUDA Wheel Resolution** - Install pre-built CUDA wheels (nvdiffrast, pytorch3d) without compilation
6
+ 2. **Process Isolation** - Run nodes in separate Python environments with their own dependencies
7
+
8
+ ## Why?
9
+
10
+ ComfyUI custom nodes face two challenges:
11
+
12
+ **Type 1: Dependency Conflicts**
13
+ - Node A needs `torch==2.1.0` with CUDA 11.8
14
+ - Node B needs `torch==2.8.0` with CUDA 12.8
15
+
16
+ **Type 2: CUDA Package Installation**
17
+ - Users don't have compilers installed
18
+ - Building from source takes forever
19
+ - pip install fails with cryptic errors
20
+
21
+ This package solves both problems.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install comfy-env
27
+ ```
28
+
29
+ Requires [uv](https://github.com/astral-sh/uv) for fast environment creation:
30
+
31
+ ```bash
32
+ curl -LsSf https://astral.sh/uv/install.sh | sh
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ ### In-Place Installation (Type 2 - CUDA Wheels)
38
+
39
+ Create a `comfy-env.toml` in your node directory:
40
+
41
+ ```toml
42
+ [env]
43
+ name = "my-node"
44
+ python = "3.10"
45
+ cuda = "auto"
46
+
47
+ [packages]
48
+ requirements = ["transformers>=4.56", "pillow"]
49
+ no_deps = ["nvdiffrast==0.4.0", "pytorch3d>=0.7.8"]
50
+
51
+ [sources]
52
+ wheel_sources = ["https://github.com/PozzettiAndrea/nvdiffrast-full-wheels/releases/download/"]
53
+ ```
54
+
55
+ Then in your `__init__.py`:
56
+
57
+ ```python
58
+ from comfy_env import install
59
+
60
+ # Install CUDA wheels into current environment
61
+ install()
62
+ ```
63
+
64
+ ### Process Isolation (Type 1 - Separate Venv)
65
+
66
+ For nodes that need completely separate dependencies:
67
+
68
+ ```python
69
+ from comfy_env import isolated
70
+
71
+ @isolated(env="my-node")
72
+ class MyNode:
73
+ FUNCTION = "process"
74
+ RETURN_TYPES = ("IMAGE",)
75
+
76
+ def process(self, image):
77
+ # Runs in isolated subprocess with its own venv
78
+ import conflicting_package
79
+ return (result,)
80
+ ```
81
+
82
+ ## CLI
83
+
84
+ ```bash
85
+ # Show detected environment
86
+ comfy-env info
87
+
88
+ # Install from config
89
+ comfy-env install
90
+
91
+ # Dry run (show what would be installed)
92
+ comfy-env install --dry-run
93
+
94
+ # Resolve wheel URLs without installing
95
+ comfy-env resolve nvdiffrast==0.4.0
96
+
97
+ # Verify installation
98
+ comfy-env doctor
99
+ ```
100
+
101
+ ## Configuration
102
+
103
+ ### comfy-env.toml
104
+
105
+ ```toml
106
+ [env]
107
+ name = "my-node" # Unique name for caching
108
+ python = "3.10" # Python version
109
+ cuda = "auto" # "auto", "12.8", "12.4", or null
110
+
111
+ [packages]
112
+ requirements = [ # Regular pip packages
113
+ "transformers>=4.56",
114
+ "pillow",
115
+ ]
116
+ no_deps = [ # CUDA packages (installed with --no-deps)
117
+ "nvdiffrast==0.4.0",
118
+ "pytorch3d>=0.7.8",
119
+ ]
120
+
121
+ [sources]
122
+ wheel_sources = [ # GitHub releases with pre-built wheels
123
+ "https://github.com/.../releases/download/",
124
+ ]
125
+ index_urls = [ # Extra pip index URLs
126
+ "https://pypi.org/simple/",
127
+ ]
128
+
129
+ [worker] # For isolation mode
130
+ package = "worker" # worker/__main__.py
131
+ ```
132
+
133
+ ### Template Variables
134
+
135
+ Wheel URLs support these template variables:
136
+
137
+ | Variable | Example | Description |
138
+ |----------|---------|-------------|
139
+ | `{cuda_version}` | `12.8` | Full CUDA version |
140
+ | `{cuda_short}` | `128` | CUDA without dot |
141
+ | `{torch_version}` | `2.8.0` | PyTorch version |
142
+ | `{torch_mm}` | `28` | PyTorch major.minor |
143
+ | `{py_version}` | `3.10` | Python version |
144
+ | `{py_short}` | `310` | Python without dot |
145
+ | `{platform}` | `linux_x86_64` | Platform tag |
146
+
147
+ ## API Reference
148
+
149
+ ### install()
150
+
151
+ ```python
152
+ from comfy_env import install
153
+
154
+ # Auto-discover config
155
+ install()
156
+
157
+ # Explicit config
158
+ install(config="comfy-env.toml")
159
+
160
+ # Isolated mode (creates separate venv)
161
+ install(mode="isolated")
162
+
163
+ # Dry run
164
+ install(dry_run=True)
165
+ ```
166
+
167
+ ### WheelResolver
168
+
169
+ ```python
170
+ from comfy_env import RuntimeEnv, WheelResolver
171
+
172
+ env = RuntimeEnv.detect()
173
+ resolver = WheelResolver()
174
+
175
+ url = resolver.resolve("nvdiffrast", "0.4.0", env)
176
+ print(url) # https://github.com/.../nvdiffrast-0.4.0+cu128torch28-...whl
177
+ ```
178
+
179
+ ### Workers (for isolation)
180
+
181
+ ```python
182
+ from comfy_env import TorchMPWorker
183
+
184
+ # Same-venv isolation (zero-copy tensors)
185
+ worker = TorchMPWorker()
186
+ result = worker.call(my_function, image=tensor)
187
+ ```
188
+
189
+ ## GPU Detection
190
+
191
+ ```python
192
+ from comfy_env import detect_cuda_version, get_gpu_summary
193
+
194
+ cuda = detect_cuda_version() # "12.8", "12.4", or None
195
+ print(get_gpu_summary())
196
+ # GPU 0: NVIDIA GeForce RTX 5090 (sm_120) [Blackwell - CUDA 12.8]
197
+ ```
198
+
199
+ ## License
200
+
201
+ MIT - see LICENSE file.
@@ -0,0 +1,5 @@
1
+ """Example ComfyUI node using process isolation."""
2
+
3
+ from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
4
+
5
+ __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
@@ -0,0 +1,65 @@
1
+ # Example isolation configuration for a ComfyUI custom node.
2
+ #
3
+ # This file defines the isolated Python environment for your node.
4
+ # The comfyui-isolation library will auto-discover this file.
5
+ #
6
+ # Usage in your node:
7
+ # bridge = WorkerBridge.from_config_file(
8
+ # node_dir=Path(__file__).parent,
9
+ # worker_script=Path(__file__).parent / "worker.py",
10
+ # )
11
+
12
+ [env]
13
+ # Unique name for this environment (used for caching)
14
+ name = "example-node"
15
+
16
+ # Python version
17
+ python = "3.10"
18
+
19
+ # CUDA version: "auto" (detect), "12.4", "12.8", or null (CPU only)
20
+ cuda = "auto"
21
+
22
+ # Optional: specific PyTorch version (if not specified, latest from index is used)
23
+ # pytorch_version = "2.4.1"
24
+
25
+
26
+ [packages]
27
+ # Required packages
28
+ requirements = [
29
+ "torch",
30
+ "torchvision",
31
+ "pillow",
32
+ "numpy",
33
+ ]
34
+
35
+ # Optional: path to additional requirements.txt (relative to this file's directory)
36
+ # requirements_file = "requirements.txt"
37
+
38
+
39
+ [sources]
40
+ # Custom wheel repositories (passed as --find-links to pip)
41
+ # wheel_sources = [
42
+ # "https://my-custom-wheels.github.io/",
43
+ # ]
44
+
45
+ # Extra package indexes (passed as --extra-index-url to pip)
46
+ # index_urls = [
47
+ # "https://test.pypi.org/simple/",
48
+ # ]
49
+
50
+
51
+ [variables]
52
+ # Define variables for substitution in requirements.
53
+ # You can reference these with {variable_name} syntax.
54
+ #
55
+ # Auto-populated variables (no need to define):
56
+ # {cuda_version} - e.g., "12.4"
57
+ # {cuda_short} - e.g., "124"
58
+ # {pytorch_version} - e.g., "2.9.1"
59
+ # {pytorch_short} - e.g., "291" (version without dots)
60
+ # {pytorch_mm} - e.g., "29" (major.minor without dot, for wheel names)
61
+ #
62
+ # Example:
63
+ # pytorch_version = "2.4.1"
64
+ # pytorch3d_version = "0.7.8+5043d15pt{pytorch_version}cu{cuda_short}"
65
+ # flex_gemm = "0.0.1+cu{cuda_short}torch{pytorch_mm}"