Пример #1
0
    def __init__(self,
                 resource_dir=False,
                 jvm_maxmem='512M',
                 jvm_classpath=None):
        self.WINDOWS = True if os.name == 'nt' else False
        self.SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
        self.LIBS = os.path.join(self.SCRIPT_DIR, 'jasperstarter', 'lib')
        if not os.path.isdir(self.LIBS):
            raise NameError('Unable to find lib in {0}'.format(self.LIBS))
        self.CLASSPATH = os.path.join(self.LIBS, 'jasperstarter.jar')
        if not os.path.exists(self.CLASSPATH):
            raise NameError('Unable to find jasperstarter in {0}'.format(
                self.LIBS))
        if jvm_classpath is None:
            jpyutil.init_jvm(jvm_maxmem=jvm_maxmem,
                             jvm_classpath=[self.CLASSPATH])
        else:
            jpyutil.init_jvm(jvm_maxmem=jvm_maxmem,
                             jvm_classpath=[self.CLASSPATH, jvm_classpath])
        # import jpy here after init_jvm
        import jpy
        self.jvFile = jpy.get_type('java.io.File')
        self.jvArrays = jpy.get_type('java.util.Arrays')
        self.jvReport = jpy.get_type('de.cenote.jasperstarter.Report')
        self.jvConfig = jpy.get_type('de.cenote.jasperstarter.Config')
        self.jvDsType = jpy.get_type('de.cenote.jasperstarter.types.DsType')
        self.jvApplicationClasspath = jpy.get_type(
            'de.cenote.tools.classpath.ApplicationClasspath')
        self.jvHashMap = jpy.get_type('java.util.HashMap')
        self.jvLocale = jpy.get_type('java.util.Locale')
        self.jvJasperFillManager = jpy.get_type(
            'net.sf.jasperreports.engine.JasperFillManager')
        self.jvDb = jpy.get_type('de.cenote.jasperstarter.Db')
        self.jvJsonQueryExecuterFactory = jpy.get_type(
            'net.sf.jasperreports.engine.query.JsonQueryExecuterFactory')
        self.jvJasperExportManager = jpy.get_type(
            'net.sf.jasperreports.engine.JasperExportManager')


        self.path_executable = os.path.dirname(os.path.abspath(__file__)) \
                               + '/jasperstarter/bin'
        self.windows = True if os.name == 'nt' else False
        self._command = ''

        if not resource_dir:
            resource_dir = os.path.dirname(os.path.abspath(__file__)) \
                           + '/jasperstarter/bin'
        else:
            if not os.path.exists(resource_dir):
                raise NameError('Invalid resource directory!')

        self.resource_directory = resource_dir
Пример #2
0
def start_jvm(jvm_args=DEFAULT_JVM_ARGS,
              jvm_properties=DEFAULT_JVM_PROPERTIES,
              java_home: str = os.environ.get('JAVA_HOME', None),
              classpath=[],
              propfile: str = None,
              devroot: str = '.',
              workspace: str = '.',
              config=None):
    """ This function uses the default DH property file to embed the Deephaven server and starts a Deephaven Python
    Script session. """

    if propfile is None:
        propfile = 'dh-defaults.prop'

    # Build jvm system properties starting with defaults we accept as args
    system_properties = {
        'devroot': os.path.realpath(devroot),
        'workspace': workspace,
        'Configuration.rootFile': propfile,
    }
    # Append user-created args, allowing them to override these values
    system_properties.update(jvm_properties)

    # Build the classpath and expand wildcards, if any
    jvm_classpath = [os.path.join(os.path.dirname(__file__), 'jars', '*.jar')]
    jvm_classpath.extend(classpath)
    jvm_classpath = _expandWildcardsInList(jvm_classpath)

    # Append args that, if missing, could cause the jvm to be misconfigured for deephaven and its dependencies
    # TODO make these less required (i.e. at your own risk, remove them)
    REQUIRED_JVM_ARGS = [
        # Allow netty to access java.nio.Buffer fields
        '--add-opens=java.base/java.nio=ALL-UNNAMED',
        # Allow our hotspotImpl project to access internals
        '--add-opens=java.management/sun.management=ALL-UNNAMED',
    ]
    if (jvm_args is None):
        jvm_args = REQUIRED_JVM_ARGS
    else:
        jvm_args.extend(REQUIRED_JVM_ARGS)

    jpyutil.init_jvm(
        java_home=java_home,
        # jvm_dll=jvm_dll,
        jvm_classpath=jvm_classpath,
        jvm_properties=system_properties,
        jvm_options=jvm_args,
        # config_file=config_file,
        config=config)
    import jpy
    jpy.VerboseExceptions.enabled = True
