Ensure that download command exits properly (resolves #1714)

This commit is contained in:
ines 2018-01-03 21:03:36 +01:00
parent 1081e08efb
commit dacfaa2ca4
1 changed files with 22 additions and 19 deletions

View File

@ -31,25 +31,28 @@ def download(cmd, model, direct=False):
version = get_version(model_name, compatibility) version = get_version(model_name, compatibility)
dl = download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name, dl = download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name,
v=version)) v=version))
if dl == 0: if dl != 0:
try: # if download subprocess doesn't return 0, exit with the respective
# Get package path here because link uses # exit code before doing anything else
# pip.get_installed_distributions() to check if model is a sys.exit(dl)
# package, which fails if model was just installed via try:
# subprocess # Get package path here because link uses
package_path = get_package_path(model_name) # pip.get_installed_distributions() to check if model is a
link(None, model_name, model, force=True, # package, which fails if model was just installed via
model_path=package_path) # subprocess
except: package_path = get_package_path(model_name)
# Dirty, but since spacy.download and the auto-linking is link(None, model_name, model, force=True,
# mostly a convenience wrapper, it's best to show a success model_path=package_path)
# message and loading instructions, even if linking fails. except:
prints( # Dirty, but since spacy.download and the auto-linking is
"Creating a shortcut link for 'en' didn't work (maybe " # mostly a convenience wrapper, it's best to show a success
"you don't have admin permissions?), but you can still " # message and loading instructions, even if linking fails.
"load the model via its full package name:", prints(
"nlp = spacy.load('%s')" % model_name, "Creating a shortcut link for 'en' didn't work (maybe "
title="Download successful but linking failed") "you don't have admin permissions?), but you can still "
"load the model via its full package name:",
"nlp = spacy.load('%s')" % model_name,
title="Download successful but linking failed")
def get_json(url, desc): def get_json(url, desc):