2020-07-25 13:01:15 +00:00
|
|
|
"""Helpers for Python and platform compatibility."""
|
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-09-23 14:00:03 +00:00
|
|
|
try: # Python 3.8+
|
|
|
|
from typing import Literal
|
|
|
|
except ImportError:
|
|
|
|
from typing_extensions import Literal # noqa: F401
|
|
|
|
|
2021-08-17 12:05:13 +00:00
|
|
|
# Important note: The importlib_metadata "backport" includes functionality
|
|
|
|
# that's not part of the built-in importlib.metadata. We should treat this
|
|
|
|
# import like the built-in and only use what's available there.
|
|
|
|
try: # Python 3.8+
|
|
|
|
import importlib.metadata as importlib_metadata
|
|
|
|
except ImportError:
|
|
|
|
from catalogue import _importlib_metadata as importlib_metadata # noqa: F401
|
|
|
|
|
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"
|