Skip to content

Commit

Permalink
fix version parsing (#3016)
Browse files Browse the repository at this point in the history
  • Loading branch information
w-e-w authored Jul 25, 2024
1 parent b63899a commit 56cec5b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -44,19 +41,19 @@ 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}",
)
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}",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 56cec5b

Please sign in to comment.