Fix link module

This commit is contained in:
Matthew Honnibal 2017-03-18 18:57:31 +01:00
parent f6c6c89546
commit 703eb7bdbd

View File

@ -1,8 +1,6 @@
# coding: utf8 # coding: utf8
from __future__ import unicode_literals from __future__ import unicode_literals
import io
import os
import pip import pip
from pathlib import Path from pathlib import Path
from distutils.sysconfig import get_python_lib from distutils.sysconfig import get_python_lib
@ -10,6 +8,7 @@ from .. import util
def link(origin, link_name, force=False): def link(origin, link_name, force=False):
print("Linking", origin, link_name)
if is_package(origin): if is_package(origin):
link_package(origin, link_name, force) link_package(origin, link_name, force)
else: else:
@ -30,20 +29,18 @@ def symlink(model_path, link_name, force):
"The data should be located in {p}".format(p=model_path), "The data should be located in {p}".format(p=model_path),
title="Can't locate model data") title="Can't locate model data")
data_path = str(util.get_data_path()) link_path = util.get_data_path() / link_name
link_path = Path(__file__).parent.parent / data_path / link_name
if Path(link_path).exists(): if link_path.exists() and not force:
if force: util.sys_exit(
os.unlink(str(link_path)) "To overwrite an existing link, use the --force flag.",
else: title="Link {l} already exists".format(l=link_name))
util.sys_exit( elif link_path.exists():
"To overwrite an existing link, use the --force flag.", link_path.unlink()
title="Link {l} already exists".format(l=link_name))
os.symlink(str(model_path), str(link_path)) link_path.symlink_to(model_path)
util.print_msg( util.print_msg(
"{a} --> {b}".format(a=str(model_path), b=str(link_path)), "{a} --> {b}".format(a=model_path.as_posix(), b=link_path.as_posix()),
"You can now load the model via spacy.load('{l}').".format(l=link_name), "You can now load the model via spacy.load('{l}').".format(l=link_name),
title="Linking successful") title="Linking successful")