2019-03-08 13:42:26 +03: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 13:07:02 +03:00
|
|
|
import sys
|
|
|
|
|
2020-01-29 19:06:46 +03:00
|
|
|
from thinc.util import copy_array
|
2017-05-31 15:14:29 +03:00
|
|
|
|
2017-04-15 13:07:02 +03:00
|
|
|
try:
|
|
|
|
import cPickle as pickle
|
|
|
|
except ImportError:
|
|
|
|
import pickle
|
|
|
|
|
|
|
|
try:
|
|
|
|
import copy_reg
|
|
|
|
except ImportError:
|
|
|
|
import copyreg as copy_reg
|
|
|
|
|
2017-05-18 15:12:45 +03:00
|
|
|
try:
|
|
|
|
from cupy.cuda.stream import Stream as CudaStream
|
|
|
|
except ImportError:
|
|
|
|
CudaStream = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
import cupy
|
|
|
|
except ImportError:
|
|
|
|
cupy = None
|
|
|
|
|
2020-02-18 17:38:18 +03:00
|
|
|
from thinc.api import Optimizer # noqa: F401
|
2017-05-18 15:12:45 +03:00
|
|
|
|
2017-05-18 15:12:31 +03:00
|
|
|
pickle = pickle
|
|
|
|
copy_reg = copy_reg
|
|
|
|
CudaStream = CudaStream
|
|
|
|
cupy = cupy
|
2017-05-31 16:25:21 +03:00
|
|
|
copy_array = copy_array
|
2017-04-15 13:07:02 +03:00
|
|
|
|
2018-11-26 20:54:20 +03:00
|
|
|
is_windows = sys.platform.startswith("win")
|
|
|
|
is_linux = sys.platform.startswith("linux")
|
|
|
|
is_osx = sys.platform == "darwin"
|
2017-04-15 13:07:02 +03:00
|
|
|
|
2017-08-01 02:11:35 +03:00
|
|
|
|
2019-12-22 03:53:56 +03:00
|
|
|
def is_config(windows=None, linux=None, osx=None, **kwargs):
|
2019-03-08 13:42:26 +03: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 20:54:20 +03:00
|
|
|
return (
|
2019-12-22 03:53:56 +03:00
|
|
|
windows in (None, is_windows)
|
2018-11-26 20:54:20 +03:00
|
|
|
and linux in (None, is_linux)
|
|
|
|
and osx in (None, is_osx)
|
|
|
|
)
|