From 36f48b865671262f6e8df8f3646bb0e30532edde Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Mon, 17 Feb 2025 22:32:26 +0900 Subject: [PATCH] feat: custom pip_blacklist https://github.com/ltdrdata/ComfyUI-Manager/issues/1560 --- README.md | 6 +++++- cm-cli.py | 17 ++++++++++++++++- glob/manager_core.py | 5 ++++- prestartup_script.py | 11 ++++++++++- pyproject.toml | 2 +- scripts/install-comfyui-venv-win.bat | 2 +- .../install-manager-for-portable-version.bat | 1 + 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 410848ac..7d22e87f 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ In `ComfyUI-Manager` V3.0 and later, configuration files and dynamically generat * Basic config files: `/default/ComfyUI-Manager/config.ini` * Configurable channel lists: `/default/ComfyUI-Manager/channels.ini` * Configurable pip overrides: `/default/ComfyUI-Manager/pip_overrides.json` +* Configurable pip blacklist: `/default/ComfyUI-Manager/pip_overrides.list` * Saved snapshot files: `/default/ComfyUI-Manager/snapshots` * Startup script files: `/default/ComfyUI-Manager/startup-scripts` * Component files: `/default/ComfyUI-Manager/components` @@ -301,7 +302,10 @@ The following settings are applied based on the section marked as `is_default`. * Custom pip mapping * When you create the `pip_overrides.json` file, it changes the installation of specific pip packages to installations defined by the user. * Please refer to the `pip_overrides.json.template` file. - + +* Prevent the installation of specific pip packages + * List the package names one per line in the `pip_blacklist.list` file. + * Use `aria2` as downloader * [howto](docs/en/use_aria2.md) diff --git a/cm-cli.py b/cm-cli.py index d9b1d63c..190ba84e 100644 --- a/cm-cli.py +++ b/cm-cli.py @@ -43,7 +43,7 @@ import cnr_utils comfyui_manager_path = os.path.abspath(os.path.dirname(__file__)) -cm_global.pip_blacklist = ['torch', 'torchsde', 'torchvision'] +cm_global.pip_blacklist = {'torch', 'torchsde', 'torchvision'} cm_global.pip_downgrade_blacklist = ['torch', 'torchsde', 'torchvision', 'transformers', 'safetensors', 'kornia'] cm_global.pip_overrides = {'numpy': 'numpy<2'} @@ -52,6 +52,14 @@ if os.path.exists(os.path.join(manager_util.comfyui_manager_path, "pip_overrides cm_global.pip_overrides = json.load(json_file) +if os.path.exists(os.path.join(manager_util.comfyui_manager_path, "pip_blacklist.list")): + with open(os.path.join(manager_util.comfyui_manager_path, "pip_blacklist.list"), 'r', encoding="UTF-8", errors="ignore") as f: + for x in f.readlines(): + y = x.strip() + if y != '': + cm_global.pip_blacklist.add(y) + + def check_comfyui_hash(): repo = git.Repo(comfy_path) core.comfy_ui_revision = len(list(repo.iter_commits('HEAD'))) @@ -137,6 +145,13 @@ class Ctx: cm_global.pip_overrides = json.load(json_file) cm_global.pip_overrides = {'numpy': 'numpy<2'} + if os.path.exists(core.manager_pip_blacklist_path): + with open(core.manager_pip_blacklist_path, 'r', encoding="UTF-8", errors="ignore") as f: + for x in f.readlines(): + y = x.strip() + if y != '': + cm_global.pip_blacklist.add(y) + @staticmethod def get_startup_scripts_path(): return os.path.join(core.manager_startup_script_path, "install-scripts.txt") diff --git a/glob/manager_core.py b/glob/manager_core.py index 4d2dfa26..311cdf4a 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -42,7 +42,7 @@ import manager_downloader from node_package import InstalledNodePackage -version_code = [3, 22, 2] +version_code = [3, 23] version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') @@ -177,6 +177,7 @@ manager_channel_list_path = None manager_startup_script_path:str = None manager_snapshot_path = None manager_pip_overrides_path = None +manager_pip_blacklist_path = None manager_components_path = None def update_user_directory(user_dir): @@ -186,6 +187,7 @@ def update_user_directory(user_dir): global manager_startup_script_path global manager_snapshot_path global manager_pip_overrides_path + global manager_pip_blacklist_path global manager_components_path manager_files_path = os.path.abspath(os.path.join(user_dir, 'default', 'ComfyUI-Manager')) @@ -203,6 +205,7 @@ def update_user_directory(user_dir): manager_config_path = os.path.join(manager_files_path, 'config.ini') manager_channel_list_path = os.path.join(manager_files_path, 'channels.list') manager_pip_overrides_path = os.path.join(manager_files_path, "pip_overrides.json") + manager_pip_blacklist_path = os.path.join(manager_files_path, "pip_blacklist.list") manager_components_path = os.path.join(manager_files_path, "components") manager_util.cache_dir = os.path.join(manager_files_path, "cache") diff --git a/prestartup_script.py b/prestartup_script.py index 7dd1acc6..323fb887 100644 --- a/prestartup_script.py +++ b/prestartup_script.py @@ -34,7 +34,7 @@ else: security_check.security_check() -cm_global.pip_blacklist = ['torch', 'torchsde', 'torchvision'] +cm_global.pip_blacklist = {'torch', 'torchsde', 'torchvision'} cm_global.pip_downgrade_blacklist = ['torch', 'torchsde', 'torchvision', 'transformers', 'safetensors', 'kornia'] @@ -82,6 +82,7 @@ comfyui_manager_path = os.path.abspath(os.path.dirname(__file__)) 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") +manager_pip_blacklist_path = os.path.join(manager_files_path, "pip_blacklist.list") 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') @@ -122,6 +123,14 @@ if os.path.exists(manager_pip_overrides_path): cm_global.pip_overrides['ultralytics'] = 'ultralytics==8.3.40' # for security +if os.path.exists(manager_pip_blacklist_path): + with open(manager_pip_blacklist_path, 'r', encoding="UTF-8", errors="ignore") as f: + for x in f.readlines(): + y = x.strip() + if y != '': + cm_global.pip_blacklist.add(y) + + def remap_pip_package(pkg): if pkg in cm_global.pip_overrides: res = cm_global.pip_overrides[pkg] diff --git a/pyproject.toml b/pyproject.toml index d08a2eb8..58d5ab52 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.22.2" +version = "3.23" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"] diff --git a/scripts/install-comfyui-venv-win.bat b/scripts/install-comfyui-venv-win.bat index 46c7ee14..47470098 100755 --- a/scripts/install-comfyui-venv-win.bat +++ b/scripts/install-comfyui-venv-win.bat @@ -6,7 +6,7 @@ python -m venv venv call venv/Scripts/activate python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 python -m pip install -r requirements.txt -python -m pip install -r custom_nodes/ComfyUI-Manager/requirements.txt +python -m pip install -r custom_nodes/comfyui-manager/requirements.txt cd .. echo "cd ComfyUI" >> run_gpu.bat echo "call venv/Scripts/activate" >> run_gpu.bat diff --git a/scripts/install-manager-for-portable-version.bat b/scripts/install-manager-for-portable-version.bat index ad4e97b5..6eb58b74 100644 --- a/scripts/install-manager-for-portable-version.bat +++ b/scripts/install-manager-for-portable-version.bat @@ -1,2 +1,3 @@ .\python_embeded\python.exe -s -m pip install gitpython .\python_embeded\python.exe -c "import git; git.Repo.clone_from('https://github.com/ltdrdata/ComfyUI-Manager', './ComfyUI/custom_nodes/comfyui-manager')" +.\python_embeded\python.exe -m pip install -r ./ComfyUI/custom_nodes/comfyui-manager/requirements.txt