diff --git a/glob/cnr_utils.py b/glob/cnr_utils.py index 14c609da..67dfa1e6 100644 --- a/glob/cnr_utils.py +++ b/glob/cnr_utils.py @@ -35,16 +35,21 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True): page = 1 full_nodes = {} - - # Get ComfyUI version tag - comfyui_tag = manager_core.get_comfyui_tag() or 'unknown' + # Determine form factor based on environment and platform is_desktop = bool(os.environ.get('__COMFYUI_DESKTOP_VERSION__')) system = platform.system().lower() is_windows = system == 'windows' is_mac = system == 'darwin' - + + # Get ComfyUI version tag + if is_desktop: + # extract version from pyproject.toml instead of git tag + comfyui_ver = manager_core.get_current_comfyui_ver() or 'unknown' + else: + comfyui_ver = manager_core.get_comfyui_tag() or 'unknown' + if is_desktop: if is_windows: form_factor = 'desktop-win' @@ -62,8 +67,8 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True): while remained: # Add comfyui_version and form_factor to the API request - sub_uri = f'{base_url}/nodes?page={page}&limit=30&comfyui_version={comfyui_tag}&form_factor={form_factor}' - sub_json_obj = await asyncio.wait_for(manager_util.get_data_with_cache(sub_uri, cache_mode=False, silent=True), timeout=30) + sub_uri = f'{base_url}/nodes?page={page}&limit=30&comfyui_version={comfyui_ver}&form_factor={form_factor}' + sub_json_obj = await asyncio.wait_for(manager_util.get_data_with_cache(sub_uri, cache_mode=False, silent=True, dont_cache=True), timeout=30) remained = page < sub_json_obj['totalPages'] for x in sub_json_obj['nodes']: diff --git a/glob/manager_core.py b/glob/manager_core.py index 5b54266b..a195d3e1 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -23,6 +23,7 @@ import yaml import zipfile import traceback from concurrent.futures import ThreadPoolExecutor, as_completed +import toml orig_print = print @@ -81,6 +82,24 @@ def get_comfyui_tag(): return None +def get_current_comfyui_ver(): + """ + Extract version from pyproject.toml + """ + toml_path = os.path.join(comfy_path, 'pyproject.toml') + if not os.path.exists(toml_path): + return None + else: + try: + with open(toml_path, "r", encoding="utf-8") as f: + data = toml.load(f) + + project = data.get('project', {}) + return project.get('version') + except: + return None + + def get_script_env(): new_env = os.environ.copy() git_exe = get_config().get('git_exe') @@ -154,7 +173,7 @@ def check_invalid_nodes(): # read env vars -comfy_path = os.environ.get('COMFYUI_PATH') +comfy_path: str = os.environ.get('COMFYUI_PATH') comfy_base_path = os.environ.get('COMFYUI_FOLDERS_BASE_PATH') if comfy_path is None: diff --git a/glob/manager_util.py b/glob/manager_util.py index 1a6aed1c..63932a87 100644 --- a/glob/manager_util.py +++ b/glob/manager_util.py @@ -180,7 +180,7 @@ def save_to_cache(uri, json_obj, silent=False): logging.info(f"[ComfyUI-Manager] default cache updated: {uri}") -async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=False): +async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=False, dont_cache=False): cache_uri = get_cache_path(uri) if cache_mode and dont_wait: @@ -199,11 +199,12 @@ async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=Fals json_obj = await get_data(cache_uri, silent=silent) else: json_obj = await get_data(uri, silent=silent) - with cache_lock: - with open(cache_uri, "w", encoding='utf-8') as file: - json.dump(json_obj, file, indent=4, sort_keys=True) - if not silent: - logging.info(f"[ComfyUI-Manager] default cache updated: {uri}") + if not dont_cache: + with cache_lock: + with open(cache_uri, "w", encoding='utf-8') as file: + json.dump(json_obj, file, indent=4, sort_keys=True) + if not silent: + logging.info(f"[ComfyUI-Manager] default cache updated: {uri}") return json_obj