spaCy/setup.py

169 lines
5.5 KiB
Python
Raw Normal View History

2014-07-05 22:49:34 +04:00
#!/usr/bin/env python
2015-01-04 21:30:56 +03:00
from setuptools import setup
2015-03-09 08:46:35 +03:00
import shutil
2015-01-04 21:30:56 +03:00
2014-07-05 22:49:34 +04:00
import sys
import os
from os import path
2015-01-04 21:30:56 +03:00
from setuptools import Extension
from distutils import sysconfig
import platform
2015-01-17 08:19:54 +03:00
# PyPy --- NB! PyPy doesn't really work, it segfaults all over the place. But,
# this is necessary to get it compile.
# We have to resort to monkey-patching to set the compiler, because pypy broke
# all the everything.
2015-01-06 05:05:43 +03:00
pre_patch_customize_compiler = sysconfig.customize_compiler
def my_customize_compiler(compiler):
2015-01-06 05:05:43 +03:00
pre_patch_customize_compiler(compiler)
compiler.compiler_cxx = ['c++']
if platform.python_implementation() == 'PyPy':
sysconfig.customize_compiler = my_customize_compiler
2015-01-03 13:02:10 +03:00
2015-01-25 06:49:10 +03:00
#def install_headers():
# dest_dir = path.join(sys.prefix, 'include', 'murmurhash')
# if not path.exists(dest_dir):
# shutil.copytree('murmurhash/headers/murmurhash', dest_dir)
#
# dest_dir = path.join(sys.prefix, 'include', 'numpy')
2015-01-17 08:19:54 +03:00
includes = ['.', path.join(sys.prefix, 'include')]
2015-01-25 06:49:10 +03:00
try:
import numpy
numpy_headers = path.join(numpy.get_include(), 'numpy')
shutil.copytree(numpy_headers, path.join(sys.prefix, 'include', 'numpy'))
2015-01-25 06:49:10 +03:00
except ImportError:
pass
except OSError:
pass
2015-01-25 06:49:10 +03:00
2015-03-09 08:46:35 +03:00
def clean(mod_names):
for name in mod_names:
name = name.replace('.', '/')
so = name + '.so'
html = name + '.html'
cpp = name + '.cpp'
c = name + '.c'
for file_path in [so, html, cpp, c]:
if os.path.exists(file_path):
2015-03-09 14:06:33 +03:00
os.unlink(file_path)
2014-07-05 22:49:34 +04:00
2015-01-04 21:30:56 +03:00
def name_to_path(mod_name, ext):
return '%s.%s' % (mod_name.replace('.', '/'), ext)
def c_ext(mod_name, language, includes, compile_args, link_args):
2015-01-04 21:30:56 +03:00
mod_path = name_to_path(mod_name, language)
return Extension(mod_name, [mod_path], include_dirs=includes,
extra_compile_args=compile_args, extra_link_args=compile_args)
def cython_setup(mod_names, language, includes, compile_args, link_args):
2015-01-04 21:30:56 +03:00
import Cython.Distutils
import Cython.Build
import distutils.core
2015-01-04 21:30:56 +03:00
if language == 'cpp':
language = 'c++'
2015-01-28 06:00:20 +03:00
exts = []
for mod_name in mod_names:
mod_path = mod_name.replace('.', '/') + '.pyx'
e = Extension(mod_name, [mod_path], language=language, include_dirs=includes,
extra_compile_args=compile_args, extra_link_args=link_args)
2015-01-28 06:00:20 +03:00
exts.append(e)
distutils.core.setup(
name='spacy',
packages=['spacy', 'spacy.en', 'spacy.syntax'],
description="Industrial-strength NLP",
author='Matthew Honnibal',
author_email='honnibal@gmail.com',
2015-06-07 20:05:28 +03:00
version=VERSION,
url="http://honnibal.github.io/spaCy/",
package_data={"spacy": ["*.pxd"],
"spacy.en": ["*.pxd", "data/pos/*",
"data/wordnet/*", "data/tokenizer/*",
"data/vocab/lexemes.bin",
"data/vocab/strings.txt"],
"spacy.syntax": ["*.pxd"]},
ext_modules=exts,
cmdclass={'build_ext': Cython.Distutils.build_ext},
license="Dual: Commercial or AGPL",
)
2015-01-04 21:30:56 +03:00
def run_setup(exts):
setup(
name='spacy',
packages=['spacy', 'spacy.en', 'spacy.syntax', 'spacy.munge'],
2015-01-04 21:30:56 +03:00
description="Industrial-strength NLP",
author='Matthew Honnibal',
author_email='honnibal@gmail.com',
2015-06-07 20:05:28 +03:00
version=VERSION,
2015-01-04 21:30:56 +03:00
url="http://honnibal.github.io/spaCy/",
package_data={"spacy": ["*.pxd"],
"spacy.en": ["*.pxd", "data/pos/*",
"data/wordnet/*", "data/tokenizer/*",
"data/vocab/lexemes.bin",
"data/vocab/strings.txt"],
2015-01-04 21:30:56 +03:00
"spacy.syntax": ["*.pxd"]},
ext_modules=exts,
license="Dual: Commercial or AGPL",
2015-06-07 23:24:21 +03:00
install_requires=['numpy', 'murmurhash', 'cymem >= 1.11', 'preshed == 0.37',
2015-06-30 19:10:37 +03:00
'thinc == 3.2', "unidecode", 'wget', 'plac', 'six',
2015-06-07 23:24:21 +03:00
'ujson'],
2015-01-04 21:30:56 +03:00
setup_requires=["headers_workaround"],
)
import headers_workaround
headers_workaround.fix_venv_pypy_include()
headers_workaround.install_headers('murmurhash')
2015-01-17 08:19:54 +03:00
headers_workaround.install_headers('numpy')
2015-01-04 21:30:56 +03:00
2015-07-08 21:07:23 +03:00
VERSION = '0.88'
2015-01-04 21:30:56 +03:00
def main(modules, is_pypy):
language = "cpp"
includes = ['.', path.join(sys.prefix, 'include')]
compile_args = ['-O3', '-Wno-strict-prototypes']
link_args = []
if sys.prefix == 'darwin':
compile_args.append(['-mmacosx-version-min=10.8', '-stdlib=libc++'])
link_args.append('-lc++')
2015-01-28 06:00:20 +03:00
if use_cython:
cython_setup(modules, language, includes, compile_args, link_args)
2015-01-28 06:00:20 +03:00
else:
exts = [c_ext(mn, language, includes, compile_args, link_args)
for mn in modules]
run_setup(exts)
2015-01-04 21:30:56 +03:00
2015-01-25 08:32:48 +03:00
MOD_NAMES = ['spacy.parts_of_speech', 'spacy.strings',
'spacy.lexeme', 'spacy.vocab', 'spacy.tokens', 'spacy.spans',
'spacy.morphology',
2015-06-09 22:20:33 +03:00
'spacy.syntax.stateclass',
2015-01-04 21:30:56 +03:00
'spacy._ml', 'spacy.tokenizer', 'spacy.en.attrs',
2015-06-10 08:09:17 +03:00
'spacy.en.pos', 'spacy.syntax.parser',
2015-04-19 11:31:31 +03:00
'spacy.syntax.transition_system',
2015-06-14 21:28:14 +03:00
'spacy.syntax.arc_eager',
'spacy.syntax._parse_features',
2015-06-09 22:20:33 +03:00
'spacy.gold', 'spacy.orth',
2015-03-09 08:46:35 +03:00
'spacy.syntax.ner']
2015-01-04 21:30:56 +03:00
if __name__ == '__main__':
2015-03-09 08:46:35 +03:00
if sys.argv[1] == 'clean':
clean(MOD_NAMES)
else:
use_cython = sys.argv[1] == 'build_ext'
main(MOD_NAMES, use_cython)