2424
2525from setuptools import setup
2626from setuptools .command .test import test
27+ from setuptools .command .build_ext import build_ext
2728from setuptools .command .install import install
29+ from setuptools .command .install_lib import install_lib
2830from setuptools .extension import Extension
2931from distutils .cmd import Command
32+ from distutils .util import get_platform
3033from distutils import log
3134
3235import jpyutil
3639__license__ = jpyutil .__license__
3740__version__ = jpyutil .__version__
3841
39- base_dir = os .path .dirname (os .path .abspath (__file__ ))
42+ base_dir = os .path .dirname (os .path .relpath (__file__ ))
4043src_main_c_dir = os .path .join (base_dir , 'src' , 'main' , 'c' )
4144src_test_py_dir = os .path .join (base_dir , 'src' , 'test' , 'python' )
42-
45+ # src_main_c_dir = 'src/main/c'
46+ # src_test_py_dir = 'src/test/python'
4347
4448do_maven = False
4549if '--maven' in sys .argv :
120124include_dirs = [src_main_c_dir , os .path .join (jdk_home_dir , 'include' )]
121125library_dirs = [jvm_dll_dir ]
122126libraries = [jpyutil .JVM_LIB_NAME ]
127+
123128define_macros = []
124129extra_link_args = []
125130extra_compile_args = []
137142 library_dirs += [os .path .join (sys .exec_prefix , 'lib' )]
138143 extra_link_args += ['-Xlinker' , '-rpath' , jvm_dll_dir ]
139144
145+
146+
140147# ----------- Functions -------------
148+ def _build_dir ():
149+ #return os.path.join(base_dir, 'build/lib.macosx-10.12-x86_64-3.6')
150+ # this is hacky, but use distutils logic to get build dir. see: distutils.command.build
151+ plat = ".%s-%d.%d" % (get_platform (), * sys .version_info [:2 ])
152+ return os .path .join ('build' , 'lib' + plat )
141153
142154def package_maven ():
143155 """ Run maven package lifecycle """
@@ -168,18 +180,16 @@ def package_maven():
168180 log .error ('Maven did not generate any JAR artifacts' )
169181 exit (1 )
170182 for jar_file in jar_files :
171- log .info ("Copying " + jar_file + " -> " + lib_dir + "" )
172- shutil .copy (jar_file , lib_dir )
183+ build_dir = _build_dir ()
184+ log .info ("Copying " + jar_file + " -> " + build_dir + "" )
185+ shutil .copy (jar_file , build_dir )
173186
174187
175188def _read (filename ):
176189 """ Helper function for reading in project files """
177190 with open (filename ) as file :
178191 return file .read ()
179192
180- def _build_dir ():
181- # TODO: figure out logic for dynamically getting this at runtime
182- return os .path .join (base_dir , 'build/lib.macosx-10.12-x86_64-3.6' )
183193
184194def test_python_java_rt ():
185195 """ Run Python test cases against Java runtime classes. """
@@ -204,32 +214,37 @@ def test_maven():
204214 code = subprocess .call (['mvn' , 'test' , mvn_args ], shell = platform .system () == 'Windows' )
205215 return code == 0
206216
207- def _write_jpy_config (target_dir = None ):
217+ def _write_jpy_config (target_dir = None , install_dir = None ):
208218 """
209219 Write out a well-formed jpyconfig.properties file for easier Java
210220 integration in a given location.
211221 """
212222 if not target_dir :
213223 target_dir = _build_dir ()
214- log .info ('Writing jpy configuration to ' + target_dir )
215- return subprocess .call ([sys .executable ,
216- os .path .join (target_dir , 'jpyutil.py' ),
217- '--jvm_dll' , jvm_dll_file ,
218- '--java_home' , jdk_home_dir ,
219- '--log_level' , 'DEBUG' ,
220- '--req_java' ,
221- '--req_py' ])
224+
225+ args = [sys .executable ,
226+ os .path .join (target_dir , 'jpyutil.py' ),
227+ '--jvm_dll' , jvm_dll_file ,
228+ '--java_home' , jdk_home_dir ,
229+ '--log_level' , 'DEBUG' ,
230+ '--req_java' ,
231+ '--req_py' ]
232+ if install_dir :
233+ args .append ('--install_dir' )
234+ args .append (install_dir )
235+
236+ log .info ('Writing jpy configuration to %s using install_dir %s' % (target_dir , install_dir ))
237+ return subprocess .call (args )
222238
223239def _copy_jpyutil ():
224- src = os .path .abspath (jpyutil .__file__ )
240+ src = os .path .relpath (jpyutil .__file__ )
225241 dest = _build_dir ()
226242 log .info ('Copying %s to %s' % (src , dest ))
227243 shutil .copy (src , dest )
228244
229245def _build_jpy ():
230246 package_maven ()
231247 _copy_jpyutil ()
232- _write_jpy_config ()
233248
234249
235250def test_suite ():
@@ -253,7 +268,7 @@ def test_java(self):
253268class MavenBuildCommand (Command ):
254269 """ Custom JPY Maven builder command """
255270 description = 'run Maven to generate JPY jar'
256- user_options = []
271+ user_options = [] # do not remove, needs to be stubbed out!
257272
258273 def initialize_options (self ):
259274 pass
@@ -264,7 +279,7 @@ def finalize_options(self):
264279 def run (self ):
265280 self .announce ('Building JPY' )
266281 _build_jpy ()
267-
282+
268283
269284class JpyBuildBeforeTest (test ):
270285 """ Customization of SetupTools Install command for JPY """
@@ -275,6 +290,13 @@ def run(self):
275290
276291 test .run (self )
277292
293+ class JpyInstallLib (install_lib ):
294+ """ Custom install_lib command for getting install_dir """
295+
296+ def run (self ):
297+ _write_jpy_config (install_dir = self .install_dir )
298+ install_lib .run (self )
299+
278300
279301class JpyInstall (install ):
280302 """ Custom install command to trigger Maven steps """
@@ -298,7 +320,6 @@ def run(self):
298320 url = 'https://github.com/bcdev/jpy' ,
299321 download_url = 'https://pypi.python.org/pypi/jpy/' + __version__ ,
300322 py_modules = ['jpyutil' ],
301- package_data = {'' : [jpy_jar_file ]},
302323 ext_modules = [Extension ('jpy' ,
303324 sources = sources ,
304325 depends = headers ,
@@ -322,7 +343,8 @@ def run(self):
322343 cmdclass = {
323344 'maven' : MavenBuildCommand ,
324345 'test' : JpyBuildBeforeTest ,
325- 'install' : JpyInstall
346+ 'install' : JpyInstall ,
347+ 'install_lib' : JpyInstallLib
326348 },
327349 classifiers = ['Development Status :: 4 - Beta' ,
328350 # Indicate who your project is intended for
@@ -337,4 +359,5 @@ def run(self):
337359 'Programming Language :: Python :: 2.7' ,
338360 'Programming Language :: Python :: 3' ,
339361 'Programming Language :: Python :: 3.3' ,
340- 'Programming Language :: Python :: 3.4' ])
362+ 'Programming Language :: Python :: 3.4' ,
363+ 'Programming Language :: Python :: 3.5' ])
0 commit comments