Created
February 13, 2014 11:00
-
-
Save arnoutaertgeerts/8973219 to your computer and use it in GitHub Desktop.
Jpype alternative setup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import codecs | |
import platform | |
import subprocess | |
from glob import glob | |
from distutils.core import setup | |
from distutils.core import Extension | |
def read_utf8(*parts): | |
filename = os.path.join(os.path.dirname(__file__), *parts) | |
return codecs.open(filename, encoding='utf-8').read() | |
def find_sources(): | |
cpp_files = [] | |
for dirpath, dirnames, filenames in os.walk('src'): | |
for filename in filenames: | |
if filename.endswith('.cpp') or filename.endswith('.c'): | |
cpp_files.append(os.path.join(dirpath, filename)) | |
return cpp_files | |
platform_specific = { | |
'include_dirs': [ | |
os.path.join('src', 'native', 'common', 'include'), | |
os.path.join('src', 'native', 'python', 'include'), | |
], | |
'sources': find_sources(), | |
} | |
java_home = os.getenv('JAVA_HOME') | |
if sys.platform == 'win32': | |
if not java_home: | |
raise SystemExit('Environment variable JAVA_HOME must be set.') | |
platform_specific['libraries'] = ['Advapi32'] | |
platform_specific['library_dir'] = [os.path.join(java_home, 'lib'), ] | |
platform_specific['define_macros'] = [('WIN32', 1)] | |
platform_specific['extra_compile_args'] = ['/EHsc'] | |
platform_specific['include_dirs'] += [ | |
os.path.join(java_home, 'include'), | |
os.path.join(java_home, 'include', 'win32') | |
] | |
elif sys.platform == 'darwin': | |
# Changes according to: | |
# http://stackoverflow.com/questions/8525193/cannot-install-jpype-on-os-x-lion-to-use-with-neo4j | |
# and | |
# http://blog.y3xz.com/post/5037243230/installing-jpype-on-mac-os-x | |
osx = platform.mac_ver()[0][:4] | |
platform_specific['libraries'] = ['dl'] | |
platform_specific['library_dir'] = [os.path.join(java_home, '/Libraries')] | |
platform_specific['define_macros'] = [('MACOSX', 1)] | |
# Found a more OS X way to find the correct java_home here: | |
# https://github.com/benol/JPype/blob/master/setup.py | |
# The elegant way is a tool in usr/libexec/java_home | |
# which returns the actual javaHome path to the newest version. Works with Apple and Oracle Java Versions. | |
# If needed you can also add the Java Version like so | |
# /usr/libexec/java_home -v 1.7 | |
# to determine the path to the needed version | |
if not java_home: | |
print "No JAVA_HOME Environment Variable set. Trying to determine it..." | |
# First try with /usr/libexec/java_home | |
java_home = subprocess.check_output('/usr/libexec/java_home').strip() | |
if not os.path.isdir(java_home): | |
# did not work. Try with some experience | |
print "Result of /usr/libexec/java_home doesn't exist! To avoid this you could install the Apple Developer Tools. Trying to guess it..." | |
java_home = '/Library/Java/Home' | |
if osx == '10.6': | |
# I'm not sure if this really works on all 10.6 - confirm please :) | |
java_home = ('/Developer/SDKs/MacOSX10.6.sdk/System/Library/' | |
'Frameworks/JavaVM.framework/Versions/1.6.0/') | |
elif osx in ('10.7', '10.8', ): | |
java_home = ('/System/Library/Frameworks/JavaVM.framework/' | |
'Versions/Current/') | |
elif osx in ('10.9', ): | |
java_home = '/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home' | |
# if not os.path.isdir(java_home): | |
# print "Could not guess the path to java_home! Try setting it yourself in your shell and rerun setup.py." | |
# print "Make sure that a JavaJDK has been installed. ( http://www.oracle.com/technetwork/java/javase/downloads/index.html )" | |
# print "then correct a symbolic link using" | |
# print "sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.7.0_<version>.jdk/Contents \" | |
# print " /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK" | |
# print "where <version> is the version number you downloaded" | |
# print "Good Luck!" | |
possible_includedirs = [os.path.join(java_home, 'Headers'), | |
os.path.join(java_home, 'include'), | |
os.path.join(java_home, 'include/darwin'), ] | |
platform_specific['include_dirs'] += filter(os.path.exists, possible_includedirs) | |
jpypeLib = Extension(name='_jpype', **platform_specific) | |
setup( | |
name='JPype1', | |
version='0.5.4.6', | |
description='Friendly jpype fork with focus on easy installation.', | |
long_description=read_utf8('README.rst'), | |
license='License :: OSI Approved :: Apache Software License', | |
author='Steve Menard', | |
author_email='devilwolf@users.sourceforge.net', | |
maintainer='Luis Nell', | |
maintainer_email='cooperate@originell.org', | |
url='https://github.com/originell/jpype/', | |
platforms=[ | |
'Operating System :: MacOS :: MacOS X', | |
'Operating System :: Microsoft :: Windows :: Windows 7', | |
'Operating System :: Microsoft :: Windows :: Windows Vista', | |
'Operating System :: POSIX :: Linux', | |
], | |
classifiers=[ | |
'Programming Language :: Java', | |
'Programming Language :: Python :: 2.5', | |
'Programming Language :: Python :: 2.6', | |
'Programming Language :: Python :: 2.7', | |
], | |
packages=[ | |
'jpype', 'jpype.awt', 'jpype.awt.event', 'jpypex', 'jpypex.swing'], | |
package_dir={ | |
'jpype': 'src/python/jpype', | |
'jpypex': 'src/python/jpypex', | |
}, | |
ext_modules=[jpypeLib], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment