2019-03-08 10:42:26 +00:00
|
|
|
"""
|
|
|
|
Helpers for Python and platform compatibility. To distinguish them from
|
|
|
|
the builtin functions, replacement functions are suffixed with an underscore,
|
|
|
|
e.g. `unicode_`.
|
|
|
|
|
|
|
|
DOCS: https://spacy.io/api/top-level#compat
|
|
|
|
"""
|
2017-04-15 10:07:02 +00:00
|
|
|
import sys
|
|
|
|
|
2020-01-29 16:06:46 +00:00
|
|
|
from thinc.util import copy_array
|
2017-05-31 12:14:29 +00:00
|
|
|
|
2017-04-15 10:07:02 +00:00
|
|
|
try:
|
|
|
|
import cPickle as pickle
|
|
|
|
except ImportError:
|
|
|
|
import pickle
|
|
|
|
|
|
|
|
try:
|
|
|
|
import copy_reg
|
|
|
|
except ImportError:
|
|
|
|
import copyreg as copy_reg
|
|
|
|
|
2017-05-18 12:12:45 +00:00
|
|
|
try:
|
|
|
|
from cupy.cuda.stream import Stream as CudaStream
|
|
|
|
except ImportError:
|
|
|
|
CudaStream = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
import cupy
|
|
|
|
except ImportError:
|
|
|
|
cupy = None
|
|
|
|
|
2020-02-18 14:38:18 +00:00
|
|
|
from thinc.api import Optimizer # noqa: F401
|
2017-05-18 12:12:45 +00:00
|
|
|
|
2017-05-18 12:12:31 +00:00
|
|
|
pickle = pickle
|
|
|
|
copy_reg = copy_reg
|
|
|
|
CudaStream = CudaStream
|
|
|
|
cupy = cupy
|
2017-05-31 13:25:21 +00:00
|
|
|
copy_array = copy_array
|
2017-04-15 10:07:02 +00:00
|
|
|
|
2018-11-26 17:54:20 +00:00
|
|
|
is_windows = sys.platform.startswith("win")
|
|
|
|
is_linux = sys.platform.startswith("linux")
|
|
|
|
is_osx = sys.platform == "darwin"
|
2017-04-15 10:07:02 +00:00
|
|
|
|
2017-07-31 23:11:35 +00:00
|
|
|
|
2019-12-22 00:53:56 +00:00
|
|
|
def is_config(windows=None, linux=None, osx=None, **kwargs):
|
2019-03-08 10:42:26 +00:00
|
|
|
"""Check if a specific configuration of Python version and operating system
|
|
|
|
matches the user's setup. Mostly used to display targeted error messages.
|
|
|
|
|
|
|
|
windows (bool): spaCy is executed on Windows.
|
|
|
|
linux (bool): spaCy is executed on Linux.
|
|
|
|
osx (bool): spaCy is executed on OS X or macOS.
|
|
|
|
RETURNS (bool): Whether the configuration matches the user's platform.
|
|
|
|
|
|
|
|
DOCS: https://spacy.io/api/top-level#compat.is_config
|
|
|
|
"""
|
2018-11-26 17:54:20 +00:00
|
|
|
return (
|
2019-12-22 00:53:56 +00:00
|
|
|
windows in (None, is_windows)
|
2018-11-26 17:54:20 +00:00
|
|
|
and linux in (None, is_linux)
|
|
|
|
and osx in (None, is_osx)
|
|
|
|
)
|