Fix auto-linking in download command

This commit is contained in:
Matthew Honnibal 2017-03-17 21:35:51 +01:00
parent 9925334fa0
commit ac4b88cce9
2 changed files with 11 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import pip
import plac
import requests
from os import path
from .link import link
from .link import link, link_package
from . import about
from . import util
@ -26,7 +26,7 @@ def download(model=None, direct=False):
compatibility = get_compatibility()
version = get_version(model_name, compatibility)
download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name, v=version))
link(model_name, model, force=True)
link_package(model_name, model, force=True)
def get_compatibility():

View File

@ -18,15 +18,18 @@ def link(origin, link_name, force=False):
"""Create a symlink for models within the spacy/data directory. Accepts
either the name of a pip package, or the local path to the model data
directory. Linking models allows loading them via spacy.load(link_name)."""
if is_package(origin):
link_package(origin, link_name)
else:
symlink(origin, link_name, force)
def link_package(origin, link_name, force=False):
package_path = site.getsitepackages()[0]
meta = get_meta(package_path, origin)
data_dir = origin + '-' + meta['version']
model_path = os.path.join(package_path, origin, data_dir)
symlink(model_path, link_name, force)
else:
symlink(origin, link_name, force)
def symlink(model_path, link_name, force):