You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2016/06/16 14:55:10 UTC
[1/2] tinkerpop git commit: Implemented a gremlin-python code
processor for the docs.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1278 8d2de3f6a -> e348a9532
Implemented a gremlin-python code processor for the docs.
This closes #1328
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e16ef673
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e16ef673
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e16ef673
Branch: refs/heads/TINKERPOP-1278
Commit: e16ef6736b7dfdd55b9e73b3e7dc93e4a042fbc8
Parents: 8d2de3f
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu Jun 16 16:51:04 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Thu Jun 16 16:51:04 2016 +0200
----------------------------------------------------------------------
.gitignore | 1 +
docs/preprocessor/awk/init-code-blocks.awk | 64 ++++++++++++++++++++++-
docs/preprocessor/awk/language-variants.awk | 49 +++++++++++++++++
docs/preprocessor/preprocess-file.sh | 8 +--
docs/src/reference/gremlin-variants.asciidoc | 19 +++++--
5 files changed, 132 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e16ef673/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 11ca63e..498cb31 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ doc/out
docs/*.asciidoc
ext/
benchmarks/
+*$py.class
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e16ef673/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 9f02f02..fde246b 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -49,10 +49,72 @@ BEGIN {
print "f = new File('/tmp/tinkergraph.kryo')"
print "if (f.exists()) f.deleteDir()"
print ":set max-iteration 100"
+ if (lang == "python") {
+ print "import org.apache.tinkerpop.gremlin.python.PythonTranslator"
+ print "import javax.script.ScriptEngineManager"
+ print "import javax.script.SimpleBindings"
+ print "def downloadFile(String url, final String localPath) {"
+ print " def f = new File(localPath)"
+ print " while (!f.exists() && url) {"
+ print " url.toURL().openConnection().with { def conn ->"
+ print " conn.instanceFollowRedirects = false"
+ print " url = conn.getHeaderField('Location')"
+ print " if (!url) {"
+ print " f.withOutputStream { def output ->"
+ print " conn.inputStream.with { def input ->"
+ print " output << input"
+ print " input.close()"
+ print " }"
+ print " }"
+ print " }"
+ print " }"
+ print " }"
+ print " return f"
+ print "}"
+ pythonVersion = "2.7.0"
+ print "pathToLocalJar = System.getProperty('java.io.tmpdir') + File.separator + 'jython-standalone-" pythonVersion ".jar'"
+ print "jarDownloadUrl = 'http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/" pythonVersion "/jython-standalone-" pythonVersion ".jar'"
+ print "loader = new URLClassLoader(downloadFile(jarDownloadUrl, pathToLocalJar).toURI().toURL())"
+ print "jython = new ScriptEngineManager(loader).getEngineByName('jython')"
+ print "jython.eval('import sys')"
+ print "jython.eval('sys.path.append(\"" TP_HOME "/gremlin-variant/src/main/jython/gremlin_python\")')"
+ print "jython.eval('sys.path.append(\"" TP_HOME "/gremlin-variant/src/main/jython/gremlin_driver\")')"
+ print "jython.eval('sys.path.append(\"" TP_HOME "/gremlin-variant/src/main/jython/gremlin_rest_driver\")')"
+ print "jython.eval('from gremlin_python import *')"
+ #print "jython.eval('from gremlin_rest_driver import RESTRemoteConnection')"
+ print "jython.eval('from groovy_translator import GroovyTranslator')"
+ print "jython.eval('for k in statics:\\n globals()[k] = statics[k]')"
+ print "jythonBindings = new SimpleBindings()"
+ print "jythonBindings.put('g', jython.eval('PythonGraphTraversalSource(GroovyTranslator(\"g\"))'))"
+ print "jython.getContext().setBindings(jythonBindings, javax.script.ScriptContext.GLOBAL_SCOPE)"
+ print "sharedData = new Binding()"
+ print "sharedData.setProperty('g', g)"
+ print "sharedData.setProperty('__', __)"
+ print "sharedData.setProperty('T', T)"
+ print "sharedData.setProperty('Order', Order)"
+ print "sharedData.setProperty('Column', Column)"
+ print "sharedData.setProperty('Direction', Direction)"
+ print "sharedData.setProperty('Operator', Operator)"
+ print "sharedData.setProperty('P', P)"
+ print "sharedData.setProperty('Pop', Pop)"
+ print "sharedData.setProperty('Scope', Scope)"
+ print "shell = new GroovyShell(sharedData)"
+ }
print "'-IGNORE'"
}
-!/^pb\([0-9]*\); '\[gremlin-/ { print }
+!/^pb\([0-9]*\); '\[gremlin-/ {
+ if (delimiter == 2 && !($0 ~ /^pb\([0-9]*\); '----'/)) {
+ switch (lang) {
+ case "python":
+ print "shell.evaluate jython.eval(\"\"\"" $0 "\"\"\").toString()"
+ break
+ default:
+ print
+ break
+ }
+ } else print
+}
/^pb\([0-9]*\); '----'/ {
if (delimiter == 1) delimiter = 2
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e16ef673/docs/preprocessor/awk/language-variants.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/language-variants.awk b/docs/preprocessor/awk/language-variants.awk
new file mode 100644
index 0000000..e89d057
--- /dev/null
+++ b/docs/preprocessor/awk/language-variants.awk
@@ -0,0 +1,49 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#
+# @author Daniel Kuppitz (http://gremlin.guru)
+#
+BEGIN {
+ lang = null
+ inCodeBlock = 0
+}
+
+/^\[source,/ {
+ delimiter = 1
+ split($0, a, ",")
+ lang = gensub(/]$/, "", 1, a[2])
+}
+
+/^----$/ {
+ if (inCodeBlock == 0) inCodeBlock = 1
+ else inCodeBlock = 0
+}
+
+{ if (inCodeBlock) {
+ switch (lang) {
+ case "python":
+ gsub(/^gremlin>/, ">>>")
+ gsub(/^==>/, "")
+ print gensub(/shell.evaluate jython.eval\("""(.*)"""\).toString\(\)/, "\\1", 1)
+ break
+ default:
+ print
+ break
+ }
+ } else print
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e16ef673/docs/preprocessor/preprocess-file.sh
----------------------------------------------------------------------
diff --git a/docs/preprocessor/preprocess-file.sh b/docs/preprocessor/preprocess-file.sh
index 35b1f15..0035402 100755
--- a/docs/preprocessor/preprocess-file.sh
+++ b/docs/preprocessor/preprocess-file.sh
@@ -113,11 +113,13 @@ 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 |
- 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 |
+ awk -f ${AWK_SCRIPTS}/init-code-blocks.awk -v TP_HOME="${TP_HOME}" |
+ 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 |
${lb} awk -f ${AWK_SCRIPTS}/prettify.awk |
- ${lb} awk -f ${AWK_SCRIPTS}/cleanup.awk > ${output}
+ ${lb} awk -f ${AWK_SCRIPTS}/cleanup.awk |
+ ${lb} awk -f ${AWK_SCRIPTS}/language-variants.awk > ${output}
ps=(${PIPESTATUS[@]})
for i in {0..6}; do
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e16ef673/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 7135089..2ea9afd 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -118,8 +118,10 @@ from gremlin_python import P
These can be used analagously to how they are used in Gremlin-Java.
-[source,python]
+[gremlin-python,modern]
+----
g.V().hasLabel('person').has('age',P.gt(30)).order().by('age',Order.decr)
+----
Moreover, by importing the `statics` of Gremlin-Python, the class prefixes can be removed.
@@ -130,13 +132,17 @@ for k in statics:
With statics, loaded its possible to represent the above traversal as below.
-[source,python]
+[gremlin-python,modern]
+----
g.V().hasLabel('person').has('age',gt(30)).order().by('age',decr)
+----
Moreover, statics includes all the `__`-methods and thus, anonymous traversals like `__.out()` can be expressed as below.
-[source,python]
-g.V().repeat(out()).times(2).name.toList()
+[gremlin-python,modern]
+----
+g.V().repeat(out()).times(2).name.fold()
+----
Gremlin-Python Sugar
~~~~~~~~~~~~~~~~~~~~
@@ -144,7 +150,10 @@ Gremlin-Python Sugar
Python supports meta-programming and operator overloading. There are three uses of these techniques in Gremlin-Python that
makes traversals a bit more succinct.
-[source,python]
+[gremlin-python,modern]
+----
g.V().both()[1:3]
g.V().both()[1]
g.V().both().name
+----
+
[2/2] tinkerpop git commit: WARNING: Added a dependency to
`gremlin-variants` in `gremlin-console`. This should be removed before this
branch gets merged into `master/`. The proper way is to provide a plugin for
Gremlin variants.
Posted by dk...@apache.org.
WARNING: Added a dependency to `gremlin-variants` in `gremlin-console`. This should be removed before this branch gets merged into `master/`.
The proper way is to provide a plugin 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/e348a953
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e348a953
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e348a953
Branch: refs/heads/TINKERPOP-1278
Commit: e348a95329c7626bd1aaa882fe771d8166082924
Parents: e16ef67
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu Jun 16 16:52:39 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Thu Jun 16 16:52:39 2016 +0200
----------------------------------------------------------------------
gremlin-console/pom.xml | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e348a953/gremlin-console/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-console/pom.xml b/gremlin-console/pom.xml
index 98cccb0..1dc45ed 100644
--- a/gremlin-console/pom.xml
+++ b/gremlin-console/pom.xml
@@ -37,6 +37,11 @@ limitations under the License.
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tinkerpop</groupId>
+ <artifactId>gremlin-variant</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>