mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-02 11:20:19 +03:00
Don't re-download installed models
When downloading a model, this checks if the same version of the same model is already installed. If it is then the download is skipped. This is necessary because pip uses the final download URL for its caching feature, but because of the way models are hosted on Github, their URLs change every few minutes.
This commit is contained in:
parent
de360bc981
commit
ed47384da1
|
@ -3,11 +3,12 @@ import requests
|
||||||
import sys
|
import sys
|
||||||
from wasabi import msg
|
from wasabi import msg
|
||||||
import typer
|
import typer
|
||||||
|
import srsly
|
||||||
|
|
||||||
from ._util import app, Arg, Opt, WHEEL_SUFFIX, SDIST_SUFFIX
|
from ._util import app, Arg, Opt, WHEEL_SUFFIX, SDIST_SUFFIX
|
||||||
from .. import about
|
from .. import about
|
||||||
from ..util import is_package, get_minor_version, run_command
|
from ..util import is_package, get_minor_version, run_command
|
||||||
from ..util import is_prerelease_version
|
from ..util import is_prerelease_version, get_installed_models, get_package_path
|
||||||
|
|
||||||
|
|
||||||
@app.command(
|
@app.command(
|
||||||
|
@ -63,6 +64,16 @@ def download(
|
||||||
compatibility = get_compatibility()
|
compatibility = get_compatibility()
|
||||||
version = get_version(model_name, compatibility)
|
version = get_version(model_name, compatibility)
|
||||||
|
|
||||||
|
# If we already have this version installed, skip downloading
|
||||||
|
installed = get_installed_models()
|
||||||
|
if model_name in installed:
|
||||||
|
model_path = get_package_path(model_name)
|
||||||
|
meta_path = model_path / "meta.json"
|
||||||
|
meta = srsly.read_json(meta_path)
|
||||||
|
if meta["version"] == version:
|
||||||
|
msg.warn(f"{model_name} v{version} already installed, skipping")
|
||||||
|
return
|
||||||
|
|
||||||
filename = get_model_filename(model_name, version, sdist)
|
filename = get_model_filename(model_name, version, sdist)
|
||||||
|
|
||||||
download_model(filename, pip_args)
|
download_model(filename, pip_args)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user