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 plac
import requests import requests
from os import path from os import path
from .link import link from .link import link, link_package
from . import about from . import about
from . import util from . import util
@ -26,7 +26,7 @@ def download(model=None, direct=False):
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)) 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(): def get_compatibility():

View File

@ -18,17 +18,20 @@ def link(origin, link_name, force=False):
"""Create a symlink for models within the spacy/data directory. Accepts """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 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).""" directory. Linking models allows loading them via spacy.load(link_name)."""
if is_package(origin): if is_package(origin):
package_path = site.getsitepackages()[0] link_package(origin, link_name)
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: else:
symlink(origin, link_name, force) 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)
def symlink(model_path, link_name, force): def symlink(model_path, link_name, force):
if not os.path.isdir(model_path): if not os.path.isdir(model_path):
util.sys_exit( util.sys_exit(