Merge branch 'develop' of https://github.com/explosion/spaCy into develop

This commit is contained in:
Matthew Honnibal 2017-08-23 13:02:16 +02:00
commit 44a1fa80d3

View File

@ -24,28 +24,29 @@ def download(cmd, model, direct=False):
with version. with version.
""" """
if direct: if direct:
download_model('{m}/{m}.tar.gz'.format(m=model)) dl = download_model('{m}/{m}.tar.gz'.format(m=model))
else: else:
shortcuts = get_json(about.__shortcuts__, "available shortcuts") shortcuts = get_json(about.__shortcuts__, "available shortcuts")
model_name = shortcuts.get(model, model) model_name = shortcuts.get(model, model)
compatibility = get_compatibility() compatibility = get_compatibility()
version = get_version(model_name, compatibility) version = get_version(model_name, compatibility)
download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name, v=version)) dl = download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name, v=version))
try: if dl == 0:
# Get package path here because link uses try:
# pip.get_installed_distributions() to check if model is a package, # Get package path here because link uses
# which fails if model was just installed via subprocess # pip.get_installed_distributions() to check if model is a package,
package_path = get_package_path(model_name) # which fails if model was just installed via subprocess
link(None, model_name, model, force=True, model_path=package_path) package_path = get_package_path(model_name)
except: link(None, model_name, model, force=True, model_path=package_path)
# Dirty, but since spacy.download and the auto-linking is mostly except:
# a convenience wrapper, it's best to show a success message and # Dirty, but since spacy.download and the auto-linking is mostly
# loading instructions, even if linking fails. # a convenience wrapper, it's best to show a success message and
prints("Creating a shortcut link for 'en' didn't work (maybe you " # loading instructions, even if linking fails.
"don't have admin permissions?), but you can still load " prints("Creating a shortcut link for 'en' didn't work (maybe you "
"the model via its full package name:", "don't have admin permissions?), but you can still load "
"nlp = spacy.load('%s')" % model_name, "the model via its full package name:",
title="Download successful") "nlp = spacy.load('%s')" % model_name,
title="Download successful")
def get_json(url, desc): def get_json(url, desc):
@ -77,6 +78,6 @@ def get_version(model, comp):
def download_model(filename): def download_model(filename):
download_url = about.__download_url__ + '/' + filename download_url = about.__download_url__ + '/' + filename
subprocess.call([sys.executable, '-m', return subprocess.call([sys.executable, '-m',
'pip', 'install', '--no-cache-dir', download_url], 'pip', 'install', '--no-cache-dir', download_url],
env=os.environ.copy()) env=os.environ.copy())