2018-10-13 21:22:39 +00:00
|
|
|
'''
|
|
|
|
Setup.py for creating a binary distribution.
|
|
|
|
'''
|
|
|
|
|
2015-05-01 21:57:22 +00:00
|
|
|
from __future__ import print_function
|
2019-09-17 13:08:24 +00:00
|
|
|
from setuptools import setup, Extension
|
2019-11-24 14:15:20 +00:00
|
|
|
from setuptools.command.build_ext import build_ext
|
2017-10-24 14:33:12 +00:00
|
|
|
try:
|
|
|
|
import subprocess32 as subprocess
|
|
|
|
except ImportError:
|
|
|
|
import subprocess
|
2019-11-24 22:05:11 +00:00
|
|
|
|
2012-08-14 01:42:43 +00:00
|
|
|
from os import environ
|
2019-11-24 22:05:11 +00:00
|
|
|
from os.path import dirname, join, exists
|
2019-07-26 02:01:42 +00:00
|
|
|
import re
|
2012-08-14 01:42:43 +00:00
|
|
|
import sys
|
2015-11-19 17:51:18 +00:00
|
|
|
from platform import machine
|
2018-10-13 21:22:39 +00:00
|
|
|
from setup_sdist import SETUP_KWARGS
|
2015-11-04 22:01:48 +00:00
|
|
|
|
2019-11-24 22:05:11 +00:00
|
|
|
# XXX hack to be able to import jnius.env withough having build
|
|
|
|
# jnius.jnius yet, better solution welcome
|
|
|
|
syspath = sys.path[:]
|
|
|
|
sys.path.insert(0, 'jnius')
|
|
|
|
from env import (
|
|
|
|
get_possible_homes,
|
|
|
|
get_library_dirs,
|
|
|
|
get_include_dirs,
|
|
|
|
get_libraries,
|
|
|
|
find_javac,
|
|
|
|
PY2,
|
|
|
|
)
|
|
|
|
sys.path = syspath
|
2012-08-14 01:42:43 +00:00
|
|
|
|
2015-11-03 13:57:04 +00:00
|
|
|
def getenv(key):
|
2018-10-13 21:22:39 +00:00
|
|
|
'''Get value from environment and decode it.'''
|
2015-11-03 13:57:04 +00:00
|
|
|
val = environ.get(key)
|
2019-11-24 22:05:11 +00:00
|
|
|
if val is not None and not PY2:
|
|
|
|
try:
|
|
|
|
return val.decode()
|
|
|
|
except AttributeError:
|
|
|
|
return val
|
2016-02-07 14:08:50 +00:00
|
|
|
return val
|
2015-11-03 13:57:04 +00:00
|
|
|
|
2017-03-23 17:56:02 +00:00
|
|
|
|
2018-10-13 21:22:39 +00:00
|
|
|
FILES = [
|
2012-08-20 23:19:43 +00:00
|
|
|
'jni.pxi',
|
2019-01-05 14:08:49 +00:00
|
|
|
'jnius_compat.pxi',
|
2012-08-20 23:19:43 +00:00
|
|
|
'jnius_conversion.pxi',
|
|
|
|
'jnius_export_class.pxi',
|
|
|
|
'jnius_export_func.pxi',
|
|
|
|
'jnius_jvm_android.pxi',
|
|
|
|
'jnius_jvm_desktop.pxi',
|
2015-05-01 16:16:58 +00:00
|
|
|
'jnius_jvm_dlopen.pxi',
|
2012-08-20 23:19:43 +00:00
|
|
|
'jnius_localref.pxi',
|
|
|
|
'jnius.pyx',
|
|
|
|
'jnius_utils.pxi',
|
|
|
|
]
|
|
|
|
|
2018-10-13 21:22:39 +00:00
|
|
|
EXTRA_LINK_ARGS = []
|
|
|
|
INSTALL_REQUIRES = ['six>=1.7.0']
|
2019-04-29 04:08:16 +00:00
|
|
|
SETUP_REQUIRES = []
|
2012-08-14 01:42:43 +00:00
|
|
|
|
|
|
|
# detect Python for android
|
2018-10-13 21:22:39 +00:00
|
|
|
PLATFORM = sys.platform
|
|
|
|
NDKPLATFORM = getenv('NDKPLATFORM')
|
|
|
|
if NDKPLATFORM is not None and getenv('LIBLINK'):
|
|
|
|
PLATFORM = 'android'
|
2012-08-14 01:42:43 +00:00
|
|
|
|
|
|
|
# detect cython
|
2019-11-24 14:15:20 +00:00
|
|
|
if PLATFORM != 'android':
|
|
|
|
SETUP_REQUIRES.append('cython')
|
2018-10-13 21:22:39 +00:00
|
|
|
INSTALL_REQUIRES.append('cython')
|
2019-11-24 14:15:20 +00:00
|
|
|
else:
|
|
|
|
FILES = [fn[:-3] + 'c' for fn in FILES if fn.endswith('pyx')]
|
2018-10-13 21:22:39 +00:00
|
|
|
|
2012-08-14 01:42:43 +00:00
|
|
|
|
2017-10-29 16:21:40 +00:00
|
|
|
def compile_native_invocation_handler(*possible_homes):
|
2018-10-13 21:22:39 +00:00
|
|
|
'''Find javac and compile NativeInvocationHandler.java.'''
|
2019-11-24 22:05:11 +00:00
|
|
|
javac = find_javac(PLATFORM, possible_homes)
|
2019-11-24 01:49:28 +00:00
|
|
|
source_level = '1.7'
|
2019-05-17 03:36:20 +00:00
|
|
|
try:
|
2019-11-24 01:49:28 +00:00
|
|
|
subprocess.check_call([
|
|
|
|
javac, '-target', source_level, '-source', source_level,
|
|
|
|
join('jnius', 'src', 'org', 'jnius', 'NativeInvocationHandler.java')
|
|
|
|
])
|
2019-05-17 03:36:20 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
subprocess.check_call([
|
2019-11-23 13:17:32 +00:00
|
|
|
javac.replace('"', ''), '-target', source_level, '-source', source_level,
|
2019-05-17 03:36:20 +00:00
|
|
|
join('jnius', 'src', 'org', 'jnius', 'NativeInvocationHandler.java')
|
|
|
|
])
|
2017-10-29 16:21:40 +00:00
|
|
|
|
2019-11-24 22:05:11 +00:00
|
|
|
compile_native_invocation_handler(*get_possible_homes(PLATFORM))
|
2018-11-29 04:45:36 +00:00
|
|
|
|
2017-10-29 16:21:40 +00:00
|
|
|
|
2012-08-14 01:42:43 +00:00
|
|
|
# generate the config.pxi
|
2012-08-14 13:09:48 +00:00
|
|
|
with open(join(dirname(__file__), 'jnius', 'config.pxi'), 'w') as fd:
|
2018-10-13 21:22:39 +00:00
|
|
|
fd.write('DEF JNIUS_PLATFORM = {0!r}\n\n'.format(PLATFORM))
|
2019-01-31 17:02:00 +00:00
|
|
|
if not PY2:
|
2019-09-17 13:08:24 +00:00
|
|
|
fd.write('# cython: language_level=3\n\n')
|
2015-05-01 21:57:22 +00:00
|
|
|
fd.write('DEF JNIUS_PYTHON3 = True\n\n')
|
|
|
|
else:
|
2019-09-17 13:08:24 +00:00
|
|
|
fd.write('# cython: language_level=2\n\n')
|
2015-05-01 21:57:22 +00:00
|
|
|
fd.write('DEF JNIUS_PYTHON3 = False\n\n')
|
2012-08-14 01:42:43 +00:00
|
|
|
|
2018-11-27 17:53:01 +00:00
|
|
|
# pop setup.py from included files in the installed package
|
|
|
|
SETUP_KWARGS['py_modules'].remove('setup')
|
|
|
|
|
2012-08-14 01:42:43 +00:00
|
|
|
# create the extension
|
2017-03-23 17:56:02 +00:00
|
|
|
setup(
|
|
|
|
cmdclass={'build_ext': build_ext},
|
2018-10-13 21:22:39 +00:00
|
|
|
install_requires=INSTALL_REQUIRES,
|
2019-04-29 04:08:16 +00:00
|
|
|
setup_requires=SETUP_REQUIRES,
|
2017-03-23 17:56:02 +00:00
|
|
|
ext_modules=[
|
|
|
|
Extension(
|
2018-10-13 21:22:39 +00:00
|
|
|
'jnius', [join('jnius', x) for x in FILES],
|
2019-11-24 22:05:11 +00:00
|
|
|
libraries=get_libraries(PLATFORM),
|
|
|
|
library_dirs=get_library_dirs(PLATFORM),
|
|
|
|
include_dirs=get_include_dirs(PLATFORM),
|
2019-09-17 13:08:24 +00:00
|
|
|
extra_link_args=EXTRA_LINK_ARGS,
|
2017-03-23 17:56:02 +00:00
|
|
|
)
|
|
|
|
],
|
2019-09-17 13:08:24 +00:00
|
|
|
extras_require={
|
2019-12-05 22:57:13 +00:00
|
|
|
'dev': ['pytest', 'wheel', 'pytest-cov', 'pycodestyle'],
|
2019-09-17 13:08:24 +00:00
|
|
|
'ci': ['coveralls', 'pytest-rerunfailures', 'setuptools>=34.4.0'],
|
|
|
|
},
|
2018-10-13 20:59:51 +00:00
|
|
|
**SETUP_KWARGS
|
2017-03-23 17:56:02 +00:00
|
|
|
)
|