From 3fe5811fa7ec0039bc7898b94bf02b6bd143842e Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Sun, 10 Mar 2019 13:02:24 +0100 Subject: [PATCH] Only link model after download if shortcut link (#3378) --- spacy/cli/download.py | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/spacy/cli/download.py b/spacy/cli/download.py index a2ec15fa4..66a47823c 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -41,24 +41,32 @@ def download(model, direct=False, *pip_args): dl = download_model(dl_tpl.format(m=model_name, v=version), pip_args) if dl != 0: # if download subprocess doesn't return 0, exit 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(model_name, model, force=True, model_path=package_path) - except: # noqa: E722 - # 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. - msg.warn( - "Download successful but linking failed", - "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('{}')".format(model_name), - ) + msg.good( + "Download and installation successful", + "You can now load the model via spacy.load('{}')".format(model_name), + ) + # Only create symlink if the model is installed via a shortcut like 'en'. + # There's no real advantage over an additional symlink for en_core_web_sm + # and if anything, it's more error prone and causes more confusion. + if model in shortcuts: + 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(model_name, model, force=True, model_path=package_path) + except: # noqa: E722 + # 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. + msg.warn( + "Download successful but linking failed", + "Creating a shortcut link for '{}' 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('{}')".format(model, model_name), + ) def get_json(url, desc):