From baf36d0588b6069b1bc04cf9ce86a6ab84487cf9 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 18 Aug 2017 21:56:47 +0200 Subject: [PATCH] Add compat function for importlib.util --- spacy/compat.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spacy/compat.py b/spacy/compat.py index 4ef24cd8b..7e69f3a61 100644 --- a/spacy/compat.py +++ b/spacy/compat.py @@ -46,6 +46,7 @@ is_osx = sys.platform == 'darwin' if is_python2: + import imp bytes_ = str unicode_ = unicode basestring_ = basestring @@ -54,6 +55,7 @@ if is_python2: path2str = lambda path: str(path).decode('utf8') elif is_python3: + import importlib.util bytes_ = bytes unicode_ = str basestring_ = str @@ -102,3 +104,12 @@ def normalize_string_keys(old): return new +def import_file(name, loc): + loc = str(loc) + if is_python2: + return imp.load_source(name, loc) + else: + spec = importlib.util.spec_from_file_location(name, str(init_file)) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module