From d95b974941f6e2d7a7fca7df58cfbb7332816a62 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Wed, 14 Aug 2024 01:53:28 +0900 Subject: [PATCH] fix: invalid version handling https://github.com/ltdrdata/ComfyUI-Manager/issues/953 --- glob/manager_core.py | 4 +- glob/manager_util.py | 125 ++++++++++++++++++++++--------------------- prestartup_script.py | 2 +- pyproject.toml | 2 +- 4 files changed, 67 insertions(+), 66 deletions(-) diff --git a/glob/manager_core.py b/glob/manager_core.py index 41b6bfe4..7a4416bb 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -23,7 +23,7 @@ import cm_global from manager_util import * -version = [2, 48, 6] +version = [2, 48, 7] version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '') @@ -123,7 +123,7 @@ def is_installed(name): if name.startswith('#'): return True - pattern = r'([^<>!=]+)([<>!=]=?)([^ ]*)' + pattern = r'([^<>!=]+)([<>!=]=?)([0-9.a-zA-Z]*)' match = re.search(pattern, name) if match: diff --git a/glob/manager_util.py b/glob/manager_util.py index 5dc66b53..5740a204 100644 --- a/glob/manager_util.py +++ b/glob/manager_util.py @@ -1,63 +1,64 @@ -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 +# DON'T USE StrictVersion - cannot handle pre_release version +# 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 3445a318..884a0891 100644 --- a/prestartup_script.py +++ b/prestartup_script.py @@ -448,7 +448,7 @@ def is_installed(name): if name.startswith('#'): return True - pattern = r'([^<>!=]+)([<>!=]=?)([^ ]*)' + pattern = r'([^<>!=]+)([<>!=]=?)([0-9.a-zA-Z]*)' match = re.search(pattern, name) if match: diff --git a/pyproject.toml b/pyproject.toml index 46bbfed8..3a804ef4 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 = "2.48.6" +version = "2.48.7" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]