Fix data loading on Python 2

This commit is contained in:
Matthew Honnibal 2017-08-18 21:57:06 +02:00
parent baf36d0588
commit ed95009b5c
1 changed files with 3 additions and 5 deletions

View File

@ -22,7 +22,7 @@ import ujson
from .symbols import ORTH from .symbols import ORTH
from .compat import cupy, CudaStream, path2str, basestring_, input_, unicode_ from .compat import cupy, CudaStream, path2str, basestring_, input_, unicode_
from .compat import copy_array, normalize_string_keys, getattr_ from .compat import copy_array, normalize_string_keys, getattr_, import_file
LANGUAGES = {} LANGUAGES = {}
@ -112,15 +112,13 @@ def load_model(name, **overrides):
def load_model_from_link(name, **overrides): def load_model_from_link(name, **overrides):
"""Load a model from a shortcut link, or directory in spaCy data path.""" """Load a model from a shortcut link, or directory in spaCy data path."""
init_file = get_data_path() / name / '__init__.py' path = get_data_path() / name / '__init__.py'
spec = importlib.util.spec_from_file_location(name, str(init_file))
try: try:
cls = importlib.util.module_from_spec(spec) cls = import_file(name, path)
except AttributeError: except AttributeError:
raise IOError( raise IOError(
"Cant' load '%s'. If you're using a shortcut link, make sure it " "Cant' load '%s'. If you're using a shortcut link, make sure it "
"points to a valid model package (not just a data directory)." % name) "points to a valid model package (not just a data directory)." % name)
spec.loader.exec_module(cls)
return cls.load(**overrides) return cls.load(**overrides)