Skip to content

Commit

Permalink
Simplify ScriptSession dependencies (#4190)
Browse files Browse the repository at this point in the history
This removes the only python init script, and removes an unused groovy
init script. The config variables are left in place for now, though
they will default to blank.

One slightly unexpected change that this results in is that the jpy,
sys, and os modules are no longer imported by default into a python
script session - this probably should be considered a feature, but
does need to be documented.

Partial #4040
  • Loading branch information
niloc132 committed Sep 20, 2023
1 parent 9405627 commit bf579e0
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 127 deletions.
17 changes: 0 additions & 17 deletions engine/table/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ plugins {

description 'Engine Table: Implementation and closely-coupled utilities'

sourceSets {
main {
resources {
srcDir 'groovy'
include 'core/*.groovy'
}
resources {
srcDir 'python'
include 'core/*.py'
}
resources {
srcDir 'src/main/resources'
include '**'
}
}
}

configurations {
// Ensure jmh picks up the same dependencies as tests
jmhImplementation.extendsFrom testImplementation
Expand Down
85 changes: 0 additions & 85 deletions engine/table/groovy/core/deephaven_core_utils.groovy

This file was deleted.

18 changes: 0 additions & 18 deletions engine/table/python/core/deephaven_jpy_init.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ private static void markReadyAndCheckEnv() {
try (
final PyModule deephavenJpyModule = PyModule.importModule("deephaven_internal.jvm");
final PyObject readyObj = deephavenJpyModule.callMethod("ready");
final PyObject checkObj = deephavenJpyModule.callMethod("check_py_env")) {
final PyObject checkObj = deephavenJpyModule.callMethod("check_py_env");
final PyObject initObj = deephavenJpyModule.callMethod("init_py")) {
// empty
}
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions props/configs/src/main/resources/dh-defaults.prop
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ QueryPerformanceRecorder.packageFilter.internal=defaultPackageFilters.qpr

########## Deephaven Groovy and Python Session defaults ##########

GroovyDeephavenSession.initScripts=core/deephaven_core_utils.groovy
GroovyDeephavenSession.initScripts=

PythonDeephavenSession.initScripts=core/deephaven_jpy_init.py
PythonDeephavenSession.initScripts=

default.processEnvironmentFactory=io.deephaven.util.process.DefaultProcessEnvironment$Factory

Expand Down
4 changes: 2 additions & 2 deletions props/test-configs/src/main/resources/dh-tests.prop
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ QueryPerformanceRecorder.packageFilter.internal=defaultPackageFilters.qpr

########## Deephaven Groovy and Python Session defaults ##########

GroovyDeephavenSession.initScripts=core/deephaven_core_utils.groovy
GroovyDeephavenSession.initScripts=

PythonDeephavenSession.initScripts=core/deephaven_jpy_init.py
PythonDeephavenSession.initScripts=

###### Measurement Options ######
statsdriver.enabled=false
Expand Down
22 changes: 22 additions & 0 deletions py/server/deephaven_internal/jvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ def init_jvm(*args, **kwargs):
"Unable to initialize JVM, try setting the environment variable JAVA_HOME (JDK 11+ required)") from e
ready()
return result

def init_py():
"""Finishes starting Python to be usable from inside of a Java process. Not intended to be called in cases
where the process was started as Python, and Java was started from inside Python.
"""

import jpy
import os
import sys
from deephaven_internal.stream import TeeStream

# Set stdin to /dev/null to prevent functions (like help()) that attempt to read from stdin from hanging python
# execution from within Java.
os.dup2(os.open("/dev/null", os.O_RDONLY), 0)

jpy.VerboseExceptions.enabled = True
# If you want jpy to tell you about all that it is doing, change this
# jpy.diag.flags = jpy.diag.F_ALL

j_sys = jpy.get_type('java.lang.System')
sys.stdout = TeeStream.redirect(sys.stdout, j_sys.out)
sys.stderr = TeeStream.redirect(sys.stderr, j_sys.err)
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public enum WorkerPythonEnvironment {
.getStringWithDefault("WorkerPythonEnvironment.defaultScriptPath", ".");

final ScriptFinder scriptFinder = new ScriptFinder(defaultScriptPath);
final String initScript = Configuration.getInstance().getStringWithDefault("WorkerPythonEnvironment.initScript",
"core/deephaven_jpy_init.py");
final String initScript =
Configuration.getInstance().getStringWithDefault("WorkerPythonEnvironment.initScript", "");

final ScriptFinder.FileOrStream file;
try {
Expand Down

0 comments on commit bf579e0

Please sign in to comment.