From 94f63cedda50521620ba56d19f22fde66cd590c6 Mon Sep 17 00:00:00 2001 From: Robert George Date: Fri, 29 Sep 2023 15:31:33 -0700 Subject: [PATCH] Use package.version for model version comparison Change `--install-models` to `--force-update-models` --- libretranslate/app.py | 2 +- libretranslate/default_values.py | 2 +- libretranslate/init.py | 3 ++- libretranslate/main.py | 2 +- pyproject.toml | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libretranslate/app.py b/libretranslate/app.py index 3af558d..0a849c6 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -125,7 +125,7 @@ def get_routes_limits(default_req_limit, daily_req_limit, api_keys_db): def create_app(args): from libretranslate.init import boot - boot(args.load_only, args.update_models, args.install_models) + boot(args.load_only, args.update_models, args.force_update_models) from libretranslate.language import load_languages diff --git a/libretranslate/default_values.py b/libretranslate/default_values.py index 5b526fb..df058a3 100644 --- a/libretranslate/default_values.py +++ b/libretranslate/default_values.py @@ -172,7 +172,7 @@ _default_options_objects = [ 'value_type': 'bool' }, { - 'name': 'INSTALL_MODELS', + 'name': 'FORCE_UPDATE_MODELS', 'default_value': False, 'value_type': 'bool' }, diff --git a/libretranslate/init.py b/libretranslate/init.py index 46a8b74..098cb20 100644 --- a/libretranslate/init.py +++ b/libretranslate/init.py @@ -1,5 +1,6 @@ from argostranslate import package, translate +from packaging import version import libretranslate.language @@ -55,7 +56,7 @@ def check_and_install_models(force=False, load_only_lang_codes=None,update=False and pack.to_code == available_package.to_code ): update = True - if pack.package_version < available_package.package_version: + if version.parse(pack.package_version) < version.parse(available_package.package_version): print( f"Updating {available_package} ({pack.package_version}->{available_package.package_version}) ..." ) diff --git a/libretranslate/main.py b/libretranslate/main.py index 41035fc..84589d3 100644 --- a/libretranslate/main.py +++ b/libretranslate/main.py @@ -161,7 +161,7 @@ def get_args(): "--update-models", default=DEFARGS['UPDATE_MODELS'], action="store_true", help="Update language models at startup" ) parser.add_argument( - "--install-models", default=DEFARGS['INSTALL_MODELS'], action="store_true", help="Install language models at startup" + "--force-update-models", default=DEFARGS['FORCE_UPDATE_MODELS'], action="store_true", help="Install/Reinstall language models at startup" ) parser.add_argument( "--metrics", diff --git a/pyproject.toml b/pyproject.toml index a766252..445091b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ dependencies = [ "redis ==4.3.4", "prometheus-client ==0.15.0", "polib ==1.1.1", + "packaging ==23.1" ] [project.scripts]