[ 
https://issues.apache.org/jira/browse/TINKERPOP-1328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Kuppitz closed TINKERPOP-1328.
-------------------------------------
    Resolution: Fixed

Done in branch {{TINKERPOP-1278}} in commit 
[e16ef67|https://github.com/apache/tinkerpop/commit/e16ef6736b7dfdd55b9e73b3e7dc93e4a042fbc8].

> Provide [gremlin-python] as an code executor in docs
> ----------------------------------------------------
>
>                 Key: TINKERPOP-1328
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1328
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: documentation
>    Affects Versions: 3.2.0-incubating
>            Reporter: Marko A. Rodriguez
>            Assignee: Daniel Kuppitz
>             Fix For: 3.2.1
>
>
> 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:
> {code}
> [gremlin-python,modern]
> g.V().out().name
> {code}
> *GROOVY*
> First, assume the following startup code that should be evaluated once and 
> only once into the Gremlin-Groovy script engine.
> {code}
> 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);
> {code}
> *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:
> {code}
> g = TinkerGraphFactory.createModern().traversal()
> Eval.me("g", g, jython.eval("g.V().out().name").toString())
> {code}
> This looks as follow:
> {code}
> 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
> {code}
> And thats that...



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to