Пример #3
0
import threading
import unittest
import jpyutil

jpyutil.init_jvm(jvm_maxmem='512M')
import jpy


class MyThread(threading.Thread):
    def __init__(self, value):
        threading.Thread.__init__(self)
        Integer = jpy.get_type('java.lang.Integer')
        self.intObj = Integer(value)

    def run(self):
        # perform some operation on the local object using a new thread
        self.intValue = self.intObj.intValue()


class TestMultipleThreads(unittest.TestCase):
    def test_multi_thread_access(self):

        t1 = MyThread(123)
        t2 = MyThread(234)
        t3 = MyThread(345)
        t4 = MyThread(456)

        t1.start()
        t2.start()
        t3.start()
        t4.start()
Пример #4
0
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# END_COPYRIGHT

from timer import Timer

import jpyutil
jvm = jpyutil.init_jvm(jvm_maxmem='48M')

import jpy

N = 256
z = '\xff' * N * 1024
with Timer() as t:
    bz = bytearray(z) # view string as bytearray
    a = jpy.array('byte', bz)  # project this to a java array
    ba = bytearray(a) # bring it back to a python bytearray
print "=> round trip for size %sKB: %ss [%s KB/sec]" % (N, t.secs, N/t.secs)



Пример #5
0
import unittest
import array
import sys

import jpyutil


jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=['target/test-classes'])
import jpy

try:
    import numpy as np
except:
    np = None


def annotate_fixture_methods(type, method):
    # print('annotate_fixture_methods: type =', type, ', method =', method.name)
    if method.name == 'modifyThing':
        method.set_param_mutable(0, True)
    elif method.name == 'returnThing':
        method.set_param_return(0, True)
    elif method.name == 'modifyAndReturnThing':
        method.set_param_mutable(0, True)
        method.set_param_return(0, True)
    elif method.name == 'modifyIntArray':
        method.set_param_mutable(0, True)
    elif method.name == 'returnIntArray':
        method.set_param_return(0, False)
        method.set_param_return(0, True)
    elif method.name == 'modifyAndReturnIntArray':
Пример #6
0
import unittest
import time
import random
import jpyutil
jpyutil.init_jvm(jvm_maxmem='512M')
import jpy


class TestPerformance(unittest.TestCase):

    def test_general_rt_perf(self):

        Integer = jpy.get_type('java.lang.Integer')
        String = jpy.get_type('java.lang.String')
        File = jpy.get_type('java.io.File')
        HashMap = jpy.get_type('java.util.HashMap')

        # 1 million
        N = 1000000

        indexes = list(range(N))
        random.shuffle(indexes)

        t0 = time.time()
        pairs = [(Integer(index), File('path')) for index in indexes]
        t1 = time.time()
        print('Integer + File object instantiation took', t1-t0, 's for', N, 'calls, this is', 1000*(t1-t0)/N, 'ms per call')

        map = HashMap()

        t0 = time.time()
Пример #7
0
#
# Copyright (c) 2016-2021 Deephaven Data Labs and Patent Pending
#

