Mikubill / sd-webui-controlnet

WebUI extension for ControlNet
GNU General Public License v3.0
17.11k stars 1.97k forks source link

fix version parsing #3016

Closed w-e-w closed 4 months ago

w-e-w commented 4 months ago

recently on every launch install.py the message keep poping up on launch

Installing sd-webui-controlnet requirement: changing opencv-python version from 4.10.0.84 to 4.8.0

this is due to improper version comparison in install.py

comparable_version() in install.py retruns Tuple of strings https://github.com/Mikubill/sd-webui-controlnet/blob/b63899a654ee2f70d475c259691f35ac67c320d4/install.py#L15-L16

until recently directly comparing Tuple of strings work good enough but opencv-python updated to vesrion 4.10.x.x

when checking for opencv-python>=4.8.0 the Tuple of strings ('4', '10', '0', '84') >= ('4', '8', '0') this retruns False due to the string '10' is < string '8'


solution

as far as I'm aware the best way of passing version number is to use from packaging.version import parse as this also handles more exotic version numbers such as the ones with suffixes

suffix like pytorch '2.1.2+cu121'

alternatively if you wish to not packaging then one could either write complex regex to handle special cases or just assume that there's no special version numbers and simply convert str to int which can be done by modifying comparable_version

def comparable_version(version: str) -> Tuple:
    return tuple(int(v) for v in version.split("."))