mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 18:26:30 +03:00
Make python 3.4 compat module loading (fix #1733)
This commit is contained in:
parent
ab33e274f5
commit
6ee5dff51c
|
@ -43,15 +43,15 @@ fix_text = ftfy.fix_text
|
||||||
copy_array = copy_array
|
copy_array = copy_array
|
||||||
izip = getattr(itertools, 'izip', zip)
|
izip = getattr(itertools, 'izip', zip)
|
||||||
|
|
||||||
is_python2 = six.PY2
|
|
||||||
is_python3 = six.PY3
|
|
||||||
is_windows = sys.platform.startswith('win')
|
is_windows = sys.platform.startswith('win')
|
||||||
is_linux = sys.platform.startswith('linux')
|
is_linux = sys.platform.startswith('linux')
|
||||||
is_osx = sys.platform == 'darwin'
|
is_osx = sys.platform == 'darwin'
|
||||||
|
|
||||||
|
is_python2 = six.PY2
|
||||||
|
is_python3 = six.PY3
|
||||||
|
is_python_pre_3_5 = is_python2 or (is_python3 and sys.version_info[1]<5)
|
||||||
|
|
||||||
if is_python2:
|
if is_python2:
|
||||||
import imp
|
|
||||||
bytes_ = str
|
bytes_ = str
|
||||||
unicode_ = unicode # noqa: F821
|
unicode_ = unicode # noqa: F821
|
||||||
basestring_ = basestring # noqa: F821
|
basestring_ = basestring # noqa: F821
|
||||||
|
@ -60,7 +60,6 @@ if is_python2:
|
||||||
path2str = lambda path: str(path).decode('utf8')
|
path2str = lambda path: str(path).decode('utf8')
|
||||||
|
|
||||||
elif is_python3:
|
elif is_python3:
|
||||||
import importlib.util
|
|
||||||
bytes_ = bytes
|
bytes_ = bytes
|
||||||
unicode_ = str
|
unicode_ = str
|
||||||
basestring_ = str
|
basestring_ = str
|
||||||
|
@ -111,9 +110,11 @@ def normalize_string_keys(old):
|
||||||
|
|
||||||
def import_file(name, loc):
|
def import_file(name, loc):
|
||||||
loc = str(loc)
|
loc = str(loc)
|
||||||
if is_python2:
|
if is_python_pre_3_5:
|
||||||
|
import imp
|
||||||
return imp.load_source(name, loc)
|
return imp.load_source(name, loc)
|
||||||
else:
|
else:
|
||||||
|
import importlib.util
|
||||||
spec = importlib.util.spec_from_file_location(name, str(loc))
|
spec = importlib.util.spec_from_file_location(name, str(loc))
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user