# add JDK to path (otherwise jnius gives DLL load error)
import os
os.environ['PATH'] = os.environ['PATH'] + ";C:\\Program Files\\Java\jdk1.8.0_72\\jre\\bin\\server"
os.environ['PATH'] = os.environ['PATH'] + ";C:\\Program Files\\Java\jdk1.8.0_60\\jre\\bin\\server"
print(os.environ['PATH'])


import jpyutil
jpyutil.init_jvm()
# jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=['target/test-classes'])

import jpy

Stack = jpy.get_type('java.util.Stack')
stack = Stack()
stack.push('hello')
stack.push('world')

print(stack.pop()) # --> 'world'
print(stack.pop()) # --> 'hello'

print(stack.getClass().getName())

Пример #8
0
 def setUpClass(cls):
   jpyutil.init_jvm()
Пример #9
0
def start_jvm(
        devroot=None,
        workspace=None,
        propfile=None,
        keyfile=None,
        verbose=False,
        skip_default_classpath=None,
        # The following are the jpyutil.init_jvm options which are passed through after attaching our options
        java_home=None,
        jvm_dll=None,
        jvm_maxmem=None,
        jvm_classpath=None,
        jvm_properties=None,
        jvm_options=None,
        config_file=None,
        config=None):
    """
    Starts a JVM within this Python process to interface with Deephaven.

    This is a small convenience wrapper around :func:`jpyutil.init_jvm`. Additionally, the Configuration is loaded
    and and Deephaven classes are brought into Python.

    :param devroot: the devroot parameter for Deephaven. Defaults to the ``ILLUMON_DEVROOT`` environment variable, or
      ``/usr/deephaven/latest``
    :param workspace: the workspace parameter for Deephaven. Defaults to the ``ILLUMON_WORKSPACE`` environment variable
    :param propfile: the ``Configuration.rootFile`` parameter for Deephaven. Defaults to the ``ILLUMON_PROPFILE`` environment
      variable
    :param keyfile: your private key file for authenticating to Deephaven
    :param skip_default_classpath: if True, do not attempt to compute default java classpath
    :param verbose: if True, print out the classpath and properties we have constructed

    The rest of the parameters are passed through to :func:`jpyutil.init_jvm`. The values for `jvm_classpath` and
    `jvm_properties` may have been modified based on the values of other arguments.

    :param java_home: The Java JRE or JDK home directory used to search JVM shared library, if 'jvm_dll' is omitted.
    :param jvm_dll: The JVM shared library file. My be inferred from 'java_home'.
    :param jvm_maxmem: The JVM maximum heap space, e.g. '400M', '8G'. Refer to the java executable '-Xmx' option.
    :param jvm_classpath: optional initial classpath elements. Default elements will be appended unless
      `skip_default_classpath` is specified
    :param jvm_properties: inserted into the dictionary generated by `devroot`, `workspace`, `propfile`, and `keyfile`.
    :param jvm_options: A list of extra options for the JVM. Refer to the java executable options.
    :param config_file: Extra configuration file (e.g. 'jpyconfig.py') to be loaded if 'config' parameter is omitted.
    :param config: An optional default configuration object providing default attributes
                   for the 'jvm_maxmem', 'jvm_classpath', 'jvm_properties', 'jvm_options' parameters.
    """

    # setup defaults

    for stem in ['DEEPHAVEN']:
        if devroot is None:
            devroot = os.environ.get("{}_DEVROOT".format(stem), None)
        if workspace is None:
            workspace = os.environ.get("{}_WORKSPACE".format(stem), None)
        if propfile is None:
            propfile = os.environ.get("{}_PROPFILE".format(stem), None)

    # if we don't have a devroot and/or propfile yet, workers will have standard environment variables we can try
    if devroot is None:
        devroot = os.environ.get('DEVROOT', None)

    if propfile is None:
        propfile = os.environ.get('CONFIGFILE', None)

    # validate devroot & workspace
    if devroot is None:
        raise IOError("dh.init: devroot is not specified.")
    if not os.path.isdir(devroot):
        raise IOError("dh.init: devroot={} does not exist.".format(devroot))

    if workspace is None:
        raise IOError("dh.init: workspace is not specified.")
    if not os.path.isdir(workspace):
        raise IOError(
            "dh.init: workspace={} does not exist.".format(workspace))

    dtemp = workspace
    for entry in ['', 'cache', 'classes']:
        dtemp = os.path.join(dtemp, entry)
        if os.path.exists(dtemp):
            if not (os.path.isdir(dtemp)
                    and os.access(dtemp, os.W_OK | os.X_OK)):
                # this is silly, but a directory must be both writable and executible by a user for a
                # file to be written there - write without executible is delete only
                raise IOError(
                    "dh.init: workspace directory={} does exists, but is "
                    "not writeable by your user.".format(dtemp))
        else:
            # Log potentially helpful warning - in case of failure.
            warnings.warn(
                "dh.init: workspace directory={} does not exist, and its absence may "
                "lead to an error. When required, it SHOULD get created with appropriate "
                "permissions by the Deephaven class DynamicCompileUtils. If strange errors arise "
                "from jpy about inability to find some java class, then check "
                "the existence/permissions of the directory.".format(dtemp),
                RuntimeWarning)

    # setup environment
    expanded_devroot = _expandLinks(devroot)

    jProperties = {'devroot': expanded_devroot, 'workspace': workspace}
    if propfile is not None:
        jProperties['Configuration.rootFile'] = propfile
    if keyfile is not None:
        jProperties[
            'WAuthenticationClientManager.defaultPrivateKeyFile'] = keyfile
    if jvm_properties is not None:
        jProperties.update(jvm_properties)

    jClassPath = []
    # allow for string or array, because users get confused
    if jvm_classpath is not None:
        if _isStr(jvm_classpath):
            jClassPath.extend(jvm_classpath.split(os.path.pathsep))
        elif isinstance(jvm_classpath, list):
            jClassPath.extend(jvm_classpath)
        else:
            raise ValueError(
                "Invalid jvm_classpath type = {}. list or string accepted.".
                format(type(jvm_classpath)))

    defaultClasspath = None
    if not skip_default_classpath:
        defaultClasspath = _getDefaultClasspath(expanded_devroot, workspace)
        jClassPath.extend(defaultClasspath)

    jClassPath = _expandWildcardsInList(jClassPath)

    if verbose:
        print("JVM default classpath... {}".format(defaultClasspath))
        print("JVM classpath... {}".format(jClassPath))
        print("JVM properties... {}".format(jProperties))

    if jvm_options is None:
        jvm_options = set()

    if path.exists("/usr/deephaven/latest/etc/JAVA_VERSION"):
        java_version_file = open("/usr/deephaven/latest/etc/JAVA_VERSION", "r")
        java_version = java_version_file.read()
        java_version_file.close()
    elif path.exists(
            "{}/projects/configs/build/resources/main/JAVA_VERSION".format(
                devroot)):
        java_version_file = open(
            "{}/projects/configs/build/resources/main/JAVA_VERSION".format(
                devroot), "r")
        java_version = java_version_file.read()
        java_version_file.close()
    elif os.environ.get('JAVA_VERSION') is not None:
        java_version = os.environ.get('JAVA_VERSION')
    else:
        raise ValueError(
            'Cannot find JAVA_VERSION from environment variable or filesystem locations'
        )

    if not any(elem.startswith('--add-opens') for elem in jvm_options):
        if java_version == '11':
            jvm_options.add(
                '--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED')
        elif java_version == '13':
            jvm_options.add(
                '--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED')
            jvm_options.add(
                '--add-opens=java.base/jdk.internal.access=ALL-UNNAMED')

    if verbose:
        if len(jvm_options) > 0:
            print("JVM options... {}".format(jvm_options))

    jpy.VerboseExceptions.enabled = True
    jpyutil.init_jvm(java_home=java_home,
                     jvm_dll=jvm_dll,
                     jvm_maxmem=jvm_maxmem,
                     jvm_classpath=jClassPath,
                     jvm_properties=jProperties,
                     jvm_options=jvm_options,
                     config_file=config_file,
                     config=config)
    # Loads our configuration and initializes the class types
    initialize()
