-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·127 lines (110 loc) · 4.28 KB
/
setup.py
File metadata and controls
executable file
·127 lines (110 loc) · 4.28 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
import codecs
import os
import sysconfig
from setuptools import setup, Extension
from commands import jep_build
from commands.clean import really_clean
from commands.dist import JepDistribution
from commands.install_lib import jep_install
from commands.java import build_java, get_java_home, get_java_include,\
get_java_linker_args, build_jar, get_java_lib_folders, get_java_libraries, setup_java
from commands.javadoc import javadoc
from commands.python import get_libpython, get_python_libs, get_python_linker_args
from commands.scripts import build_scripts
from commands.test import test
from commands.util import is_windows
from commands.build_ext import build_ext
VERSION = None # shut up pycharm
with open('src/main/python/jep/version.py') as f:
exec(f.read())
numpy_include = []
numpy_found = 0
try:
import numpy
numpy1_include_path = os.path.join(numpy.__path__[0], 'core', 'include')
numpy2_include_path = os.path.join(numpy.__path__[0], '_core', 'include')
if os.path.exists(numpy1_include_path):
print('numpy include found at', numpy1_include_path)
numpy_found = 1
numpy_include = [numpy1_include_path]
elif os.path.exists(numpy2_include_path):
print('numpy include found at', numpy2_include_path)
numpy_found = 1
numpy_include = [numpy2_include_path]
else:
print('numpy include not found')
except ImportError:
print('numpy not found, running without numpy support')
def get_files(pattern):
ret = []
for root, dirs, files in os.walk('src'):
for f in files:
if f.endswith(pattern):
ret.append(os.path.join(root, f))
return ret
def read_file(name):
return codecs.open(os.path.join(os.path.dirname(__file__), name), encoding='utf-8').read()
if __name__ == '__main__':
get_java_home()
defines=[
('PACKAGE', 'jep'),
('USE_DEALLOC', 1),
('JEP_NUMPY_ENABLED', numpy_found),
('VERSION', '"{0}"'.format(VERSION)),
]
ldlib = get_libpython()
if ldlib:
# a libpython was found, so use the basename of the discovered path
ldlib = os.path.basename(ldlib)
else:
# no libpython was found, so use LDLIBRARY blindly
ldlib = sysconfig.get_config_var('LDLIBRARY')
if ldlib:
defines.append(('PYTHON_LDLIBRARY', '"' + ldlib + '"'))
if is_windows():
defines.append(('WIN32', 1))
#Disable warnings about Secure CRT Functions in util.c and pyembed.c.
defines.append(('_CRT_SECURE_NO_WARNINGS', 1))
setup(version=VERSION,
packages=['jep'],
package_dir={'': 'src/main/python'},
scripts=['src/main/scripts/jep'],
ext_modules=[
Extension(
name='jep',
sources=get_files('.c'),
define_macros=defines,
libraries=get_java_libraries() + get_python_libs(),
library_dirs=get_java_lib_folders(),
extra_link_args=get_java_linker_args() + get_python_linker_args(),
include_dirs=get_java_include() + ['src/main/c/Include', 'build/include',] + numpy_include,
)
],
# my hacks to compile java files
java_files=get_files('.java'),
extra_jar_files=['src/main/resources/jep/classlist_8.txt',
'src/main/resources/jep/classlist_9.txt',
'src/main/resources/jep/classlist_10.txt',
'src/main/resources/jep/classlist_11.txt'],
javah_files=['jep.Jep',
'jep.MainInterpreter',
'jep.python.InvocationHandler',
'jep.python.PyObject',
'jep.python.PyCallable',
'jep.python.PyPointer'],
distclass=JepDistribution,
cmdclass={
'setup_java': setup_java,
'build_java': build_java,
'javadoc': javadoc,
'build_jar': build_jar,
'build': jep_build,
'build_ext' : build_ext,
'build_scripts': build_scripts,
'install_lib': jep_install,
'clean': really_clean,
'test': test,
},
zip_safe=False
)