You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/08/16 22:19:40 UTC

tinkerpop git commit: docs are building. wow...I spent all day in awk hell. the big solution os.chdir() ... dah. Docs looks beautiful for gremlin-variants.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 85e15f7c5 -> 640d4ccc7


docs are building. wow...I spent all day in awk hell. the big solution os.chdir() ... dah. Docs looks beautiful for gremlin-variants.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/640d4ccc
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/640d4ccc
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/640d4ccc

Branch: refs/heads/TINKERPOP-1278
Commit: 640d4ccc7bcd986d37eecb6ff505c7b0e6ff4442
Parents: 85e15f7
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Aug 16 16:19:33 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Aug 16 16:19:33 2016 -0600

----------------------------------------------------------------------
 docs/preprocessor/awk/init-code-blocks.awk      | 22 ++++++++++--------
 docs/preprocessor/awk/language-variants.awk     |  2 +-
 docs/preprocessor/install-plugins.sh            |  4 +++-
 docs/preprocessor/preprocess-file.sh            |  2 +-
 docs/src/reference/gremlin-variants.asciidoc    | 24 ++++++++------------
 .../GremlinJythonScriptEngineFactory.java       | 13 ++++++-----
 6 files changed, 34 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/640d4ccc/docs/preprocessor/awk/init-code-blocks.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/init-code-blocks.awk b/docs/preprocessor/awk/init-code-blocks.awk
index 24da9d5..67f116c 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -50,23 +50,22 @@ BEGIN {
   print "if (f.exists()) f.deleteDir()"
   print ":set max-iteration 100"
   if (lang == "python") {
-    print "import org.apache.tinkerpop.gremlin.python.jsr223.PythonTranslator"
-    print "import javax.script.ScriptEngineManager"
-    print "import javax.script.SimpleBindings"
+    print "import static javax.script.ScriptContext.*"
     print "jython = new org.apache.tinkerpop.gremlin.python.jsr223.GremlinJythonScriptEngine()"
+    print "jython.eval('import os')"
+    print "jython.eval('os.chdir(\"" TP_HOME "\")')"
     print "jython.eval('import sys')"
-    # print "jython.eval('sys.path.append(\"" PYTHONPATH "\")')"
+    print "jython.eval('sys.path.append(\"" PYTHONPATH "\")')"
     print "jython.eval('sys.path.append(\"" TP_HOME "/gremlin-python/target/test-classes/Lib\")')"
-    # print "jython.eval('sys.path.append(\"/Users/marko/software/tinkerpop/gremlin-python/target/test-classes/Lib\")')"
     print "jython.eval('from gremlin_python import statics')"
     print "jython.eval('from gremlin_python.process.traversal import *')"
     print "jython.eval('from gremlin_python.process.graph_traversal import GraphTraversal')"
     print "jython.eval('from gremlin_python.process.graph_traversal import GraphTraversalSource')"
     print "jython.eval('from gremlin_python.process.graph_traversal import __')"
-    # print "jython.eval('from gremlin_python.driver.websocket_remote_connection import WebSocketRemoteConnection')"
     print "jython.eval('from gremlin_python.structure.remote_graph import RemoteGraph')"
     print "jython.eval('from gremlin_python.process.graphson import GraphSONWriter')"
-    print "jython.eval('from gremlin_python.process.graphson import serializers')"
+    # print "jython.eval('from gremlin_python.process.graphson import serializers')"
+    # print "jython.eval('from gremlin_python.driver.websocket_remote_connection import WebSocketRemoteConnection')"
     print "jython.eval('statics.load_statics(globals())')"
     print "jythonBindings = jython.createBindings()"
     print "jythonBindings.put('g', jython.eval('RemoteGraph(None).traversal()'))"
@@ -76,6 +75,11 @@ BEGIN {
     print "groovyBindings.put('g', g)"
     print "groovyBindings.put('TinkerGraphComputer', TinkerGraphComputer)"
     print "groovy.getContext().setBindings(groovyBindings, javax.script.ScriptContext.GLOBAL_SCOPE)"
+    print "def processTraversal(t, jython, groovy) {"
+    print "  jython.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval(t))"
+    print "  groovy.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval('GraphSONWriter.writeObject(j)').toString())"
+    print "  return groovy.eval(groovy.eval('GroovyTranslator.of(\"g\").translate(GraphSONReader.build().create().mapper.readValue(j,Bytecode.class))').toString())"
+    print "}"
   }
   print "'-IGNORE'"
 }
@@ -84,9 +88,7 @@ BEGIN {
   if (delimiter == 2 && !($0 ~ /^pb\([0-9]*\); '----'/)) {
     switch (lang) {
       case "python":
-        print "jython.getContext().getBindings(javax.script.ScriptContext.GLOBAL_SCOPE).put('j',\"\"\"" gensub("\\('id',([0-9]+)\\)", "\\1", "g") "\"\"\")"
-        print "groovy.getContext().getBindings(javax.script.ScriptContext.GLOBAL_SCOPE).put('j', jython.eval('GraphSONWriter.writeObject(j)').toString())"
-        print "groovy.eval(groovy.eval('GroovyTranslator.of(\"g\").translate(GraphSONReader.build().create().mapper.readValue(j,Bytecode.class))').toString())"
+        print "processTraversal(\"\"\"" gensub("\\('id',([0-9]+)\\)", "\\1", "g") "\"\"\", jython, groovy)"
         break
       default:
         print

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/640d4ccc/docs/preprocessor/awk/language-variants.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/language-variants.awk b/docs/preprocessor/awk/language-variants.awk
index 9f9a6ee..5429070 100644
--- a/docs/preprocessor/awk/language-variants.awk
+++ b/docs/preprocessor/awk/language-variants.awk
@@ -39,7 +39,7 @@ BEGIN {
       case "python":
         gsub(/^gremlin>/, ">>>")
         gsub(/^==>/, "")
-        $0 = gensub(/groovy.eval jython.eval\("""(.*)"""\).toString\(\)/, "\\1", 1)
+        $0 = gensub(/processTraversal\("""(.*)"""\, jython, groovy)/, "\\1", 1)
         print gensub("g\\.V\\(([^\\)]+)", "g.V(('id',\\1)", "g")
         break
       default:

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/640d4ccc/docs/preprocessor/install-plugins.sh
----------------------------------------------------------------------
diff --git a/docs/preprocessor/install-plugins.sh b/docs/preprocessor/install-plugins.sh
index 8411f37..2737ccb 100755
--- a/docs/preprocessor/install-plugins.sh
+++ b/docs/preprocessor/install-plugins.sh
@@ -50,7 +50,9 @@ while [ ${i} -lt ${pluginsCount} ]; do
   fi
   ((i++))
 done
-echo ":install org.apache.tinkerpop gremlin-python ${TP_VERSION}" >> ${INSTALL_FILE}
+
+echo "installPlugin(new Artifact(\"org.apache.tinkerpop\", \"gremlin-python\", \"${TP_VERSION}\"))" >> ${INSTALL_FILE}
+echo "gremlin-python" >> ${TMP_DIR}/plugins.dir
 
 echo "System.exit(0)" >> ${INSTALL_FILE}
 echo -ne " * tinkerpop-sugar ... "

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/640d4ccc/docs/preprocessor/preprocess-file.sh
----------------------------------------------------------------------
diff --git a/docs/preprocessor/preprocess-file.sh b/docs/preprocessor/preprocess-file.sh
index 7a9833f..978c7ca 100755
--- a/docs/preprocessor/preprocess-file.sh
+++ b/docs/preprocessor/preprocess-file.sh
@@ -120,7 +120,7 @@ if [ ! ${SKIP} ] && [ $(grep -c '^\[gremlin' ${input}) -gt 0 ]; then
   fi
 
   awk -f ${AWK_SCRIPTS}/prepare.awk ${input} |
-  awk -f ${AWK_SCRIPTS}/init-code-blocks.awk -v TP_HOME="${TP_HOME}" PYTHONPATH="${PYTHONPATH}" |
+  awk -f ${AWK_SCRIPTS}/init-code-blocks.awk -v TP_HOME="${TP_HOME}" PYTHONPATH="." |
   awk -f ${AWK_SCRIPTS}/progressbar.awk -v tpl=${AWK_SCRIPTS}/progressbar.groovy.template |
   HADOOP_GREMLIN_LIBS="${CONSOLE_HOME}/ext/giraph-gremlin/lib:${CONSOLE_HOME}/ext/tinkergraph-gremlin/lib" bin/gremlin.sh |
   ${lb} awk -f ${AWK_SCRIPTS}/ignore.awk   |

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/640d4ccc/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index c05f343..5c49d7b 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -54,7 +54,6 @@ prefixes `_` in front of these terms for their use with graph traversal. For ins
 To install Gremlin-Python, simply use Python's link:https://en.wikipedia.org/wiki/Pip_(package_manager)[pip] package manager.
 
 [source,bash]
-pip install requests
 pip install gremlin_python
 
 There are three primary classes distributed with Gremlin-Python: `GraphTraversalSource`, `GraphTraversal`, and `__`.
@@ -100,7 +99,6 @@ Within the CPython console, it is possible to evaluate the following.
 [source,python]
 graph = RemoteGraph(WebSocketsRemoteConnection('ws://localhost:8182','g'))
 g = graph.traversal()
-g.V().repeat(__.out()).times(2).name.toList()
 
 When the traversal above is submitted to the `RemoteConnection`, it's `Bytecode` is sent in order to construct the equivalent traversal
 in GremlinServer (thus, remotely). The bytecode is analyzed to determine which language the bytecode should be translated to.
@@ -177,8 +175,8 @@ In Gremlin-Python, bindings are 2-tuples and used as follows.
 
 [gremlin-python,modern]
 ----
-g.V(('x',1)).out('created').name
-g.V(('x',4)).out('created').name
+g.V(('id',1)).out('created').name
+g.V(('id',4)).out('created').name
 ----
 
 The Lambda Solution
@@ -193,18 +191,16 @@ such that the remote connection host can infer which translator to use.
 
 [gremlin-python,modern]
 ----
-g.V().out().map(lambda: ("it.get().value('name').length()", "gremlin-groovy")).sum() <2>
+g.V().out().map(lambda: ("it.get().value('name').length()", "gremlin-groovy")).sum()
 ----
 
-todo: put below back into above.
+A zero-arg lambda can yield a 2-tuple with the first element being the lambda script and second element being the lambda language.
+If the zero-arg lambda yields a string representation of a lambda (not a 2-tuple), then the language is assumed to be Gremlin-Jython.
+
+To change the default lambda language, update `gremlin_python.statics.default_lambda_language`.
 
 [source,python]
-g.V().out().map(lambda: "lambda x: x.get().value('name').length()").sum() <1>
-gremlin_python.statics.default_lambda_language = "gremlin-groovy" <3>
-g.V().out().map(lambda: "it.get().value('name').length()").sum() <4>
-
-<1> A zero-arg lambda yields a string representation of a lambda in Gremlin-Jython.
-<2> A zero-arg lambda can yield a 2-tuple with the second element being the lambda language.
-<3> The default lambda language can be changed so a 2-tuple is no needed.
-<4> A zero-arg lambda yields a string representation of a closure in Gremlin-Groovy.
+g.V().out().map(lambda: "lambda x: x.get().value('name').length()").sum()
+gremlin_python.statics.default_lambda_language = "gremlin-groovy"
+g.V().out().map(lambda: "it.get().value('name').length()").sum()
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/640d4ccc/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
index 8ecbcd4..c94e94f 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineFactory.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.util.Gremlin;
 import org.python.jsr223.PyScriptEngineFactory;
 
 import javax.script.ScriptEngine;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -34,8 +35,8 @@ import java.util.List;
  */
 public class GremlinJythonScriptEngineFactory extends PyScriptEngineFactory implements GremlinScriptEngineFactory {
 
-    private static final String ENGINE_NAME = "gremlin-jython";
-    private static final String LANGUAGE_NAME = "gremlin-jython";
+    private static final String GREMLIN_JYTHON = "gremlin-jython";
+    private static final String GREMLIN_PYTHON = "gremlin-python";
     private static final String PLAIN = "plain";
     private static final List<String> EXTENSIONS = Collections.singletonList("py");
 
@@ -48,7 +49,7 @@ public class GremlinJythonScriptEngineFactory extends PyScriptEngineFactory impl
 
     @Override
     public String getEngineName() {
-        return ENGINE_NAME;
+        return GREMLIN_JYTHON;
     }
 
     @Override
@@ -63,7 +64,7 @@ public class GremlinJythonScriptEngineFactory extends PyScriptEngineFactory impl
 
     @Override
     public String getLanguageName() {
-        return LANGUAGE_NAME;
+        return GREMLIN_JYTHON;
     }
 
     @Override
@@ -78,7 +79,7 @@ public class GremlinJythonScriptEngineFactory extends PyScriptEngineFactory impl
 
     @Override
     public List<String> getNames() {
-        return Collections.singletonList(LANGUAGE_NAME);
+        return Arrays.asList(GREMLIN_JYTHON, GREMLIN_PYTHON);
     }
 
     @Override
@@ -88,7 +89,7 @@ public class GremlinJythonScriptEngineFactory extends PyScriptEngineFactory impl
         } else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
             return this.getEngineVersion();
         } else if (key.equals(ScriptEngine.NAME)) {
-            return ENGINE_NAME;
+            return GREMLIN_JYTHON;
         } else if (key.equals(ScriptEngine.LANGUAGE)) {
             return this.getLanguageName();
         } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {