mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 18:06:29 +03:00
* Refactor setup
This commit is contained in:
parent
e0711d7024
commit
83fa1850e2
108
setup.py
108
setup.py
|
@ -1,14 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import subprocess
|
||||||
|
from setuptools import setup
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from os import path
|
from os import path
|
||||||
from glob import glob
|
from os.path import splitext
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import Extension
|
||||||
from distutils.core import Extension
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
|
|
||||||
def clean(ext):
|
def clean(ext):
|
||||||
|
@ -22,59 +23,29 @@ def clean(ext):
|
||||||
os.unlink(html)
|
os.unlink(html)
|
||||||
|
|
||||||
|
|
||||||
compile_args = []
|
def name_to_path(mod_name, ext):
|
||||||
link_args = []
|
return '%s.%s' % (mod_name.replace('.', '/'), ext)
|
||||||
libs = []
|
|
||||||
|
|
||||||
includes = ['.']
|
|
||||||
virtual_env = os.environ.get('VIRTUAL_ENV', '')
|
|
||||||
|
|
||||||
includes = ['.']
|
|
||||||
if virtual_env:
|
|
||||||
includes += glob(os.path.join(virtual_env, 'include', 'site'))
|
|
||||||
includes += glob(os.path.join(virtual_env, 'include', 'site', '*'))
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
ext_args = {'language': "c++", "include_dirs": includes}
|
def c_ext(mod_name, language, includes, compile_args):
|
||||||
|
mod_path = name_to_path(mod_name, language)
|
||||||
exts = [
|
return Extension(mod_name, [mod_path], include_dirs=includes,
|
||||||
Extension("spacy.typedefs", ["spacy/typedefs.cpp"], **ext_args),
|
extra_compile_args=compile_args, extra_link_args=compile_args)
|
||||||
Extension("spacy.strings", ["spacy/strings.cpp"], **ext_args),
|
|
||||||
Extension("spacy.lexeme", ["spacy/lexeme.cpp"], **ext_args),
|
|
||||||
Extension("spacy.vocab", ["spacy/vocab.cpp"], **ext_args),
|
|
||||||
Extension("spacy.tokens", ["spacy/tokens.cpp"], **ext_args),
|
|
||||||
Extension("spacy.morphology", ["spacy/morphology.cpp"], **ext_args),
|
|
||||||
|
|
||||||
Extension("spacy._ml", ["spacy/_ml.cpp"], **ext_args),
|
|
||||||
|
|
||||||
Extension("spacy.tokenizer", ["spacy/tokenizer.cpp"], **ext_args),
|
|
||||||
Extension("spacy.en.attrs", ["spacy/en/attrs.cpp"], **ext_args),
|
|
||||||
Extension("spacy.en.pos", ["spacy/en/pos.cpp"], **ext_args),
|
|
||||||
Extension("spacy.syntax.parser", ["spacy/syntax/parser.cpp"], **ext_args),
|
|
||||||
Extension("spacy.syntax._state", ["spacy/syntax/_state.cpp"], **ext_args),
|
|
||||||
Extension("spacy.syntax.arc_eager", ["spacy/syntax/arc_eager.cpp"], **ext_args),
|
|
||||||
Extension("spacy.syntax._parse_features", ["spacy/syntax/_parse_features.cpp"],
|
|
||||||
**ext_args)
|
|
||||||
|
|
||||||
#Extension("spacy.pos_feats", ["spacy/pos_feats.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner._state", ["spacy/ner/_state.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.bilou_moves", ["spacy/ner/bilou_moves.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.io_moves", ["spacy/ner/io_moves.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.greedy_parser", ["spacy/ner/greedy_parser.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.pystate", ["spacy/ner/pystate.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.context", ["spacy/ner/context.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.feats", ["spacy/ner/feats.pyx"], language="c++", include_dirs=includes),
|
|
||||||
#Extension("spacy.ner.annot", ["spacy/ner/annot.pyx"], language="c++", include_dirs=includes),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
if sys.argv[1] == 'clean':
|
def cython_ext(mod_name, language, includes, compile_args):
|
||||||
print >> sys.stderr, "cleaning .c, .c++ and .so files matching sources"
|
import Cython.Distutils
|
||||||
map(clean, exts)
|
import Cython.Build
|
||||||
|
mod_path = mod_name.replace('.', '/') + '.pyx'
|
||||||
|
if language == 'cpp':
|
||||||
|
language = 'c++'
|
||||||
|
ext = Extension(mod_name, [mod_path], language=language, include_dirs=includes,
|
||||||
|
extra_compile_args=compile_args)
|
||||||
|
return Cython.Build.cythonize([ext])[0]
|
||||||
|
|
||||||
|
|
||||||
|
def run_setup(exts):
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='spacy',
|
name='spacy',
|
||||||
packages=['spacy', 'spacy.en', 'spacy.syntax'],
|
packages=['spacy', 'spacy.en', 'spacy.syntax'],
|
||||||
|
@ -90,17 +61,34 @@ setup(
|
||||||
"spacy.syntax": ["*.pxd"]},
|
"spacy.syntax": ["*.pxd"]},
|
||||||
ext_modules=exts,
|
ext_modules=exts,
|
||||||
license="Dual: Commercial or AGPL",
|
license="Dual: Commercial or AGPL",
|
||||||
install_requires=['murmurhash', 'numpy', 'cymem', 'preshed', 'thinc', "unidecode",
|
install_requires=['murmurhash', 'numpy', 'cymem', 'preshed', 'thinc',
|
||||||
"ujson"],
|
"unidecode", "ujson"],
|
||||||
setup_requires=["headers_workaround"],
|
setup_requires=["headers_workaround"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
import headers_workaround
|
import headers_workaround
|
||||||
|
|
||||||
|
headers_workaround.fix_venv_pypy_include()
|
||||||
|
headers_workaround.install_headers('murmurhash')
|
||||||
|
headers_workaround.install_headers('numpy')
|
||||||
|
|
||||||
include_dir = path.join(sys.prefix, 'include', 'site')
|
|
||||||
if not path.exists(include_dir):
|
def main(modules, is_pypy):
|
||||||
os.mkdir(include_dir)
|
language = "cpp"
|
||||||
headers_workaround.install_headers(include_dir, 'murmurhash')
|
ext_func = cython_ext if use_cython else c_ext
|
||||||
headers_workaround.install_headers(include_dir, 'numpy')
|
includes = ['.', path.join(sys.prefix, 'include')]
|
||||||
|
compile_args = ['-O3']
|
||||||
|
exts = [ext_func(mn, language, includes, compile_args) for mn in modules]
|
||||||
|
run_setup(exts)
|
||||||
|
|
||||||
|
|
||||||
|
MOD_NAMES = ['spacy.typedefs', 'spacy.strings', 'spacy.lexeme',
|
||||||
|
'spacy.vocab', 'spacy.tokens', 'spacy.morphology',
|
||||||
|
'spacy._ml', 'spacy.tokenizer', 'spacy.en.attrs',
|
||||||
|
'spacy.en.pos', 'spacy.syntax.parser', 'spacy.syntax._state',
|
||||||
|
'spacy.syntax.arc_eager', 'spacy.syntax._parse_features']
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
use_cython = sys.argv[1] == 'build_ext'
|
||||||
|
main(MOD_NAMES, use_cython)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user