Пример #10
0
if __name__ != '__main__':
    quit()

import jpyutil
import jpy

print(jpy.has_jvm())
print(jpyutil.init_jvm())
print(jpy.has_jvm())

System = jpy.get_type('java.lang.System')
File = jpy.get_type('java.io.File')

classpath = System.getProperty('java.class.path')
separator = File.pathSeparator
classpathEntries = classpath.split(separator)
for entry in classpathEntries:
    print(entry)
Пример #11
0
}

# A boolean that decides whether module names are prepended to all object names (for object types where a “module” of some kind is defined), e.g. for py:function directives. Default is True.
add_module_names = False
# if we allow sphinx to generate type hints for signatures (default), it would make the generated doc cluttered and hard to read
autodoc_typehints = 'none'

#########################################################################################################################################################################

# Turn on jpy so the modern deephaven API can reference Java types.
# The Deephaven wheel can't be used without the JVM running and the
# server classpath being present, so we must at least set this much
# up.
from glob import glob
import os
import jpyutil
jpyutil.init_jvm(jvm_classpath=glob(os.environ.get('DEEPHAVEN_CLASSPATH')),
                 jvm_properties={
                     'Configuration.rootFile':
                     os.environ.get('DEEPHAVEN_PROPFILE')
                 })

import deephaven
import jpy
docs_title = "Deephaven python modules."
package_roots = [jpy, deephaven]
package_excludes = ['._']

