Use package.version for model version comparison

Change `--install-models` to `--force-update-models`
This commit is contained in:
Robert George 2023-09-29 15:31:33 -07:00
parent 78713d8017
commit 94f63cedda
No known key found for this signature in database
GPG key ID: 9B0D835A293663C4
5 changed files with 6 additions and 4 deletions

View file

@ -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

View file

@ -172,7 +172,7 @@ _default_options_objects = [
'value_type': 'bool'
},
{
'name': 'INSTALL_MODELS',
'name': 'FORCE_UPDATE_MODELS',
'default_value': False,
'value_type': 'bool'
},

View file

@ -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}) ..."
)

View file

@ -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",

View file

@ -54,6 +54,7 @@ dependencies = [
"redis ==4.3.4",
"prometheus-client ==0.15.0",
"polib ==1.1.1",
"packaging ==23.1"
]
[project.scripts]