Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.2.0-incubating
-
None
Description
We currently support [gremlin-groovy] and [gremlin-groovy,modern]-style code block annotations. It would be good to also support [gremlin-python] and [gremlin-python,modern]. Likewise, ensure a generalization for the future when gremlin-ruby and gremlin-php are added.
Gremlin-Python source can be evaluated using Groovy and the Jython ScriptEngine. Suppose the following code block:
[gremlin-python,modern] g.V().out().name
GROOVY
First, assume the following startup code that should be evaluated once and only once into the Gremlin-Groovy script engine.
import javax.script.ScriptEngineManager import javax.script.SimpleBindings loader = new URLClassLoader(new File("/Applications/jython-2.7.0/jython.jar").toURI().toURL()) // JYTHON_PATH is better jython = new ScriptEngineManager(loader).getEngineByName("jython") jython.eval("import sys"); jython.eval("sys.path.append('/Users/marko/software/tinkerpop/gremlin-variant/src/main/jython/gremlin_python')"); // PYTHON_PATH is better jython.eval("from gremlin_python import *"); jythonBindings = new SimpleBindings(); jythonBindings.put("g", jython.eval("PythonGraphTraversalSource('g')")); jython.getContext().setBindings(jythonBindings, javax.script.ScriptContext.GLOBAL_SCOPE);
The above requires that a global variable exist to where Jython is installed as well as to where Gremlin-Python is installed. Though, for the latter, you will simply be able to use pip to install dynamically (PYTHON_PATH) is set to the location of Gremlin-Python.
From there, the code block above would be evaluated as:
g = TinkerGraphFactory.createModern().traversal() Eval.me("g", g, jython.eval("g.V().out().name").toString())
This looks as follow:
gremlin> g = TinkerFactory.createModern().traversal() ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> Eval.me("g", g, jython.eval("g.V().out().name").toString()) ==>lop ==>vadas ==>josh ==>ripple ==>lop ==>lop
And thats that...
Attachments
Issue Links
- is related to
-
TINKERPOP-1278 Implement Gremlin-Python and general purpose language variant test infrastructure
- Closed