import dh_sphinx
dh_sphinx.gen_sphinx_modules(docs_title, package_roots, package_excludes)
Пример #12
0
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
EXAMPLES_DIR = os.path.dirname(SCRIPT_DIR)
#
# Locate jasperstarter.jar when installed, or in a development tree.
#
LIBS = os.path.join(os.path.dirname(EXAMPLES_DIR), 'lib')
if not os.path.isdir(LIBS):
    LIBS = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(EXAMPLES_DIR))), 'target',
                        'jasperstarter-dev-bin', 'lib')
CLASSPATH = os.path.join(LIBS, 'jasperstarter.jar')
assert(os.path.exists(CLASSPATH)), 'Unable to find jasperstarter in {0}'.format(LIBS)
#
# Load the JVM. See the jpy docs for details.
#
import jpyutil
jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=[CLASSPATH])
#
# Load the Java types needed.
#
import jpy
Arrays = jpy.get_type('java.util.Arrays')
File = jpy.get_type('java.io.File')
Report = jpy.get_type('de.cenote.jasperstarter.Report')
Config = jpy.get_type('de.cenote.jasperstarter.Config')
DsType = jpy.get_type('de.cenote.jasperstarter.types.DsType')
System = jpy.get_type('java.lang.System')
PrintStream = jpy.get_type('java.io.PrintStream')
ByteArrayInputStream = jpy.get_type('java.io.ByteArrayInputStream')
ByteArrayOutputStream = jpy.get_type('java.io.ByteArrayOutputStream')

