Skip to content

Commit

Permalink
feat: Expose Python/Groovy version to clients (#5970)
Browse files Browse the repository at this point in the history
* Sets `groovy.version` configuration property, as sourced from class
`groovy.lang.GroovyShell`.
* Sets `python.version` configuration property, as sourced from python
code `platform.python_version()`
* Adds `groovy.version` and `python.version` to
`client.configuration.list` in dh-defaults.prop (to be returned to
client as part of `ConfigService.GetConfigurationConstants` gRPC)
* Adds `io.deephaven.client.examples.PrintConfigurationConstants` to
invoke and print out results of
`ConfigService.GetConfigurationConstants`

Fixes #5938
  • Loading branch information
devinrsmith authored Aug 22, 2024
1 parent 7b13def commit 6521382
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,25 @@ public class PythonDeephavenSession extends AbstractScriptSession<PythonSnapshot
private static final String DEFAULT_SCRIPT_PATH = Configuration.getInstance()
.getStringWithDefault("PythonDeephavenSession.defaultScriptPath", ".");

/**
* This is following the convention set by io.deephaven.server.config.ConfigServiceGrpcImpl / dh-defaults.prop of
* relaying version information to the client via Configuration properties.
*/
private static final String PYTHON_VERSION_PROPERTY = "python.version";

public static String SCRIPT_TYPE = "Python";

private static void setPythonVersion(Configuration configuration) {
final String pythonVersion;
try (final PyModule platformModule = PyModule.importModule("platform")) {
pythonVersion = platformModule.call(String.class, "python_version", new Class[0], new Object[0]);
} catch (RuntimeException e) {
log.warn(e).append("Unable to retrieve python version").endl();
return;
}
configuration.setProperty(PYTHON_VERSION_PROPERTY, pythonVersion);
}

private final PythonEvaluator evaluator;
private final PythonScope<PyObject> scope;
private final PythonScriptSessionModule module;
Expand All @@ -67,6 +84,10 @@ public class PythonDeephavenSession extends AbstractScriptSession<PythonSnapshot
/**
* Create a Python ScriptSession.
*
* <p>
* Sets the configuration property {@value PYTHON_VERSION_PROPERTY} to the value returned from the python code
* {@code platform.python_version()}.
*
* @param updateGraph the default update graph to install for the repl
* @param operationInitializer the default operation initializer to install for the repl
* @param objectTypeLookup the object type lookup
Expand Down Expand Up @@ -96,16 +117,19 @@ public PythonDeephavenSession(

registerJavaExecutor(threadInitializationFactory);
publishInitial();

final Configuration configuration = Configuration.getInstance();
/*
* And now the user-defined initialization scripts, if any.
*/
if (runInitScripts) {
String[] scripts = Configuration.getInstance().getProperty("PythonDeephavenSession.initScripts").split(",");
String[] scripts = configuration.getProperty("PythonDeephavenSession.initScripts").split(",");

for (String script : scripts) {
runScript(script);
}
}
setPythonVersion(configuration);
}

/**
Expand Down
1 change: 1 addition & 0 deletions java-client/session-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ application.applicationDistribution.into('bin') {
from(createApplication('message-stream-send-receive', 'io.deephaven.client.examples.MessageStreamSendReceive'))
from(createApplication('filter-table', 'io.deephaven.client.examples.FilterTable'))
from(createApplication('create-shared-id', 'io.deephaven.client.examples.CreateSharedId'))
from(createApplication('print-configuration-constants', 'io.deephaven.client.examples.PrintConfigurationConstants'))

fileMode = 0755
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.client.examples;

import io.deephaven.client.impl.Session;
import io.deephaven.proto.backplane.grpc.ConfigValue;
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.util.Map.Entry;

@Command(name = "print-configuration-constants", mixinStandardHelpOptions = true,
description = "Print configuration constants", version = "0.1.0")
class PrintConfigurationConstants extends SingleSessionExampleBase {

@Override
protected void execute(Session session) throws Exception {
for (Entry<String, ConfigValue> entry : session.getConfigurationConstants().get().entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue().getStringValue());
}
}

public static void main(String[] args) {
int execute = new CommandLine(new PrintConfigurationConstants()).execute(args);
System.exit(execute);
}
}
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 @@ -62,9 +62,9 @@ web.webgl.editable=true
authentication.client.configuration.list=AuthHandlers

# List of configuration properties to provide to authenticated clients, so they can interact with the server.
client.configuration.list=java.version,deephaven.version,barrage.version,http.session.durationMs,file.separator,web.storage.layout.directory,web.storage.notebook.directory,web.webgl,web.webgl.editable
client.configuration.list=java.version,deephaven.version,barrage.version,groovy.version,python.version,http.session.durationMs,file.separator,web.storage.layout.directory,web.storage.notebook.directory,web.webgl,web.webgl.editable

# Version list to add to the configuration property list. Each `=`-delimited pair denotes a short name for a versioned
# jar, and a class that is found in that jar. Any such keys will be made available to the client.configuration.list
# as <key>.version.
client.version.list=deephaven=io.deephaven.engine.table.Table,barrage=io.deephaven.barrage.flatbuf.BarrageMessageWrapper
client.version.list=deephaven=io.deephaven.engine.table.Table,barrage=io.deephaven.barrage.flatbuf.BarrageMessageWrapper,groovy=groovy.lang.GroovyShell

0 comments on commit 6521382

Please sign in to comment.