Files
FemtoStudio-comfyui-timeline/__init__.py
T

66 lines
2.6 KiB
Python

"""ComfyUI V3 entry point for ``comfyui-timeline-animation``.
The wrapper subpackage is named ``timelineanim_nodes`` (not the more
common ``custom_node``) to avoid a sys.modules collision with any
other ComfyUI custom-nodes pack that uses the same generic name.
Whichever pack loaded second would otherwise silently inherit the
first one's extension via Python's import cache.
"""
import logging
import os
import sys
logger = logging.getLogger(__name__)
# Use os.path.dirname (not Path.resolve) so symlinked custom_nodes/
# layouts don't get eagerly dereferenced.
_SRC = os.path.join(os.path.dirname(__file__), "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
# ``comfy_timeline`` (the public Python helper third-party packs import)
# is a generic top-level module name — the same sys.modules collision
# class the ``timelineanim_nodes`` rename above dodges for the node
# subpackage. If another pack already claimed the name, imports of
# ``comfy_timeline`` silently bind to THAT implementation, not ours;
# warn loudly so a mismatched API surfaces in the log instead of as
# quiet misbehaviour. (Real fix — a namespaced ``comfyui-timeline-core``
# pip package — is tracked but not shipped.)
_foreign = sys.modules.get("comfy_timeline")
if _foreign is not None:
_expected_dir = os.path.normcase(os.path.join(_SRC, "comfy_timeline"))
_actual_dir = os.path.normcase(
os.path.dirname(getattr(_foreign, "__file__", "") or ""),
)
if _actual_dir != _expected_dir:
logger.warning(
"comfyui-timeline-animation: a different 'comfy_timeline' "
"module is already imported from %r (ours lives at %r). "
"Consumers importing comfy_timeline will bind to that "
"implementation — API mismatches are possible.",
_actual_dir or "<unknown>", _expected_dir,
)
# Pytest collection in a non-ComfyUI env can hit this path without
# ``comfy_api`` available. Fall back to a sentinel so test collection
# doesn't fail at import time.
try:
from timelineanim_nodes import comfy_entrypoint
except ImportError as exc:
logger.warning(
"comfyui-timeline-animation: could not import comfy_entrypoint "
"(%s). Node will not register until ComfyUI's import chain is "
"available — expected in pytest runs without comfy on sys.path.",
exc,
)
comfy_entrypoint = None # type: ignore[assignment]
# ComfyUI resolves WEB_DIRECTORY relative to the __init__.py defining it.
WEB_DIRECTORY = "./src/timelineanim_nodes/web"
__all__ = [
"comfy_entrypoint",
"WEB_DIRECTORY",
]