Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,35 @@


# ----------- Functions -------------
from distutils.ccompiler import new_compiler
from sysconfig import get_paths

class StaticLib(Command):
description = 'build static lib'
user_options = [] # do not remove, needs to be stubbed out!
python_info = get_paths()

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
# Create compiler with default options
c = new_compiler()

# Optionally add include directories etc.
for d in include_dirs:
c.add_include_dir(d)

c.add_include_dir(self.python_info['include'])
# Compile into .o files
objects = c.compile(sources)

# Create static or shared library
c.create_static_lib(objects, "jpy", output_dir=_build_dir())

def _build_dir():
# this is hacky, but use distutils logic to get build dir. see: distutils.command.build
plat = ".%s-%d.%d" % (get_platform(), sys.version_info.major, sys.version_info.minor)
Expand Down Expand Up @@ -205,7 +234,7 @@ def test_python_java_classes():
log.info('Executing Python unit tests (against JPY test classes)...')
return jpyutil._execute_python_scripts(python_java_jpy_tests,
env=sub_env)

def test_maven():
jpy_config = os.path.join(_build_dir(),'jpyconfig.properties')
mvn_args = '-DargLine=-Xmx512m -Djpy.config=' + jpy_config + ' -Djpy.debug=true'
Expand All @@ -220,7 +249,7 @@ def _write_jpy_config(target_dir=None, install_dir=None):
"""
if not target_dir:
target_dir = _build_dir()

args = [sys.executable,
os.path.join(target_dir, 'jpyutil.py'),
'--jvm_dll', jvm_dll_file,
Expand All @@ -245,14 +274,14 @@ def _build_jpy():
package_maven()
_copy_jpyutil()
_write_jpy_config()


def test_suite():
suite = unittest.TestSuite()

def test_python_with_java_runtime(self):
assert 0 == test_python_java_rt()

def test_python_with_java_classes(self):
assert 0 == test_python_java_classes()

Expand Down Expand Up @@ -287,20 +316,20 @@ class JpyBuildBeforeTest(test):
def run(self):
self.run_command('build')
self.run_command('maven')

test.run(self)

class JpyInstallLib(install_lib):
""" Custom install_lib command for getting install_dir """

def run(self):
_write_jpy_config(install_dir=self.install_dir)
install_lib.run(self)


class JpyInstall(install):
""" Custom install command to trigger Maven steps """

def run(self):
self.run_command('build')
self.run_command('maven')
Expand Down Expand Up @@ -344,7 +373,8 @@ def run(self):
'maven': MavenBuildCommand,
'test': JpyBuildBeforeTest,
'install': JpyInstall,
'install_lib': JpyInstallLib
'install_lib': JpyInstallLib,
'static': StaticLib
},
classifiers=['Development Status :: 4 - Beta',
# Indicate who your project is intended for
Expand Down
14 changes: 13 additions & 1 deletion src/main/c/jpy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,19 @@ PyObject* JPy_has_jvm(PyObject* self)
return PyBool_FromLong(JPy_JVM != NULL);
}

PyObject* JPy_get_jvm(PyObject* self)
{
JavaVM** jvms;
jsize nVMs = 0;

JNI_GetCreatedJavaVMs(NULL, 0, &nVMs); // 1. just get the required array length
jvms = (JavaVM**)malloc(sizeof(JavaVM*) * nVMs);
JNI_GetCreatedJavaVMs(jvms, nVMs, &nVMs); // 2. get the data
printf("jvm status: %p:%u\nstarting python\n", *jvms, nVMs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only print, if global diagnosis flag is set.

JPy_JVM = *jvms;
return PyBool_FromLong(JPy_JVM != NULL);
}

PyObject* JPy_create_jvm(PyObject* self, PyObject* args, PyObject* kwds)
{
static char* keywords[] = {"options", NULL};
Expand Down Expand Up @@ -1263,4 +1276,3 @@ void JPy_free(void* unused)

JPy_DIAG_PRINT(JPy_DIAG_F_ALL, "JPy_free: done freeing module data\n");
}