From 784d32c8ecab6990f6a6be9f75357029da7a770b Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Sun, 5 Jan 2025 11:18:53 +0900 Subject: [PATCH] revise /customnode/installed improved: don't fetch data from cnr for the api improved: change format {: } -> {: [, ]} --- glob/cnr_utils.py | 23 +++++++++++++++++++++++ glob/manager_core.py | 28 +++++++++++++++++++++++++++- glob/manager_server.py | 20 +++++++++++++------- pyproject.toml | 2 +- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/glob/cnr_utils.py b/glob/cnr_utils.py index b56b900b..6e964cb6 100644 --- a/glob/cnr_utils.py +++ b/glob/cnr_utils.py @@ -129,3 +129,26 @@ def read_cnr_info(fullpath): return None except Exception: return None # not valid CNR node pack + + +def generate_cnr_id(fullpath, cnr_id): + cnr_id_path = os.path.join(fullpath, '.git', '.cnr-id') + try: + if not os.path.exists(cnr_id_path): + with open(cnr_id_path, "w") as f: + return f.write(cnr_id) + except: + print(f"[ComfyUI Manager] unable to create file: {cnr_id_path}") + + +def read_cnr_id(fullpath): + cnr_id_path = os.path.join(fullpath, '.git', '.cnr-id') + try: + if not os.path.exists(cnr_id_path): + with open(cnr_id_path) as f: + return f.read().strip() + except: + pass + + return None + diff --git a/glob/manager_core.py b/glob/manager_core.py index f59f706d..7de81d69 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -36,7 +36,7 @@ import manager_downloader from node_package import InstalledNodePackage -version_code = [3, 3, 10] +version_code = [3, 4] version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') @@ -457,6 +457,7 @@ class UnifiedManager: cnr = self.get_cnr_by_repo(url) commit_hash = git_utils.get_commit_hash(fullpath) if cnr: + cnr_utils.generate_cnr_id(fullpath, cnr['id']) return {'id': cnr['id'], 'cnr': cnr, 'ver': 'nightly', 'hash': commit_hash} else: url = os.path.basename(url) @@ -1318,6 +1319,7 @@ class UnifiedManager: if version_spec == 'unknown': self.unknown_active_nodes[node_id] = to_path elif version_spec == 'nightly': + cnr_utils.generate_cnr_id(to_path, node_id) self.active_nodes[node_id] = 'nightly', to_path return res.with_target(version_spec) @@ -1370,6 +1372,30 @@ class UnifiedManager: unified_manager = UnifiedManager() +def identify_node_pack_from_path(fullpath): + module_name = os.path.basename(fullpath) + if module_name.endswith('.git'): + module_name = module_name[:-4] + + repo_url = git_utils.git_url(fullpath) + if repo_url is None: + # cnr + cnr = cnr_utils.read_cnr_info(fullpath) + if cnr is not None: + return module_name, cnr['version'], cnr['id'] + + return None + else: + # nightly or unknown + cnr_id = cnr_utils.read_cnr_id(fullpath) + commit_hash = git_utils.get_commit_hash(fullpath) + + if cnr_id is not None: + return module_name, commit_hash, cnr_id + else: + return module_name, commit_hash, '' + + def get_channel_dict(): global channel_dict diff --git a/glob/manager_server.py b/glob/manager_server.py index 5fcddff0..6f59163a 100644 --- a/glob/manager_server.py +++ b/glob/manager_server.py @@ -539,15 +539,21 @@ def populate_markdown(x): @routes.get("/customnode/installed") async def installed_list(request): - unified_manager = core.unified_manager + res = {} - await unified_manager.reload('cache') - await unified_manager.get_custom_nodes('default', 'cache') + for x in core.get_custom_nodes_paths(): + for y in os.listdir(x): + if y == '__pycache__' or y.endswith('.disabled'): + continue - return web.json_response({ - node_id: package.version if package.is_from_cnr else package.get_commit_hash() - for node_id, package in unified_manager.installed_node_packages.items() if not package.disabled - }, content_type='application/json') + fullpath = os.path.join(x, y) + info = core.identify_node_pack_from_path(fullpath) + if info is None: + continue + + res[info[0]] = [info[1], info[2]] + + return web.json_response(res, content_type='application/json') @routes.get("/customnode/getlist") diff --git a/pyproject.toml b/pyproject.toml index 543e491c..a668c2a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-manager" description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." -version = "3.3.10" +version = "3.4" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]