Пример #13
0
def start_jvm(jvm_props: Dict[str, str] = None):
    """ This function uses the default DH property file to embed the Deephaven server and starts a Deephaven Python
    Script session. """
    if not jpy.has_jvm():

        # we will try to initialize the jvm
        workspace = os.environ.get('DEEPHAVEN_WORKSPACE', '.')
        devroot = os.environ.get('DEEPHAVEN_DEVROOT', '.')
        propfile = os.environ.get('DEEPHAVEN_PROPFILE', 'dh-defaults.prop')

        # validate devroot & workspace
        if devroot is None:
            raise IOError("dh.init: devroot is not specified.")
        if not os.path.isdir(devroot):
            raise IOError(
                "dh.init: devroot={} does not exist.".format(devroot))

        if workspace is None:
            raise IOError("dh.init: workspace is not specified.")
        if not os.path.isdir(workspace):
            raise IOError(
                "dh.init: workspace={} does not exist.".format(workspace))

        dtemp = workspace
        for entry in ['', 'cache', 'classes']:
            dtemp = os.path.join(dtemp, entry)
            if os.path.exists(dtemp):
                if not (os.path.isdir(dtemp)
                        and os.access(dtemp, os.W_OK | os.X_OK)):
                    # this is silly, but a directory must be both writable and executible by a user for a
                    # file to be written there - write without executible is delete only
                    raise IOError(
                        "dh.init: workspace directory={} does exists, but is "
                        "not writeable by your user.".format(dtemp))
            else:
                # Log potentially helpful warning - in case of failure.
                warnings.warn(
                    "dh.init: workspace directory={} does not exist, and its absence may "
                    "lead to an error. When required, it SHOULD get created with appropriate "
                    "permissions by the Deephaven class DynamicCompileUtils. If strange errors arise "
                    "from jpy about inability to find some java class, then check "
                    "the existence/permissions of the directory.".format(
                        dtemp), RuntimeWarning)

        jvm_properties = {
            'PyObject.cleanup_on_thread': 'false',
            'java.awt.headless': 'true',
            'MetricsManager.enabled': 'true',
            'Configuration.rootFile': propfile,
            'devroot': os.path.realpath(devroot),
            'workspace': os.path.realpath(workspace),
        }

        if jvm_props:
            jvm_properties.update(jvm_props)

        jvm_options = {
            '-XX:+UseG1GC',
            '-XX:MaxGCPauseMillis=100',
            '-XX:+UseStringDeduplication',
            '-XX:InitialRAMPercentage=25.0',
            '-XX:MinRAMPercentage=70.0',
            '-XX:MaxRAMPercentage=80.0',
            '--add-opens=java.base/java.nio=ALL-UNNAMED',
        }
        jvm_classpath = os.environ.get('DEEPHAVEN_CLASSPATH', '')

        # Start up the JVM
        jpy.VerboseExceptions.enabled = True
        jpyutil.init_jvm(jvm_classpath=_expandWildcardsInList(
            jvm_classpath.split(os.path.pathsep)),
                         jvm_properties=jvm_properties,
                         jvm_options=jvm_options)

        # Set up a Deephaven Python session
        py_scope_jpy = jpy.get_type(
            "io.deephaven.engine.util.PythonScopeJpyImpl").ofMainGlobals()
        py_dh_session = jpy.get_type(
            "io.deephaven.engine.util.PythonDeephavenSession")(py_scope_jpy)
        jpy.get_type("io.deephaven.engine.table.lang.QueryScope").setScope(
            py_dh_session.newQueryScope())
Пример #14
0
import sys

sys.path.append('/home/andr/work/jpy/build/lib.linux-x86_64-3.5')

import jpy
import jpyutil

jpyutil.init_jvm(jvm_maxmem='512M',
                 jvm_classpath=['/home/andr/work/jpy/testClasses'])

FileInputStream = jpy.get_type('java.io.FileInputStream')
InputStreamReader = jpy.get_type('java.io.InputStreamReader')
BufferedReader = jpy.get_type('java.io.BufferedReader')
File = jpy.get_type('java.io.File')
FileReader = jpy.get_type('java.io.FileReader')
String = jpy.get_type('java.lang.String')
System = jpy.get_type('java.lang.System')

f = File('test_java.txt')

fin = BufferedReader(FileReader(f))

for i in range(4):
    stringLine = String(fin.readLine())
    System.out.println(stringLine)
Пример #15
0
# Copyright 2009-2015 CRS4.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# END_COPYRIGHT

