fixed: address abnormal encoding of 'requirements.txt'

improved: better error message

https://github.com/ltdrdata/ComfyUI-Manager/issues/1513
This commit is contained in:
Dr.Lt.Data 2025-02-16 10:05:29 +09:00
parent 661586d3b6
commit 60a5e4f261
5 changed files with 47 additions and 24 deletions

View File

@ -42,7 +42,7 @@ import manager_downloader
from node_package import InstalledNodePackage
version_code = [3, 21, 3]
version_code = [3, 21, 4]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
@ -815,14 +815,14 @@ class UnifiedManager:
print("Install: pip packages")
pip_fixer = manager_util.PIPFixer(manager_util.get_installed_packages())
res = True
with open(requirements_path, "r") as requirements_file:
for line in requirements_file:
package_name = remap_pip_package(line.strip())
if package_name and not package_name.startswith('#') and package_name not in self.processed_install:
self.processed_install.add(package_name)
install_cmd = manager_util.make_pip_cmd(["install", package_name])
if package_name.strip() != "" and not package_name.startswith('#'):
res = res and try_install_script(url, repo_path, install_cmd, instant_execution=instant_execution)
lines = manager_util.robust_readlines(requirements_path)
for line in lines:
package_name = remap_pip_package(line.strip())
if package_name and not package_name.startswith('#') and package_name not in self.processed_install:
self.processed_install.add(package_name)
install_cmd = manager_util.make_pip_cmd(["install", package_name])
if package_name.strip() != "" and not package_name.startswith('#'):
res = res and try_install_script(url, repo_path, install_cmd, instant_execution=instant_execution)
pip_fixer.fix_broken()
return res
@ -1252,7 +1252,8 @@ class UnifiedManager:
return result.fail(f"Failed to execute install script: {url}")
except Exception as e:
return result.fail(f"Install(git-clone) error: {url} / {e}")
traceback.print_exc()
return result.fail(f"Install(git-clone) error[2]: {url} / {e}")
print("Installation was successful.")
return result
@ -2048,8 +2049,8 @@ async def gitclone_install(url, instant_execution=False, msg_prefix='', no_deps=
except Exception as e:
traceback.print_exc()
print(f"Install(git-clone) error: {url} / {e}", file=sys.stderr)
return result.fail(f"Install(git-clone) error: {url} / {e}")
print(f"Install(git-clone) error[1]: {url} / {e}", file=sys.stderr)
return result.fail(f"Install(git-clone)[1] error: {url} / {e}")
def git_pull(path):
@ -2148,7 +2149,7 @@ def gitclone_fix(files, instant_execution=False, no_deps=False):
return False
except Exception as e:
print(f"Install(git-clone) error: {url} / {e}", file=sys.stderr)
print(f"Fix(git-clone) error: {url} / {e}", file=sys.stderr)
return False
print(f"Attempt to fixing '{files}' is done.")

View File

@ -12,6 +12,7 @@ import subprocess
import sys
import re
import logging
import chardet
cache_lock = threading.Lock()
@ -373,3 +374,22 @@ def sanitize(data):
def sanitize_filename(input_string):
result_string = re.sub(r'[^a-zA-Z0-9_]', '_', input_string)
return result_string
def robust_readlines(fullpath):
try:
with open(fullpath, "r") as f:
return f.readlines()
except:
encoding = None
with open(fullpath, "rb") as f:
raw_data = f.read()
result = chardet.detect(raw_data)
encoding = result['encoding']
if encoding is not None:
with open(fullpath, "r", encoding=encoding) as f:
return f.readlines()
print(f"[ComfyUI-Manager] Failed to recognize encoding for: {fullpath}")
return []

View File

@ -598,17 +598,18 @@ def execute_lazy_install_script(repo_path, executable):
if os.path.exists(requirements_path):
print(f"Install: pip packages for '{repo_path}'")
with open(requirements_path, "r") as requirements_file:
for line in requirements_file:
package_name = remap_pip_package(line.strip())
if package_name and not is_installed(package_name):
if '--index-url' in package_name:
s = package_name.split('--index-url')
install_cmd = manager_util.make_pip_cmd(["install", s[0].strip(), '--index-url', s[1].strip()])
else:
install_cmd = manager_util.make_pip_cmd(["install", package_name])
process_wrap(install_cmd, repo_path)
lines = manager_util.robust_readlines(requirements_path)
for line in lines:
package_name = remap_pip_package(line.strip())
if package_name and not is_installed(package_name):
if '--index-url' in package_name:
s = package_name.split('--index-url')
install_cmd = manager_util.make_pip_cmd(["install", s[0].strip(), '--index-url', s[1].strip()])
else:
install_cmd = manager_util.make_pip_cmd(["install", package_name])
process_wrap(install_cmd, repo_path)
if os.path.exists(install_script_path) and f'{repo_path}/install.py' not in processed_install:
processed_install.add(f'{repo_path}/install.py')

View File

@ -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.21.3"
version = "3.21.4"
license = { file = "LICENSE.txt" }
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]

View File

@ -8,3 +8,4 @@ rich
typing-extensions
toml
uv
chardet