From dacfaa2ca4e48be00fac0e099029aa7db2b6b4ae Mon Sep 17 00:00:00 2001 From: ines Date: Wed, 3 Jan 2018 21:03:36 +0100 Subject: [PATCH] Ensure that download command exits properly (resolves #1714) --- spacy/cli/download.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 07dea3858..991fefd2c 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -31,25 +31,28 @@ def download(cmd, model, direct=False): version = get_version(model_name, compatibility) dl = download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name, v=version)) - if dl == 0: - try: - # Get package path here because link uses - # pip.get_installed_distributions() to check if model is a - # package, which fails if model was just installed via - # subprocess - package_path = get_package_path(model_name) - link(None, model_name, model, force=True, - model_path=package_path) - except: - # Dirty, but since spacy.download and the auto-linking is - # mostly a convenience wrapper, it's best to show a success - # message and loading instructions, even if linking fails. - prints( - "Creating a shortcut link for 'en' didn't work (maybe " - "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") + if dl != 0: + # if download subprocess doesn't return 0, exit with the respective + # exit code before doing anything else + sys.exit(dl) + try: + # Get package path here because link uses + # pip.get_installed_distributions() to check if model is a + # package, which fails if model was just installed via + # subprocess + package_path = get_package_path(model_name) + link(None, model_name, model, force=True, + model_path=package_path) + except: + # Dirty, but since spacy.download and the auto-linking is + # mostly a convenience wrapper, it's best to show a success + # message and loading instructions, even if linking fails. + prints( + "Creating a shortcut link for 'en' didn't work (maybe " + "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):