Packaging: Add agnostic method to check version of packages
Some packages such as ExllamaV2 and V3 require specific versions for the latest features. Rather than creating repetitive functions, create an agnostic function to check the installed package and then report to the user to upgrade. This is also sent to requests for loading and unloading, so keep the error short. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
parent
084916c04f
commit
17f3dca6fc
3 changed files with 33 additions and 0 deletions
|
|
@ -1,6 +1,9 @@
|
|||
"""Construct a model of all optional dependencies"""
|
||||
|
||||
import importlib.util
|
||||
from importlib.metadata import version as package_version
|
||||
from loguru import logger
|
||||
from packaging import version
|
||||
from pydantic import BaseModel, computed_field
|
||||
|
||||
|
||||
|
|
@ -49,4 +52,26 @@ def get_installed_deps() -> DependenciesModel:
|
|||
return DependenciesModel(**installed_deps)
|
||||
|
||||
|
||||
def check_package_version(package_name: str, required_version_str: str):
|
||||
"""
|
||||
Fetches and verifies a given package version.
|
||||
|
||||
This assumes that the required package is installed.
|
||||
"""
|
||||
|
||||
required_version = version.parse(required_version_str)
|
||||
current_version = version.parse(package_version(package_name).split("+")[0])
|
||||
|
||||
unsupported_message = (
|
||||
f"ERROR: TabbyAPI requires ExLlamaV2 {required_version} "
|
||||
f"or greater. Your current version is {current_version}. "
|
||||
"Please update your dependencies."
|
||||
)
|
||||
|
||||
if current_version < required_version:
|
||||
raise RuntimeError(unsupported_message)
|
||||
else:
|
||||
logger.info(f"{package_name} version: {current_version}")
|
||||
|
||||
|
||||
dependencies = get_installed_deps()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue