2020-07-25 16:01:15 +03:00
|
|
|
"""Helpers for Python and platform compatibility."""
|
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-09-23 17:00:03 +03:00
|
|
|
try: # Python 3.8+
|
|
|
|
from typing import Literal
|
|
|
|
except ImportError:
|
|
|
|
from typing_extensions import Literal # noqa: F401
|
|
|
|
|
2021-08-17 15:05:13 +03: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 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"
|