From c35d494af517c740db5bf838f526f8909ab77564 Mon Sep 17 00:00:00 2001 From: "dr.lt.data" Date: Wed, 3 Apr 2024 15:25:14 +0900 Subject: [PATCH] fix: fallback mode for missing distutils --- __init__.py | 4 +-- glob/manager_util.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ prestartup_script.py | 9 ++----- 3 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 glob/manager_util.py diff --git a/__init__.py b/__init__.py index bfed725..c2bd6f3 100644 --- a/__init__.py +++ b/__init__.py @@ -17,7 +17,7 @@ import re import nodes import hashlib from datetime import datetime -from distutils.version import StrictVersion +from .glob.manager_util import * try: @@ -30,7 +30,7 @@ except: print(f"[WARN] ComfyUI-Manager: Your ComfyUI version is outdated. Please update to the latest version.") -version = [2, 13, 1] +version = [2, 14] version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '') print(f"### Loading: ComfyUI-Manager ({version_str})") diff --git a/glob/manager_util.py b/glob/manager_util.py new file mode 100644 index 0000000..5dc66b5 --- /dev/null +++ b/glob/manager_util.py @@ -0,0 +1,63 @@ +try: + from distutils.version import StrictVersion +except: + print(f"[ComfyUI-Manager] 'distutils' package not found. Activating fallback mode for compatibility.") + class StrictVersion: + def __init__(self, version_string): + self.version_string = version_string + self.major = 0 + self.minor = 0 + self.patch = 0 + self.pre_release = None + self.parse_version_string() + + def parse_version_string(self): + parts = self.version_string.split('.') + if not parts: + raise ValueError("Version string must not be empty") + + self.major = int(parts[0]) + self.minor = int(parts[1]) if len(parts) > 1 else 0 + self.patch = int(parts[2]) if len(parts) > 2 else 0 + + # Handling pre-release versions if present + if len(parts) > 3: + self.pre_release = parts[3] + + def __str__(self): + version = f"{self.major}.{self.minor}.{self.patch}" + if self.pre_release: + version += f"-{self.pre_release}" + return version + + def __eq__(self, other): + return (self.major, self.minor, self.patch, self.pre_release) == \ + (other.major, other.minor, other.patch, other.pre_release) + + def __lt__(self, other): + if (self.major, self.minor, self.patch) == (other.major, other.minor, other.patch): + return self.pre_release_compare(self.pre_release, other.pre_release) < 0 + return (self.major, self.minor, self.patch) < (other.major, other.minor, other.patch) + + @staticmethod + def pre_release_compare(pre1, pre2): + if pre1 == pre2: + return 0 + if pre1 is None: + return 1 + if pre2 is None: + return -1 + return -1 if pre1 < pre2 else 1 + + def __le__(self, other): + return self == other or self < other + + def __gt__(self, other): + return not self <= other + + def __ge__(self, other): + return not self < other + + def __ne__(self, other): + return not self == other + diff --git a/prestartup_script.py b/prestartup_script.py index b3fba3f..0134aec 100644 --- a/prestartup_script.py +++ b/prestartup_script.py @@ -9,16 +9,11 @@ import locale import platform -try: - from distutils.version import StrictVersion -except: - print(f"[ComfyUI-Manager] Missing `distutils`. Try install...") - subprocess.check_output([sys.executable, '-m', 'pip', 'install', 'distutils']) - from distutils.version import StrictVersion - glob_path = os.path.join(os.path.dirname(__file__), "glob") sys.path.append(glob_path) +from manager_util import * + import cm_global