From fd164862f3bc8064fe9c6378048fdae5ef2bd011 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Thu, 9 Jan 2025 22:47:02 +0900 Subject: [PATCH] fixed: invalid config.ini path fixed: invalid environment setup for git_helper.py fixed: default pip overrides doesn't work modified: git_helper.py - use GIT_EXE_PATH env instead of config.ini improved: print user_directory and ComfyUI-Manager config path on startup --- cm-cli.py | 5 ++--- git_helper.py | 12 ++++-------- glob/manager_core.py | 26 ++++++++++++++++---------- glob/manager_server.py | 2 +- prestartup_script.py | 21 ++++++++++----------- pyproject.toml | 2 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cm-cli.py b/cm-cli.py index 8c227414..80dde26e 100644 --- a/cm-cli.py +++ b/cm-cli.py @@ -71,9 +71,8 @@ core.check_invalid_nodes() def read_downgrade_blacklist(): try: import configparser - config_path = os.path.join(os.path.dirname(__file__), "config.ini") config = configparser.ConfigParser() - config.read(config_path) + config.read(core.manager_config.path) default_conf = config['default'] if 'downgrade_blacklist' in default_conf: @@ -136,9 +135,9 @@ class Ctx: core.update_user_directory(user_directory) if os.path.exists(core.manager_pip_overrides_path): - cm_global.pip_overrides = {'numpy': 'numpy<2'} with open(core.manager_pip_overrides_path, 'r', encoding="UTF-8", errors="ignore") as json_file: cm_global.pip_overrides = json.load(json_file) + cm_global.pip_overrides = {'numpy': 'numpy<2'} @staticmethod def get_startup_scripts_path(): diff --git a/git_helper.py b/git_helper.py index eb7e3a9e..14c6b7e9 100644 --- a/git_helper.py +++ b/git_helper.py @@ -4,7 +4,6 @@ import os import traceback import git -import configparser import json import yaml import requests @@ -13,13 +12,13 @@ from git.remote import RemoteProgress comfy_path = os.environ.get('COMFYUI_PATH') +git_exe_path = os.environ.get('GIT_EXE_PATH') if comfy_path is None: - print("\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr) + print("\nWARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.", file=sys.stderr) comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) - def download_url(url, dest_folder, filename=None): # Ensure the destination folder exists if not os.path.exists(dest_folder): @@ -43,7 +42,6 @@ def download_url(url, dest_folder, filename=None): print(f"Failed to download file from {url}") -config_path = os.path.join(os.path.dirname(__file__), "config.ini") nodelist_path = os.path.join(os.path.dirname(__file__), "custom-node-list.json") working_directory = os.getcwd() @@ -440,10 +438,8 @@ def restore_pip_snapshot(pips, options): def setup_environment(): - config = configparser.ConfigParser() - config.read(config_path) - if 'default' in config and 'git_exe' in config['default'] and config['default']['git_exe'] != '': - git.Git().update_environment(GIT_PYTHON_GIT_EXECUTABLE=config['default']['git_exe']) + if git_exe_path is not None: + git.Git().update_environment(GIT_PYTHON_GIT_EXECUTABLE=git_exe_path) setup_environment() diff --git a/glob/manager_core.py b/glob/manager_core.py index d157a93c..e84ca38c 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, 4] +version_code = [3, 5] version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') @@ -50,6 +50,7 @@ DEFAULT_CHANNEL = "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/ma default_custom_nodes_path = None + def get_default_custom_nodes_path(): global default_custom_nodes_path if default_custom_nodes_path is None: @@ -79,6 +80,16 @@ def get_comfyui_tag(): return None +def get_script_env(): + copied = os.environ.copy() + git_exe = get_config().get('git_exe') + if git_exe is not None: + copied['GIT_EXE_PATH'] = git_exe + copied['COMFYUI_PATH'] = comfy_path + + return copied + + invalid_nodes = {} @@ -1480,9 +1491,7 @@ class ManagerFuncs: print(f"[ComfyUI-Manager] Unexpected behavior: `{cmd}`") return 0 - new_env = os.environ.copy() - new_env["COMFYUI_PATH"] = comfy_path - subprocess.check_call(cmd, cwd=cwd, env=new_env) + subprocess.check_call(cmd, cwd=cwd, env=get_script_env()) return 0 @@ -1639,9 +1648,8 @@ def __win_check_git_update(path, do_fetch=False, do_update=False): else: command = [sys.executable, git_script_path, "--check", path] - new_env = os.environ.copy() - new_env["COMFYUI_PATH"] = comfy_path - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=get_default_custom_nodes_path()) + new_env = get_script_env() + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=get_default_custom_nodes_path(), env=new_env) output, _ = process.communicate() output = output.decode('utf-8').strip() @@ -1692,10 +1700,8 @@ def __win_check_git_update(path, do_fetch=False, do_update=False): def __win_check_git_pull(path): - new_env = os.environ.copy() - new_env["COMFYUI_PATH"] = comfy_path command = [sys.executable, git_script_path, "--pull", path] - process = subprocess.Popen(command, env=new_env, cwd=get_default_custom_nodes_path()) + process = subprocess.Popen(command, env=get_script_env(), cwd=get_default_custom_nodes_path()) process.wait() diff --git a/glob/manager_server.py b/glob/manager_server.py index 89639594..94ec3dab 100644 --- a/glob/manager_server.py +++ b/glob/manager_server.py @@ -108,7 +108,7 @@ class ManagerFuncsInComfyUI(core.ManagerFuncs): logging.error(f"[ComfyUI-Manager] Unexpected behavior: `{cmd}`") return 0 - process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1) + process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, env=core.get_script_env()) stdout_thread = threading.Thread(target=handle_stream, args=(process.stdout, "")) stderr_thread = threading.Thread(target=handle_stream, args=(process.stderr, "[!]")) diff --git a/prestartup_script.py b/prestartup_script.py index be78264b..3a32b5d2 100644 --- a/prestartup_script.py +++ b/prestartup_script.py @@ -50,9 +50,8 @@ def check_file_logging(): global enable_file_logging try: import configparser - config_path = os.path.join(os.path.dirname(__file__), "config.ini") config = configparser.ConfigParser() - config.read(config_path) + config.read(manager_config_path) default_conf = config['default'] if 'file_logging' in default_conf and default_conf['file_logging'].lower() == 'false': @@ -79,12 +78,12 @@ custom_nodes_base_path = folder_paths.get_folder_paths('custom_nodes')[0] manager_files_path = os.path.abspath(os.path.join(folder_paths.get_user_directory(), 'default', 'ComfyUI-Manager')) manager_pip_overrides_path = os.path.join(manager_files_path, "pip_overrides.json") restore_snapshot_path = os.path.join(manager_files_path, "startup-scripts", "restore-snapshot.json") +manager_config_path = os.path.join(manager_files_path, 'config.ini') -git_script_path = os.path.join(comfyui_manager_path, "git_helper.py") cm_cli_path = os.path.join(comfyui_manager_path, "cm-cli.py") -cm_global.pip_overrides = {} +cm_global.pip_overrides = {'numpy': 'numpy<2', 'ultralytics': 'ultralytics==8.3.40'} if os.path.exists(manager_pip_overrides_path): with open(manager_pip_overrides_path, 'r', encoding="UTF-8", errors="ignore") as json_file: cm_global.pip_overrides = json.load(json_file) @@ -345,6 +344,9 @@ print("** Platform:", platform.system()) print("** Python version:", sys.version) print("** Python executable:", sys.executable) print("** ComfyUI Path:", comfy_path) +print("** User directory:", folder_paths.user_directory) +print("** ComfyUI-Manager config path:", manager_config_path) + if log_path_base is not None: print("** Log path:", os.path.abspath(f'{log_path_base}.log')) @@ -355,9 +357,8 @@ else: def read_downgrade_blacklist(): try: import configparser - config_path = os.path.join(os.path.dirname(__file__), "config.ini") config = configparser.ConfigParser() - config.read(config_path) + config.read(manager_config_path) default_conf = config['default'] if 'downgrade_blacklist' in default_conf: @@ -376,13 +377,12 @@ def check_bypass_ssl(): try: import configparser import ssl - config_path = os.path.join(os.path.dirname(__file__), "config.ini") config = configparser.ConfigParser() - config.read(config_path) + config.read(manager_config_path) default_conf = config['default'] if 'bypass_ssl' in default_conf and default_conf['bypass_ssl'].lower() == 'true': - print("[ComfyUI-Manager] WARN: Unsafe - SSL verification bypass option is Enabled. (see ComfyUI-Manager/config.ini)") + print(f"[ComfyUI-Manager] WARN: Unsafe - SSL verification bypass option is Enabled. (see {manager_config_path})") ssl._create_default_https_context = ssl._create_unverified_context # SSL certificate error fix. except Exception: pass @@ -648,9 +648,8 @@ manager_util.clear_pip_cache() def check_windows_event_loop_policy(): try: import configparser - config_path = os.path.join(os.path.dirname(__file__), "config.ini") config = configparser.ConfigParser() - config.read(config_path) + config.read(manager_config_path) default_conf = config['default'] if 'windows_selector_event_loop_policy' in default_conf and default_conf['windows_selector_event_loop_policy'].lower() == 'true': diff --git a/pyproject.toml b/pyproject.toml index a668c2a5..0ecd4199 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.4" +version = "3.5" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]