mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-12 23:35:47 +03:00
Update cythonize
This commit is contained in:
parent
dca663a2ef
commit
2e91e07388
|
@ -1,7 +1,7 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = [
|
requires = [
|
||||||
"setuptools",
|
"setuptools",
|
||||||
"cython>=0.25",
|
"cython>=0.25,<3.0",
|
||||||
"cymem>=2.0.2,<2.1.0",
|
"cymem>=2.0.2,<2.1.0",
|
||||||
"preshed>=3.0.2,<3.1.0",
|
"preshed>=3.0.2,<3.1.0",
|
||||||
"murmurhash>=0.28.0,<1.1.0",
|
"murmurhash>=0.28.0,<1.1.0",
|
||||||
|
|
97
setup.py
97
setup.py
|
@ -1,16 +1,17 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import contextlib
|
|
||||||
import numpy
|
import numpy
|
||||||
|
from pathlib import Path
|
||||||
from distutils.command.build_ext import build_ext
|
from distutils.command.build_ext import build_ext
|
||||||
from distutils.sysconfig import get_python_inc
|
from distutils.sysconfig import get_python_inc
|
||||||
import distutils.util
|
import distutils.util
|
||||||
from distutils import ccompiler, msvccompiler
|
from distutils import ccompiler, msvccompiler
|
||||||
from setuptools import Extension, setup, find_packages
|
from setuptools import Extension, setup, find_packages
|
||||||
|
from Cython.Build import cythonize
|
||||||
|
from Cython.Compiler import Options
|
||||||
|
|
||||||
|
|
||||||
def is_new_osx():
|
def is_new_osx():
|
||||||
|
@ -28,6 +29,10 @@ def is_new_osx():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# Preserve `__doc__` on functions and classes
|
||||||
|
# http://docs.cython.org/en/latest/src/userguide/source_files_and_compilation.html#compiler-options
|
||||||
|
Options.docstrings = True
|
||||||
|
|
||||||
PACKAGES = find_packages()
|
PACKAGES = find_packages()
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,6 +79,12 @@ COMPILE_OPTIONS = {
|
||||||
|
|
||||||
LINK_OPTIONS = {"msvc": [], "mingw32": [], "other": []}
|
LINK_OPTIONS = {"msvc": [], "mingw32": [], "other": []}
|
||||||
|
|
||||||
|
COMPILER_DIRECTIVES = {
|
||||||
|
"language_level": -3,
|
||||||
|
"embedsignature": True,
|
||||||
|
"annotation_typing": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if is_new_osx():
|
if is_new_osx():
|
||||||
# On Mac, use libc++ because Apple deprecated use of
|
# On Mac, use libc++ because Apple deprecated use of
|
||||||
|
@ -105,20 +116,6 @@ class build_ext_subclass(build_ext, build_ext_options):
|
||||||
build_ext.build_extensions(self)
|
build_ext.build_extensions(self)
|
||||||
|
|
||||||
|
|
||||||
def generate_cython(root, source):
|
|
||||||
print("Cythonizing sources")
|
|
||||||
p = subprocess.call(
|
|
||||||
[sys.executable, os.path.join(root, "bin", "cythonize.py"), source],
|
|
||||||
env=os.environ,
|
|
||||||
)
|
|
||||||
if p != 0:
|
|
||||||
raise RuntimeError("Running cythonize failed")
|
|
||||||
|
|
||||||
|
|
||||||
def is_source_release(path):
|
|
||||||
return os.path.exists(os.path.join(path, "PKG-INFO"))
|
|
||||||
|
|
||||||
|
|
||||||
# Include the git version in the build (adapted from NumPy)
|
# Include the git version in the build (adapted from NumPy)
|
||||||
# Copyright (c) 2005-2020, NumPy Developers.
|
# Copyright (c) 2005-2020, NumPy Developers.
|
||||||
# BSD 3-Clause license, see licenses/3rd_party_licenses.txt
|
# BSD 3-Clause license, see licenses/3rd_party_licenses.txt
|
||||||
|
@ -169,75 +166,41 @@ GIT_VERSION = "%(git_version)s"
|
||||||
|
|
||||||
|
|
||||||
def clean(path):
|
def clean(path):
|
||||||
for name in MOD_NAMES:
|
for path in path.glob("**/*"):
|
||||||
name = name.replace(".", "/")
|
if path.is_file() and path.suffix in (".so", ".cpp"):
|
||||||
for ext in [".so", ".html", ".cpp", ".c"]:
|
print(f"Deleting {path.name}")
|
||||||
file_path = os.path.join(path, name + ext)
|
path.unlink()
|
||||||
if os.path.exists(file_path):
|
|
||||||
os.unlink(file_path)
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def chdir(new_dir):
|
|
||||||
old_dir = os.getcwd()
|
|
||||||
try:
|
|
||||||
os.chdir(new_dir)
|
|
||||||
sys.path.insert(0, new_dir)
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
del sys.path[0]
|
|
||||||
os.chdir(old_dir)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_package():
|
def setup_package():
|
||||||
write_git_info_py()
|
write_git_info_py()
|
||||||
|
|
||||||
root = os.path.abspath(os.path.dirname(__file__))
|
root = Path(__file__).parent
|
||||||
|
|
||||||
if hasattr(sys, "argv") and len(sys.argv) > 1 and sys.argv[1] == "clean":
|
if hasattr(sys, "argv") and len(sys.argv) > 1 and sys.argv[1] == "clean":
|
||||||
return clean(root)
|
return clean(root / "spacy")
|
||||||
|
|
||||||
with chdir(root):
|
with (root / "spacy" / "about.py").open("r") as f:
|
||||||
with io.open(os.path.join(root, "spacy", "about.py"), encoding="utf8") as f:
|
|
||||||
about = {}
|
about = {}
|
||||||
exec(f.read(), about)
|
exec(f.read(), about)
|
||||||
|
|
||||||
include_dirs = [
|
include_dirs = [
|
||||||
numpy.get_include(),
|
|
||||||
get_python_inc(plat_specific=True),
|
get_python_inc(plat_specific=True),
|
||||||
os.path.join(root, "include"),
|
numpy.get_include(),
|
||||||
|
str(root / "include"),
|
||||||
]
|
]
|
||||||
|
|
||||||
if (
|
if (
|
||||||
ccompiler.new_compiler().compiler_type == "msvc"
|
ccompiler.new_compiler().compiler_type == "msvc"
|
||||||
and msvccompiler.get_build_version() == 9
|
and msvccompiler.get_build_version() == 9
|
||||||
):
|
):
|
||||||
include_dirs.append(os.path.join(root, "include", "msvc9"))
|
include_dirs.append(str(root / "include" / "msvc9"))
|
||||||
|
|
||||||
ext_modules = []
|
ext_modules = []
|
||||||
for mod_name in MOD_NAMES:
|
for name in MOD_NAMES:
|
||||||
mod_path = mod_name.replace(".", "/") + ".cpp"
|
mod_path = name.replace(".", "/") + ".pyx"
|
||||||
extra_link_args = []
|
ext = Extension(name, [mod_path], language="c++")
|
||||||
# ???
|
ext_modules.append(ext)
|
||||||
# Imported from patch from @mikepb
|
print("Cythonizing sources")
|
||||||
# See Issue #267. Running blind here...
|
ext_modules = cythonize(ext_modules, compiler_directives=COMPILER_DIRECTIVES)
|
||||||
if sys.platform == "darwin":
|
|
||||||
dylib_path = [".." for _ in range(mod_name.count("."))]
|
|
||||||
dylib_path = "/".join(dylib_path)
|
|
||||||
dylib_path = "@loader_path/%s/spacy/platform/darwin/lib" % dylib_path
|
|
||||||
extra_link_args.append("-Wl,-rpath,%s" % dylib_path)
|
|
||||||
ext_modules.append(
|
|
||||||
Extension(
|
|
||||||
mod_name,
|
|
||||||
[mod_path],
|
|
||||||
language="c++",
|
|
||||||
include_dirs=include_dirs,
|
|
||||||
extra_link_args=extra_link_args,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not is_source_release(root):
|
|
||||||
generate_cython(root, "spacy")
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="spacy",
|
name="spacy",
|
||||||
|
@ -245,6 +208,8 @@ def setup_package():
|
||||||
version=about["__version__"],
|
version=about["__version__"],
|
||||||
ext_modules=ext_modules,
|
ext_modules=ext_modules,
|
||||||
cmdclass={"build_ext": build_ext_subclass},
|
cmdclass={"build_ext": build_ext_subclass},
|
||||||
|
include_dirs=include_dirs,
|
||||||
|
package_data={"": ["*.pyx", "*.pxd", "*.pxi", "*.cpp"]},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user