From 825296c3e0152f2b694c8fde3027a2b48de624ee Mon Sep 17 00:00:00 2001 From: Vedat Baday <54285744+badayvedat@users.noreply.github.com> Date: Fri, 1 Nov 2024 20:39:08 +0000 Subject: [PATCH] fix: install manual (#794) --- install-manual.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/install-manual.py b/install-manual.py index 7d20c60..cc2b70c 100644 --- a/install-manual.py +++ b/install-manual.py @@ -1,10 +1,12 @@ import os +import re import shutil import sys import subprocess import threading import locale import traceback +from typing import Set if sys.argv[0] == 'install.py': @@ -66,6 +68,41 @@ def process_wrap(cmd_str, cwd=None, handler=None, env=None): stderr_thread.join() return process.wait() + + +def get_installed_packages() -> Set[str]: + try: + result = subprocess.check_output([sys.executable, '-m', 'pip', 'list'], universal_newlines=True) + pip_list = set([line.split()[0].lower() for line in result.split('\n') if line.strip()]) + return pip_list + except subprocess.CalledProcessError as e: + raise Exception(f"[ComfyUI-Impact-Pack] Failed to retrieve the information of installed pip packages.") + + +def is_package_installed(name: str) -> bool: + name = name.strip() + pattern = r'([^<>!=]+)([<>!=]=?)' + match = re.search(pattern, name) + + if match: + name = match.group(1) + + result = name.lower() in get_installed_packages() + return result + + +def is_requirements_installed(file_path: str) -> bool: + print(f"Requirements file: {file_path}") + if os.path.exists(file_path): + with open(file_path, "r") as file: + lines = file.readlines() + + for line in lines: + if not is_package_installed(line): + return False + +pip_install = [sys.executable, "-m", "pip", "install", "-U"] + # ---