mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-14 03:26:24 +03:00
f37863093a
Remove hacks and wrappers, keep code in sync across our libraries and move spaCy a few steps closer to only depending on packages with binary wheels 🎉 See here: https://github.com/explosion/srsly Serialization is hard, especially across Python versions and multiple platforms. After dealing with many subtle bugs over the years (encodings, locales, large files) our libraries like spaCy and Prodigy have steadily grown a number of utility functions to wrap the multiple serialization formats we need to support (especially json, msgpack and pickle). These wrapping functions ended up duplicated across our codebases, so we wanted to put them in one place. At the same time, we noticed that having a lot of small dependencies was making maintainence harder, and making installation slower. To solve this, we've made srsly standalone, by including the component packages directly within it. This way we can provide all the serialization utilities we need in a single binary wheel. srsly currently includes forks of the following packages: ujson msgpack msgpack-numpy cloudpickle * WIP: replace json/ujson with srsly * Replace ujson in examples Use regular json instead of srsly to make code easier to read and follow * Update requirements * Fix imports * Fix typos * Replace msgpack with srsly * Fix warning
85 lines
2.2 KiB
Plaintext
85 lines
2.2 KiB
Plaintext
//- 💫 DOCS > API > TOP-LEVEL > COMPATIBILITY
|
|
|
|
p
|
|
| All Python code is written in an
|
|
| #[strong intersection of Python 2 and Python 3]. This is easy in Cython,
|
|
| but somewhat ugly in Python. Logic that deals with Python or platform
|
|
| compatibility only lives in #[code spacy.compat]. To distinguish them from
|
|
| the builtin functions, replacement functions are suffixed with an
|
|
| underscore, e.e #[code unicode_].
|
|
|
|
+aside-code("Example").
|
|
from spacy.compat import unicode_
|
|
|
|
compatible_unicode = unicode_('hello world')
|
|
|
|
+table(["Name", "Python 2", "Python 3"])
|
|
+row
|
|
+cell #[code compat.bytes_]
|
|
+cell #[code str]
|
|
+cell #[code bytes]
|
|
|
|
+row
|
|
+cell #[code compat.unicode_]
|
|
+cell #[code unicode]
|
|
+cell #[code str]
|
|
|
|
+row
|
|
+cell #[code compat.basestring_]
|
|
+cell #[code basestring]
|
|
+cell #[code str]
|
|
|
|
+row
|
|
+cell #[code compat.input_]
|
|
+cell #[code raw_input]
|
|
+cell #[code input]
|
|
|
|
+row
|
|
+cell #[code compat.path2str]
|
|
+cell #[code str(path)] with #[code .decode('utf8')]
|
|
+cell #[code str(path)]
|
|
|
|
+h(3, "is_config") compat.is_config
|
|
+tag function
|
|
|
|
p
|
|
| Check if a specific configuration of Python version and operating system
|
|
| matches the user's setup. Mostly used to display targeted error messages.
|
|
|
|
+aside-code("Example").
|
|
from spacy.compat import is_config
|
|
|
|
if is_config(python2=True, windows=True):
|
|
print("You are using Python 2 on Windows.")
|
|
|
|
+table(["Name", "Type", "Description"])
|
|
+row
|
|
+cell #[code python2]
|
|
+cell bool
|
|
+cell spaCy is executed with Python 2.x.
|
|
|
|
+row
|
|
+cell #[code python3]
|
|
+cell bool
|
|
+cell spaCy is executed with Python 3.x.
|
|
|
|
+row
|
|
+cell #[code windows]
|
|
+cell bool
|
|
+cell spaCy is executed on Windows.
|
|
|
|
+row
|
|
+cell #[code linux]
|
|
+cell bool
|
|
+cell spaCy is executed on Linux.
|
|
|
|
+row
|
|
+cell #[code osx]
|
|
+cell bool
|
|
+cell spaCy is executed on OS X or macOS.
|
|
|
|
+row("foot")
|
|
+cell returns
|
|
+cell bool
|
|
+cell Whether the specified configuration matches the user's platform.
|