From 34151b03eff9803d508ec0b77bfcbedc89347a0c Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Wed, 15 Jan 2025 12:24:19 +0900 Subject: [PATCH] refactor: print -> logging fixed: log message - manager-core -> ComfyUI-Manager --- glob/manager_core.py | 2 +- glob/manager_util.py | 40 +++++++++++++++++++++------------------- pyproject.toml | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/glob/manager_core.py b/glob/manager_core.py index ffd400ab..12231f96 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -41,7 +41,7 @@ import manager_downloader from node_package import InstalledNodePackage -version_code = [3, 7, 4] +version_code = [3, 7, 5] version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') diff --git a/glob/manager_util.py b/glob/manager_util.py index 9fb6a914..9c7d4b83 100644 --- a/glob/manager_util.py +++ b/glob/manager_util.py @@ -125,7 +125,7 @@ async def get_data(uri, silent=False): json_obj = json.loads(json_text) if not silent: - print(" [DONE]") + logging.info(" [DONE]") return json_obj @@ -154,7 +154,7 @@ async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=Fals with open(cache_uri, "w", encoding='utf-8') as file: json.dump(json_obj, file, indent=4, sort_keys=True) if not silent: - print(f"[ComfyUI-Manager] default cache updated: {uri}") + logging.info(f"[ComfyUI-Manager] default cache updated: {uri}") return json_obj @@ -169,10 +169,10 @@ def extract_package_as_zip(file_path, extract_path): with zipfile.ZipFile(file_path, "r") as zip_ref: zip_ref.extractall(extract_path) extracted_files = zip_ref.namelist() - print(f"Extracted zip file to {extract_path}") + logging.info(f"Extracted zip file to {extract_path}") return extracted_files except zipfile.BadZipFile: - print(f"File '{file_path}' is not a zip or is corrupted.") + logging.error(f"File '{file_path}' is not a zip or is corrupted.") return None @@ -196,7 +196,7 @@ def get_installed_packages(renew=False): pip_map[y[0]] = y[1] except subprocess.CalledProcessError: - print("[ComfyUI-Manager] Failed to retrieve the information of installed pip packages.") + logging.error("[ComfyUI-Manager] Failed to retrieve the information of installed pip packages.") return set() return pip_map @@ -236,7 +236,7 @@ class PIPFixer: else: cmd = [sys.executable, '-m', 'pip', 'install', '--force', 'torch', 'torchvision', 'torchaudio'] subprocess.check_output(cmd, universal_newlines=True) - print(cmd) + logging.error(cmd) return torch_ver = StrictVersion(spec[0]) @@ -247,12 +247,12 @@ class PIPFixer: cmd = [sys.executable, '-m', 'pip', 'install', '--pre', 'torch', 'torchvision', 'torchaudio', '--index-url', f"https://download.pytorch.org/whl/nightly/{platform}"] - print("[manager-core] restore PyTorch to nightly version") + logging.info("[ComfyUI-Manager] restore PyTorch to nightly version") else: cmd = [sys.executable, '-m', 'pip', 'install', f'torch=={torch_ver}', f'torchvision=={torchvision_ver}', f"torchaudio=={torch_ver}", '--index-url', f"https://download.pytorch.org/whl/{platform}"] - print(f"[manager-core] restore PyTorch to {torch_ver}+{platform}") + logging.info(f"[ComfyUI-Manager] restore PyTorch to {torch_ver}+{platform}") subprocess.check_output(cmd, universal_newlines=True) @@ -265,20 +265,22 @@ class PIPFixer: cmd = [sys.executable, '-m', 'pip', 'uninstall', 'comfy'] subprocess.check_output(cmd, universal_newlines=True) - print("[manager-core] 'comfy' python package is uninstalled.\nWARN: The 'comfy' package is completely unrelated to ComfyUI and should never be installed as it causes conflicts with ComfyUI.") + logging.warning("[ComfyUI-Manager] 'comfy' python package is uninstalled.\nWARN: The 'comfy' package is completely unrelated to ComfyUI and should never be installed as it causes conflicts with ComfyUI.") except Exception as e: - print("[manager-core] Failed to uninstall `comfy` python package") - print(e) + logging.error("[ComfyUI-Manager] Failed to uninstall `comfy` python package") + logging.error(e) # fix torch - reinstall torch packages if version is changed try: - if self.prev_pip_versions['torch'] != new_pip_versions['torch'] \ + if 'torch' not in self.prev_pip_versions or 'torchvision' not in self.prev_pip_versions or 'torchaudio' not in self.prev_pip_versions: + logging.error(f"[ComfyUI-Manager] PyTorch is not installed") + elif self.prev_pip_versions['torch'] != new_pip_versions['torch'] \ or self.prev_pip_versions['torchvision'] != new_pip_versions['torchvision'] \ or self.prev_pip_versions['torchaudio'] != new_pip_versions['torchaudio']: self.torch_rollback() except Exception as e: - print("[manager-core] Failed to restore PyTorch") - print(e) + logging.error("[ComfyUI-Manager] Failed to restore PyTorch") + logging.error(e) # fix opencv try: @@ -309,10 +311,10 @@ class PIPFixer: cmd = [sys.executable, '-m', 'pip', 'install', f"{x}=={versions[0].version_string}"] subprocess.check_output(cmd, universal_newlines=True) - print(f"[manager-core] 'opencv' dependencies were fixed: {targets}") + logging.info(f"[ComfyUI-Manager] 'opencv' dependencies were fixed: {targets}") except Exception as e: - print("[manager-core] Failed to restore opencv") - print(e) + logging.error("[ComfyUI-Manager] Failed to restore opencv") + logging.error(e) # fix numpy try: @@ -321,8 +323,8 @@ class PIPFixer: if StrictVersion(np) >= StrictVersion('2'): subprocess.check_output([sys.executable, '-m', 'pip', 'install', "numpy<2"], universal_newlines=True) except Exception as e: - print("[manager-core] Failed to restore numpy") - print(e) + logging.error("[ComfyUI-Manager] Failed to restore numpy") + logging.error(e) def sanitize(data): diff --git a/pyproject.toml b/pyproject.toml index f0583f15..594d83d3 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.7.4" +version = "3.7.5" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]