This repository has been archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
93 lines (83 loc) · 3.3 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import os
import pathlib
from setuptools import find_packages, setup, Extension
from setuptools.command.build_ext import build_ext
class cython_build_ext(build_ext):
user_options = build_ext.user_options + [
('annotate', None,
'Generate HTML files with Python overhead annotation for Cython')
]
def initialize_options(self):
build_ext.initialize_options(self)
self.annotate = False
def finalize_options(self):
build_ext.finalize_options(self)
if self.annotate:
self.force = True
def run(self):
build_ext.run(self)
abs_path = pathlib.Path(__file__).absolute()
c_paths = [
abs_path / "src/finalfusion/subword/hash_indexers.c",
abs_path / "src/finalfusion/subword/ngrams.c",
abs_path / "src/finalfusion/subword/explicit_indexer.c"
]
# cython is needed if not all extensions have been cythonized
need_cython = not all(map(os.path.exists, c_paths))
# or if annotation or force is specified
annotate = "--annotate" in sys.argv
force = "--force" in sys.argv or annotate
if need_cython or force or annotate:
try:
from Cython.Build import cythonize
from Cython.Compiler import Options
except ImportError:
print("Please install Cython", file=sys.stderr)
exit(1)
Options.annotate = annotate
Options.docstrings = True
Options.embed_pos_in_docstring = True
Options.warning_errors = True
hash_indexers = Extension(
"finalfusion.subword.hash_indexers",
["src/finalfusion/subword/hash_indexers.pyx", "src/fnv/hash_64a.c"],
include_dirs=["src/fnv/", "src/include"])
ngrams = Extension("finalfusion.subword.ngrams",
["src/finalfusion/subword/ngrams.pyx"])
explicit_indexer = Extension(
"finalfusion.subword.explicit_indexer",
["src/finalfusion/subword/explicit_indexer.pyx"])
extensions = cythonize([hash_indexers, ngrams, explicit_indexer], force=force)
else:
# sdist should include the C files so Cython isn't required
hash_indexers = Extension(
"finalfusion.subword.hash_indexers",
["src/finalfusion/subword/hash_indexers.c", "src/fnv/hash_64a.c"],
include_dirs=["src/fnv/", "src/include"])
ngrams = Extension("finalfusion.subword.ngrams",
["src/finalfusion/subword/ngrams.c"])
explicit_indexer = Extension(
"finalfusion.subword.explicit_indexer",
["src/finalfusion/subword/explicit_indexer.c"])
extensions = [hash_indexers, ngrams, explicit_indexer]
setup(name='finalfusion',
author="Sebastian Pütz",
author_email="[email protected]",
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Topic :: Text Processing :: Linguistic",
],
cmdclass={'build_ext': cython_build_ext},
description="Interface to finalfusion embeddings",
ext_modules=extensions,
install_requires=["numpy", "toml"],
license='BlueOak-1.0.0',
packages=find_packages('src'),
include_package_data=True,
package_dir={'': 'src'},
package_data={'finalfusion': ['py.typed', '*.pyi', '*.h', '*.c']},
url="https://github.com/finalfusion/ffp",
entry_points=dict(console_scripts=['ffp-convert=finalfusion.scripts.convert:main']),
)