from timer import Timer

import jpyutil
jvm = jpyutil.init_jvm(jvm_maxmem='48M')

import jpy

N = 256
z = '\xff' * N * 1024
with Timer() as t:
    bz = bytearray(z)  # view string as bytearray
    a = jpy.array('byte', bz)  # project this to a java array
    ba = bytearray(a)  # bring it back to a python bytearray
print "=> round trip for size %sKB: %ss [%s KB/sec]" % (N, t.secs, N/t.secs)
Пример #16
0
def jvm_init(devroot=None,
             workspace=None,
             propfile=None,
             userHome=None,
             keyfile=None,
             librarypath=None,
             log4jconffile=None,
             workerHeapGB=12,
             jvmHeapGB=2,
             jvmOptions=None,
             verbose=False):
    """
    Initialize the JVM to run Deephaven.

    :param devroot: for Deephaven Java installation - must include trailing path separator
    :param workspace: Java workspace directory
    :param propfile: Deephaven Java propfile
    :param userHome: User's home directory
    :param keyfile: path to private key file for Deephaven user authentication
    :param librarypath: Java library path
    :param log4jconffile: Log4j config file
    :param workerHeapGB: desired worker heap in GB
    :param jvmHeapGB: Desired jvm heap in GB
    :param jvmOptions: optional jvm options
    :param verbose: enable / disable verbose output

    .. note:: for clarity, the `userHome` parameter should be provided. If not, it resolves to the home directory of
        user determined by environment variable ``USER`` or ``USERNAME``. If neither of those is set, it resolves to
        the home directory of ``~``. These resolutions are performed using :func:`os.path.expanduser`.
    """

    # setup defaults
    for stem in ['DEEPHAVEN', 'ILLUMON']:
        if devroot is None:
            devroot = os.environ.get("{}_DEVROOT".format(stem), None)
        if workspace is None:
            workspace = os.environ.get("{}_WORKSPACE".format(stem), None)
        if propfile is None:
            propfile = os.environ.get("{}_PROPFILE".format(stem), None)

    if not os.path.isdir(devroot):
        raise Exception("idb.init: devroot={} does not exist.".format(devroot))
    if not os.path.isdir(workspace):
        os.makedirs(workspace)
        if verbose:
            print("idb.init: Creating workspace folder {}".format(workspace))

    username = None
    if userHome is None:
        for val in ['USER', 'USERNAME']:
            if username is None:
                username = os.environ.get(val, None)
        userhome1 = "W:/home/{}/".format(
            username
        )  # addressed in IDS-759, and defunct except for Genesis...
        if os.path.exists(userhome1):
            userHome = userhome1
        elif username is not None:
            userHome = os.path.expanduser('~' + username)
        else:
            userHome = os.path.expanduser('~')

        if userHome[0] == '~':
            # NB: this expansion could fail, and will just leave these unchanged...what would I do?
            userHome = None
    if (userHome is not None) and (userHome[-1] != '/'):
        userHome += "/"
    if verbose:
        print("idb.init: userHome = {}".format(userHome))

    if keyfile is None and username is not None:
        keyfile1 = os.path.join(userHome,
                                'priv-{}.base64.txt'.format(username))
        if os.path.exists(keyfile1):
            keyfile = keyfile1
    if not os.path.isfile(keyfile):
        raise Exception("idb.init: keyfile={} does not exist.".format(keyfile))

    if log4jconffile is None and userHome is not None:
        log4jconffile = os.path.join(userHome, "log4j.xml")

    # setup environment
    jProperties = {
        'workspace':
        workspace,
        'Configuration.rootFile':
        propfile,
        'devroot':
        devroot,
        'disable.jvmstatus':
        'true',
        'RemoteProcessingRequest.defaultQueryHeapMB':
        '{}'.format(workerHeapGB * 1024),
        'useLongClientDelayThreshold':
        'true',
        'WAuthenticationClientManager.defaultPrivateKeyFile':
        keyfile
    }

    if librarypath is not None:
        jProperties['java.library.path'] = librarypath

    if os.path.isfile(log4jconffile):
        jProperties['log4j.configuration'] = 'file:{}'.format(log4jconffile)

    if verbose:
        print("JVM properties...\n{}".format(jProperties))

    jClassPath = [
        os.path.join(devroot, el) for el in [
            'etc', 'Common/config', 'configs', 'build/classes/main',
            'build/resources/main'
        ]
    ]

    jClassPath.extend(glob("{}/*/build/classes/main".format(devroot)))

    for root, dirs, files in os.walk(os.path.join(devroot, 'lib')):
        for f in files:
            if f.endswith(".jar"):
                fname = os.path.join(root, f)
                logging.info("JAR {}".format(fname))
                jClassPath.append(fname)

    for root, dirs, files in os.walk(os.path.join(devroot, "build", "jars")):
        for f in files:
            if f.endswith(".jar"):
                fname = os.path.join(root, f)
                logging.info("JAR {}".format(fname))
                jClassPath.append(fname)

    if verbose:
        print("JVM classpath...{}".format(jClassPath))

    jpy.VerboseExceptions.enabled = True

    jvm_options = []
    if jvmOptions is None:
        pass
    elif isinstance(jvmOptions, str):
        jvm_options = jvmOptions.strip().split()
    elif isinstance(jvmOptions, list):
        jvm_options = jvmOptions
    if verbose and len(jvm_options) > 0:
        print("JVM Options...{}".format(jvm_options))

    jpyutil.init_jvm(jvm_maxmem='{}m'.format(jvmHeapGB * 1024),
                     jvm_properties=jProperties,
                     jvm_classpath=jClassPath,
                     jvm_options=jvm_options)
    # Loads our configuration and initializes the class types
    initialize()
