mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2026-03-29 12:53:34 +08:00
* feat: add pygit2 compatibility wrapper for standalone Desktop 2.0 installs Add git_compat.py abstraction layer that wraps both GitPython and pygit2 behind a unified GitRepo interface. When CM_USE_PYGIT2=1 is set (by the Desktop 2.0 Launcher for standalone installs), or when system git is not available, the pygit2 backend is used automatically. Key changes: - New comfyui_manager/common/git_compat.py with abstract GitRepo base class, _GitPythonRepo (1:1 pass-throughs) and _Pygit2Repo implementations - All 6 non-legacy files updated to use the wrapper: - comfyui_manager/glob/manager_core.py (14 git.Repo usages) - comfyui_manager/common/git_helper.py (7 git.Repo usages) - comfyui_manager/common/context.py (1 usage) - comfyui_manager/glob/utils/environment_utils.py (2 usages) - cm_cli/__main__.py (1 usage) - comfyui_manager/common/timestamp_utils.py (repo.heads usage) - get_script_env() propagates CM_USE_PYGIT2 to subprocesses - git_helper.py uses sys.path.insert to find git_compat as standalone script - All repo handles wrapped in context managers to prevent resource leaks - get_head_by_name returns _HeadProxy for interface consistency - Submodule fallback logs clear message when system git is absent - 47 tests comparing both backends via subprocess isolation Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d0ec5-cb9f-74df-a1a2-0c8154a330b3 * fix(pygit2): address review findings + bump version to 4.2b1 - C1: add submodule_update() after pygit2 clone for recursive parity - C2: check subprocess returncode in submodule_update fallback - C3: move GIT_OPT_SET_OWNER_VALIDATION to module-level (once at import) - H1: use context manager in git_pull() to prevent resource leaks - Bump version to 4.2b1, version_code to [4, 2] - Add pygit2 to dev dependencies and requirements.txt * style: fix ruff F841 unused variable and F541 unnecessary f-string --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Dr.Lt.Data <dr.lt.data@gmail.com>
127 lines
4.4 KiB
Python
127 lines
4.4 KiB
Python
import os
|
|
from comfyui_manager.common.git_compat import open_repo, setup_git_environment
|
|
import logging
|
|
import traceback
|
|
|
|
from comfyui_manager.common import context
|
|
import folder_paths
|
|
|
|
from comfyui_manager.glob import manager_core as core
|
|
from comfyui_manager.common import cm_global
|
|
|
|
|
|
comfy_ui_hash = "-"
|
|
comfyui_tag = None
|
|
|
|
|
|
def print_comfyui_version():
|
|
global comfy_ui_hash
|
|
global comfyui_tag
|
|
|
|
is_detached = False
|
|
try:
|
|
with open_repo(os.path.dirname(folder_paths.__file__)) as repo:
|
|
core.comfy_ui_revision = repo.iter_commits_count()
|
|
|
|
comfy_ui_hash = repo.head_commit_hexsha
|
|
cm_global.variables["comfyui.revision"] = core.comfy_ui_revision
|
|
|
|
core.comfy_ui_commit_datetime = repo.head_commit_datetime
|
|
cm_global.variables["comfyui.commit_datetime"] = core.comfy_ui_commit_datetime
|
|
|
|
is_detached = repo.head_is_detached
|
|
current_branch = repo.active_branch_name
|
|
|
|
comfyui_tag = context.get_comfyui_tag()
|
|
|
|
try:
|
|
if (
|
|
not os.environ.get("__COMFYUI_DESKTOP_VERSION__")
|
|
and core.comfy_ui_commit_datetime.date()
|
|
< core.comfy_ui_required_commit_datetime.date()
|
|
):
|
|
logging.warning(
|
|
f"\n\n## [WARN] ComfyUI-Manager: Your ComfyUI version ({core.comfy_ui_revision})[{core.comfy_ui_commit_datetime.date()}] is too old. Please update to the latest version. ##\n\n"
|
|
)
|
|
except Exception:
|
|
pass
|
|
|
|
# process on_revision_detected -->
|
|
if "cm.on_revision_detected_handler" in cm_global.variables:
|
|
for k, f in cm_global.variables["cm.on_revision_detected_handler"]:
|
|
try:
|
|
f(core.comfy_ui_revision)
|
|
except Exception:
|
|
logging.error(f"[ERROR] '{k}' on_revision_detected_handler")
|
|
traceback.print_exc()
|
|
|
|
del cm_global.variables["cm.on_revision_detected_handler"]
|
|
else:
|
|
logging.warning(
|
|
"[ComfyUI-Manager] Some features are restricted due to your ComfyUI being outdated."
|
|
)
|
|
# <--
|
|
|
|
if current_branch == "master":
|
|
if comfyui_tag:
|
|
logging.info(
|
|
f"### ComfyUI Version: {comfyui_tag} | Released on '{core.comfy_ui_commit_datetime.date()}'"
|
|
)
|
|
else:
|
|
logging.info(
|
|
f"### ComfyUI Revision: {core.comfy_ui_revision} [{comfy_ui_hash[:8]}] | Released on '{core.comfy_ui_commit_datetime.date()}'"
|
|
)
|
|
else:
|
|
if comfyui_tag:
|
|
logging.info(
|
|
f"### ComfyUI Version: {comfyui_tag} on '{current_branch}' | Released on '{core.comfy_ui_commit_datetime.date()}'"
|
|
)
|
|
else:
|
|
logging.info(
|
|
f"### ComfyUI Revision: {core.comfy_ui_revision} on '{current_branch}' [{comfy_ui_hash[:8]}] | Released on '{core.comfy_ui_commit_datetime.date()}'"
|
|
)
|
|
except Exception:
|
|
if is_detached:
|
|
logging.info(
|
|
f"### ComfyUI Revision: {core.comfy_ui_revision} [{comfy_ui_hash[:8]}] *DETACHED | Released on '{core.comfy_ui_commit_datetime.date()}'"
|
|
)
|
|
else:
|
|
logging.info(
|
|
"### ComfyUI Revision: UNKNOWN (The currently installed ComfyUI is not a Git repository)"
|
|
)
|
|
|
|
|
|
def set_update_policy(mode):
|
|
core.get_config()["update_policy"] = mode
|
|
|
|
|
|
def set_db_mode(mode):
|
|
core.get_config()["db_mode"] = mode
|
|
|
|
|
|
def setup_environment():
|
|
git_exe = core.get_config()["git_exe"]
|
|
|
|
if git_exe != "":
|
|
setup_git_environment(git_exe)
|
|
|
|
|
|
def initialize_environment():
|
|
context.comfy_path = os.path.dirname(folder_paths.__file__)
|
|
core.js_path = os.path.join(context.comfy_path, "web", "extensions")
|
|
|
|
# Legacy database paths - kept for potential future use
|
|
# local_db_model = os.path.join(manager_util.comfyui_manager_path, "model-list.json")
|
|
# local_db_alter = os.path.join(manager_util.comfyui_manager_path, "alter-list.json")
|
|
# local_db_custom_node_list = os.path.join(
|
|
# manager_util.comfyui_manager_path, "custom-node-list.json"
|
|
# )
|
|
# local_db_extension_node_mappings = os.path.join(
|
|
# manager_util.comfyui_manager_path, "extension-node-map.json"
|
|
# )
|
|
|
|
print_comfyui_version()
|
|
setup_environment()
|
|
|
|
core.check_invalid_nodes()
|