Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix version parsing #3016

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading