You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Marko A. Rodriguez (JIRA)" <ji...@apache.org> on 2016/06/07 16:12:20 UTC

[jira] [Updated] (TINKERPOP-1328) Provide [gremlin-python] as an code executor in docs

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

Marko A. Rodriguez updated TINKERPOP-1328:
------------------------------------------
    Summary: Provide [gremlin-python] as an code executor in docs  (was: Provide [source,gremlin-python] as an code executor in docs)

> 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
>             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-jython,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)