First real generation through FunPack's nodes: SD1.5 on this Mac, real weights, a real picture of an apple. Everything before this was static. What it proved, on a real model rather than a fixture: the empty latent takes its shape from SD1.5's own format with no family branch anywhere (1, 4, 64, 64, an IMAGE latent from a pack built for video); the traits read off the live model are predict_eps and spatial_latent; and ALG is correctly absent, saying "needs temporal_latent", rather than running on a model with no time axis. What it found: the absolute-core-import bug again, this time INSIDE A FUNCTION BODY. It imported fine, registered fine, passed 258 tests, and raised at execute time -- during the generation. A suite that imports every module cannot see an import that only happens when a node runs, so the check for it is now static and walks the AST: no module may name `core` anywhere, at any nesting, except through the shim. The dev preview loaded one module in nine. It runs system python, which has neither ComfyUI nor torch, so every module that imports either was absent and the app looked almost empty while reporting nothing. It now re-execs under ComfyUI's interpreter. Looking at the app is meant to be how the app gets tested; it has to see what ComfyUI sees. ALG asked for a mount point no region offered, so its panel vanished in silence. The shell now offers one per stage, and a modules page lists what loaded, what asked for a mount nothing offers, and what failed to import -- absence is correct behaviour and indistinguishable from "never installed", so somewhere has to say which. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
"""No module may reach for `core` by absolute name.
|
|
|
|
ComfyUI loads a pack by file location and never puts its directory on sys.path,
|
|
so `from core import ...` inside a module resolves under pytest and finds nothing
|
|
under ComfyUI. This has now cost the same bug twice: once at module level, where
|
|
the node quietly failed to register, and once INSIDE A FUNCTION BODY, where it
|
|
imported fine, registered fine, passed every test, and raised at execute time --
|
|
during a real generation.
|
|
|
|
That second one is why this is a static check and not a runtime one. A test that
|
|
imports every module cannot see an import that only happens when a node runs.
|
|
"""
|
|
|
|
import ast
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
MODULES = Path(__file__).resolve().parents[2] / "modules"
|
|
SHIM = "_core.py"
|
|
|
|
|
|
def _module_files():
|
|
return [p for p in MODULES.rglob("*.py")
|
|
if p.name != SHIM and "/tests/" not in str(p) and p.parent.name != "tests"]
|
|
|
|
|
|
def _absolute_core_imports(path: Path):
|
|
"""Every `import core...` / `from core... import` anywhere in the file.
|
|
|
|
Walks the AST rather than the text, so an import nested in a function, a
|
|
method or a try block is found exactly like a top-level one.
|
|
"""
|
|
tree = ast.parse(path.read_text(), filename=str(path))
|
|
found = []
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.ImportFrom):
|
|
# level > 0 is relative, which is what the shim exists to provide.
|
|
if node.level == 0 and (node.module or "").split(".")[0] == "core":
|
|
found.append((node.lineno, f"from {node.module} import ..."))
|
|
elif isinstance(node, ast.Import):
|
|
for alias in node.names:
|
|
if alias.name.split(".")[0] == "core":
|
|
found.append((node.lineno, f"import {alias.name}"))
|
|
return found
|
|
|
|
|
|
def test_every_module_file_exists():
|
|
assert _module_files(), "found no module files to check"
|
|
|
|
|
|
@pytest.mark.parametrize("path", _module_files(), ids=lambda p: str(p.relative_to(MODULES)))
|
|
def test_a_module_reaches_core_only_through_the_shim(path):
|
|
offences = _absolute_core_imports(path)
|
|
assert not offences, (
|
|
f"{path.relative_to(MODULES)} imports core by absolute name at "
|
|
+ ", ".join(f"line {line} ({what})" for line, what in offences)
|
|
+ ". Under ComfyUI there is no top-level `core`. Use `from ..._core import ...`."
|
|
)
|