Пример #17
0
# This file was modified by Illumon.
import unittest

import jpyutil

jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=['target/test-classes'])
import jpy


class TestConstructorOverloads(unittest.TestCase):
    def setUp(self):
        self.Fixture = jpy.get_type(
            'org.jpy.fixtures.ConstructorOverloadTestFixture')
        self.assertIsNotNone(self.Fixture)

    def test_FloatConstructors(self):
        fixture = self.Fixture()
        self.assertEqual(fixture.getState(), '')

        fixture = self.Fixture(12)
        self.assertEqual(fixture.getState(), 'Integer(12)')

        fixture = self.Fixture(12, 34)
        self.assertEqual(fixture.getState(), 'Integer(12),Integer(34)')

        fixture = self.Fixture(0.12)
        self.assertEqual(fixture.getState(), 'Float(0.12)')

        fixture = self.Fixture(0.12, 0.34)
        self.assertEqual(fixture.getState(), 'Float(0.12),Float(0.34)')
Пример #18
0
import sys, os
# os.environ["GLOG_minloglevel"] = "4"
os.environ["GLOG_minloglevel"] = "2"
sys.path.insert(0, '/usr/local/jpy')
import caffe    # extract feature
import mtcnn    # detect facial points
import jpy, jpyutil # java python bridge
import json         # configs loader
import numpy as np  # image container 
import skimage.io   # image reader
from skimage import transform as tf # align: affine transform
from numpy import linalg as la  # linear transformation
from sklearn.externals import joblib   # load pca model

jpyutil.init_jvm(jvm_maxmem='256M')
FloatArray = jpy.get_type('[F')

"""
Details of MTcnn from c++ explosion
python module: mtcnn
 + set_device(int)  # set gpu id used for detection
 * MTcnn(str)       # handle face detection with given model_dir
   * factor      float  read write 0.709 
   * minSize     int    read write 40
   * threshold   list   read write [0.5, 0.6, 0.6]
   + detect(np)  list   detected face information
"""

"""
Wrapper for instantiation of FACE in Java