forked from chezou/Mykytea-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
64 lines (52 loc) · 1.64 KB
/
setup.py
File metadata and controls
64 lines (52 loc) · 1.64 KB
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
#!/usr/bin/env python
try:
from setuptools import setup, Extension
has_setuptools = True
except ImportError:
from distutils.core import setup, Extension
has_setuptools = False
# Subclass the build commands to run build_ext before build_py so that
# build_py can find Mykytea.py.
# ref. http://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
cmdclass = {}
def patch_command(name, base_class):
class CustomCommand(base_class):
def run(self):
self.run_command('build_ext')
base_class.run(self)
cmdclass[name] = CustomCommand
from distutils.command.build import build
patch_command('build', build)
if has_setuptools:
from setuptools.command.install import install
from setuptools.command.bdist_egg import bdist_egg
patch_command('install', install)
patch_command('bdist_egg', bdist_egg)
def has_swig():
import os
import subprocess
devnull = open(os.devnull, 'w')
retcode = subprocess.call(['swig', '-version'], stdout=devnull)
return retcode == 0
use_swig = has_swig()
if use_swig:
ext_module = Extension(
'_Mykytea',
sources=['mykytea.i', 'mykytea.cpp'],
libraries=["kytea"],
swig_opts=['-Wall', '-shadow', '-c++', '-I/usr/local/include'],
)
else:
ext_module = Extension(
'_Mykytea',
sources=['mykytea_wrap.cxx', 'mykytea.cpp'],
libraries=["kytea"],
)
setup(name='kytea-python',
version='0.1',
author='chezou',
author_email='[email protected]',
cmdclass=cmdclass,
py_modules=['Mykytea'],
ext_modules=[ext_module],
)