From 56cec5b2958edf3b1807b7e7b2b1b5186dbd2f81 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 26 Jul 2024 05:52:52 +0900 Subject: [PATCH] fix version parsing (#3016) --- install.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/install.py b/install.py index a02ae032c..4a7fec204 100644 --- a/install.py +++ b/install.py @@ -5,17 +5,14 @@ import shutil import platform from pathlib import Path -from typing import Tuple, Optional +from typing import Optional +from packaging.version import parse repo_root = Path(__file__).parent main_req_file = repo_root / "requirements.txt" -def comparable_version(version: str) -> Tuple: - return tuple(version.split(".")) - - def get_installed_version(package: str) -> Optional[str]: try: return metadata.version(package) @@ -44,9 +41,9 @@ def install_requirements(req_file): elif ">=" in package: package_name, package_version = package.split(">=") installed_version = get_installed_version(package_name) - if not installed_version or comparable_version( + if not installed_version or parse( installed_version - ) < comparable_version(package_version): + ) < parse(package_version): launch.run_pip( f'install -U "{package}"', f"sd-webui-controlnet requirement: changing {package_name} version from {installed_version} to {package_version}", @@ -54,9 +51,9 @@ def install_requirements(req_file): elif "<=" in package: package_name, package_version = package.split("<=") installed_version = get_installed_version(package_name) - if not installed_version or comparable_version( + if not installed_version or parse( installed_version - ) > comparable_version(package_version): + ) > parse(package_version): launch.run_pip( f'install "{package_name}=={package_version}"', f"sd-webui-controlnet requirement: changing {package_name} version from {installed_version} to {package_version}", @@ -94,7 +91,7 @@ def try_install_from_wheel(pkg_name: str, wheel_url: str, version: Optional[str] if version is None: return # Version requirement already satisfied. - if comparable_version(current_version) >= comparable_version(version): + if parse(current_version) >= parse(version): return try: