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/06/22 20:50:21 UTC
[4/6] tinkerpop git commit: removed gremlin-variants/ and created
gremlin-python. Reorganized lots of things given new insights. A few sucky
things to work out. Need @spmallette help -- packaging,
testing issues. Really cool stuff.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonBypassTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonBypassTranslator.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonBypassTranslator.java
new file mode 100644
index 0000000..0bbde96
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonBypassTranslator.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.util.Translator;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+class PythonBypassTranslator extends PythonTranslator {
+
+ private PythonBypassTranslator(final String alias, final boolean importStatics) {
+ super(alias, importStatics);
+ }
+
+ public static PythonBypassTranslator of(final String alias) {
+ return new PythonBypassTranslator(alias, false);
+ }
+
+ public static PythonBypassTranslator of(final String alias, final boolean importStatics) {
+ return new PythonBypassTranslator(alias, importStatics);
+ }
+
+ @Override
+ public void addStep(final Traversal.Admin<?, ?> traversal, final String stepName, final Object... arguments) {
+ super.addStep(traversal, stepName, arguments);
+ if (!this.importStatics)
+ assert this.traversalScript.toString().startsWith(this.alias + ".");
+ }
+
+ @Override
+ public Translator getAnonymousTraversalTranslator() {
+ return new PythonBypassTranslator("__", this.importStatics);
+ }
+
+ @Override
+ public String getTargetLanguage() {
+ return "gremlin-groovy";
+ }
+
+ @Override
+ public String getTraversalScript() {
+ final String traversal = super.getTraversalScript();
+ if (!this.alias.equals("__")) {
+ try {
+ final ScriptEngine jythonEngine = ScriptEngineCache.get("gremlin-jython");
+ final Bindings jythonBindings = new SimpleBindings();
+ jythonBindings.put(this.alias, jythonEngine.eval("PythonGraphTraversalSource(GroovyTranslator(\"" + this.alias + "\"))"));
+ jythonEngine.getContext().setBindings(jythonBindings, ScriptContext.GLOBAL_SCOPE);
+ return jythonEngine.eval(traversal).toString();
+ } catch (final ScriptException e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ } else
+ return traversal;
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.translatorString(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorTest.java
new file mode 100644
index 0000000..adce9ee
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.python.jsr223.GremlinJythonScriptEngineSetup;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class PythonTranslatorTest {
+
+ static {
+ GremlinJythonScriptEngineSetup.setup();
+ }
+
+ @Test
+ public void shouldSupportStringSupplierLambdas() throws Exception {
+ final GraphTraversalSource g = TinkerFactory.createModern().traversal().withTranslator(PythonBypassTranslator.of("g", true));
+ GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1)
+ .V()
+ .filter(Lambda.predicate("lambda: \"it.get().label().equals('person')\""))
+ .flatMap(Lambda.<Traverser<Vertex>, Iterator<Vertex>>function("it.get().vertices(Direction.OUT)"))
+ .map(Lambda.<Traverser<Vertex>, Integer>function("it.get().value('name').length()"))
+ .sideEffect(Lambda.consumer("x -> x.sideEffects('lengthSum', x.<Integer>sideEffects('lengthSum') + x.get())"))
+ .order().by(Lambda.comparator("a,b -> a <=> b"))
+ .sack(Lambda.biFunction("lambda : \"a,b -> a + b\""))
+ .asAdmin();
+ final List<Integer> sacks = new ArrayList<>();
+ final List<Integer> lengths = new ArrayList<>();
+ while (t.hasNext()) {
+ final Traverser.Admin<Integer> traverser = t.getEndStep().next();
+ sacks.add(traverser.sack());
+ lengths.add(traverser.get());
+ }
+ assertFalse(t.hasNext());
+ //
+ assertEquals(6, lengths.size());
+ assertEquals(3, lengths.get(0).intValue());
+ assertEquals(3, lengths.get(1).intValue());
+ assertEquals(3, lengths.get(2).intValue());
+ assertEquals(4, lengths.get(3).intValue());
+ assertEquals(5, lengths.get(4).intValue());
+ assertEquals(6, lengths.get(5).intValue());
+ ///
+ assertEquals(6, sacks.size());
+ assertEquals(4, sacks.get(0).intValue());
+ assertEquals(4, sacks.get(1).intValue());
+ assertEquals(4, sacks.get(2).intValue());
+ assertEquals(5, sacks.get(3).intValue());
+ assertEquals(6, sacks.get(4).intValue());
+ assertEquals(7, sacks.get(5).intValue());
+ //
+ assertEquals(24, t.getSideEffects().<Number>get("lengthSum").intValue());
+ }
+
+ @Test
+ public void shouldHaveValidToString() {
+ assertEquals("translator[h:gremlin-java->gremlin-jython]", PythonTranslator.of("h").toString());
+ assertEquals("translator[h:gremlin-java->gremlin-groovy]", PythonBypassTranslator.of("h").toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorComputerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorComputerProvider.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorComputerProvider.java
new file mode 100644
index 0000000..6dcf40b
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorComputerProvider.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.GraphProvider;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@GraphProvider.Descriptor(computer = TinkerGraphComputer.class)
+public class TinkerGraphPythonTranslatorComputerProvider extends TinkerGraphPythonTranslatorProvider {
+
+ @Override
+ public GraphTraversalSource traversal(final Graph graph) {
+ return super.traversal(graph).withComputer();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessComputerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessComputerTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessComputerTest.java
new file mode 100644
index 0000000..2abf94a
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessComputerTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.process.ProcessComputerSuite;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(ProcessComputerSuite.class)
+@GraphProviderClass(provider = TinkerGraphPythonTranslatorComputerProvider.class, graph = TinkerGraph.class)
+public class TinkerGraphPythonTranslatorProcessComputerTest {
+
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessStandardTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessStandardTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessStandardTest.java
new file mode 100644
index 0000000..e393d88
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProcessStandardTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(ProcessStandardSuite.class)
+@GraphProviderClass(provider = TinkerGraphPythonTranslatorProvider.class, graph = TinkerGraph.class)
+public class TinkerGraphPythonTranslatorProcessStandardTest {
+
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProvider.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProvider.java
new file mode 100644
index 0000000..507b7c3
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/TinkerGraphPythonTranslatorProvider.java
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.AbstractGraphProvider;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest;
+import org.apache.tinkerpop.gremlin.python.jsr223.GremlinJythonScriptEngineSetup;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerEdge;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerElement;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphVariables;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerProperty;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertexProperty;
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+
+import javax.script.ScriptException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class TinkerGraphPythonTranslatorProvider extends AbstractGraphProvider {
+
+ private static final boolean IMPORT_STATICS = new Random().nextBoolean();
+
+ static {
+ GremlinJythonScriptEngineSetup.setup();
+ }
+
+ private static Set<String> SKIP_TESTS = new HashSet<>(Arrays.asList(
+ "testProfileStrategyCallback",
+ "testProfileStrategyCallbackSideEffect",
+ "g_withSideEffectXa_setX_V_both_name_storeXaX_capXaX",
+ "g_V_both_hasLabelXpersonX_order_byXage_decrX_name",
+ "g_VX1X_out_injectXv2X_name",
+ "shouldSupportGraphFilter",
+ "shouldNeverPropagateANoBulkTraverser",
+ "shouldNeverPropagateANullValuedTraverser",
+ "shouldTraversalResetProperly",
+ "shouldHidePartitionKeyForValues",
+ ProgramTest.Traversals.class.getCanonicalName(),
+ TraversalInterruptionTest.class.getCanonicalName(),
+ TraversalInterruptionComputerTest.class.getCanonicalName(),
+ ElementIdStrategyProcessTest.class.getCanonicalName()));
+
+ private static final Set<Class> IMPLEMENTATION = new HashSet<Class>() {{
+ add(TinkerEdge.class);
+ add(TinkerElement.class);
+ add(TinkerGraph.class);
+ add(TinkerGraphVariables.class);
+ add(TinkerProperty.class);
+ add(TinkerVertex.class);
+ add(TinkerVertexProperty.class);
+ }};
+
+ @Override
+ public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName,
+ final LoadGraphWith.GraphData loadGraphWith) {
+
+ final TinkerGraph.DefaultIdManager idManager = selectIdMakerFromGraphData(loadGraphWith);
+ final String idMaker = (idManager.equals(TinkerGraph.DefaultIdManager.ANY) ? selectIdMakerFromGraphData(loadGraphWith) : idManager).name();
+ return new HashMap<String, Object>() {{
+ put(Graph.GRAPH, TinkerGraph.class.getName());
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, idMaker);
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, idMaker);
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, idMaker);
+ put("skipTest", SKIP_TESTS.contains(testMethodName) || SKIP_TESTS.contains(test.getCanonicalName()));
+ if (loadGraphWith == LoadGraphWith.GraphData.CREW)
+ put(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name());
+ }};
+ }
+
+ @Override
+ public void clear(final Graph graph, final Configuration configuration) throws Exception {
+ if (graph != null) graph.close();
+ }
+
+ @Override
+ public Set<Class> getImplementations() {
+ return IMPLEMENTATION;
+ }
+
+ /**
+ * Test that load with specific graph data can be configured with a specific id manager as the data type to
+ * be used in the test for that graph is known.
+ */
+ protected TinkerGraph.DefaultIdManager selectIdMakerFromGraphData(final LoadGraphWith.GraphData loadGraphWith) {
+ if (null == loadGraphWith) return TinkerGraph.DefaultIdManager.ANY;
+ if (loadGraphWith.equals(LoadGraphWith.GraphData.CLASSIC))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.MODERN))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.CREW))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.GRATEFUL))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else
+ throw new IllegalStateException(String.format("Need to define a new %s for %s", TinkerGraph.IdManager.class.getName(), loadGraphWith.name()));
+ }
+
+ @Override
+ public GraphTraversalSource traversal(final Graph graph) {
+ if ((Boolean) graph.configuration().getProperty("skipTest"))
+ return graph.traversal();
+ //throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance());
+ else {
+ try {
+ if (IMPORT_STATICS)
+ ScriptEngineCache.get("gremlin-jython").eval("for k in statics:\n globals()[k] = statics[k]");
+ else
+ ScriptEngineCache.get("gremlin-jython").eval("for k in statics:\n if k in globals():\n del globals()[k]");
+ } catch (final ScriptException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ return graph.traversal().withTranslator(PythonBypassTranslator.of("g", IMPORT_STATICS)); // the bypass translator will ensure that gremlin-groovy is ultimately used
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
new file mode 100644
index 0000000..686c1bc
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.python.driver;
+
+import org.apache.tinkerpop.gremlin.python.jsr223.GremlinJythonScriptEngineSetup;
+import org.apache.tinkerpop.gremlin.server.GremlinServer;
+import org.apache.tinkerpop.gremlin.server.Settings;
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.SimpleBindings;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class RESTRemoteConnectionTest {
+
+ private final ScriptEngine jython = ScriptEngineCache.get("gremlin-jython");
+
+ @Before
+ public void setup() {
+ try {
+ GremlinJythonScriptEngineSetup.setup();
+ final Bindings jythonBindings = new SimpleBindings();
+ jythonBindings.put("g", jython.eval("PythonGraphTraversalSource(GroovyTranslator('g'), RESTRemoteConnection('http://localhost:8182'))"));
+ jython.getContext().setBindings(jythonBindings, ScriptContext.GLOBAL_SCOPE);
+ final GremlinServer server = new GremlinServer(Settings.read(RESTRemoteConnectionTest.class.getResourceAsStream("gremlin-server-rest-modern.yaml")));
+ server.start().join();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testRESTRemoteConnection() throws Exception {
+ final List<String> results = (List) jython.eval("g.V().repeat(__.out()).times(2).name.toList()");
+ assertEquals(2, results.size());
+ assertTrue(results.contains("lop"));
+ assertTrue(results.contains("ripple"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineSetup.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineSetup.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineSetup.java
new file mode 100644
index 0000000..9cb3270
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineSetup.java
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.python.jsr223;
+
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class GremlinJythonScriptEngineSetup {
+
+ private GremlinJythonScriptEngineSetup() {
+ }
+
+ public static void setup() {
+ try {
+ final ScriptEngine jythonEngine = ScriptEngineCache.get("gremlin-jython");
+ jythonEngine.eval("from gremlin_python.gremlin_python import *");
+ jythonEngine.eval("from gremlin_python.gremlin_python import __");
+ jythonEngine.eval("from gremlin_python.groovy_translator import GroovyTranslator");
+ jythonEngine.eval("from gremlin_rest_driver import RESTRemoteConnection");
+ } catch (final ScriptException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineTest.java
new file mode 100644
index 0000000..7582877
--- /dev/null
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngineTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.python.jsr223;
+
+import org.junit.Test;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class GremlinJythonScriptEngineTest {
+
+ @Test
+ public void shouldGetEngineByName() throws Exception {
+ final ScriptEngine engine = new ScriptEngineManager().getEngineByName("gremlin-jython");
+ assertNotNull(engine);
+ assertTrue(engine instanceof GremlinJythonScriptEngine);
+ assertTrue(engine.eval("Graph") instanceof Class);
+ assertEquals(3, engine.eval("1+2"));
+ }
+
+ @Test
+ public void shouldHaveStandardImports() throws Exception {
+ final ScriptEngine engine = new ScriptEngineManager().getEngineByName("gremlin-jython");
+ assertTrue(engine.eval("Graph") instanceof Class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/resources/META-INF/services/javax.script.ScriptEngineFactory
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/META-INF/services/javax.script.ScriptEngineFactory b/gremlin-python/src/test/resources/META-INF/services/javax.script.ScriptEngineFactory
new file mode 100644
index 0000000..92f4825
--- /dev/null
+++ b/gremlin-python/src/test/resources/META-INF/services/javax.script.ScriptEngineFactory
@@ -0,0 +1 @@
+org.apache.tinkerpop.gremlin.python.jsr223.GremlinJythonScriptEngineFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/resources/log4j-silent.properties
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/log4j-silent.properties b/gremlin-python/src/test/resources/log4j-silent.properties
new file mode 100644
index 0000000..1825bb0
--- /dev/null
+++ b/gremlin-python/src/test/resources/log4j-silent.properties
@@ -0,0 +1,23 @@
+# 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.
+
+# this file should always have logging set to OFF. it seems, however, that an appender of some sort is
+# required or else some logs throw error and use other log4j.properties files on the path.
+log4j.rootLogger=OFF, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/resources/log4j-test.properties
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/log4j-test.properties b/gremlin-python/src/test/resources/log4j-test.properties
new file mode 100644
index 0000000..79038b1
--- /dev/null
+++ b/gremlin-python/src/test/resources/log4j-test.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+log4j.rootLogger=WARN, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-rest-modern.yaml
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-rest-modern.yaml b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-rest-modern.yaml
new file mode 100644
index 0000000..3a54a0c
--- /dev/null
+++ b/gremlin-python/src/test/resources/org/apache/tinkerpop/gremlin/python/driver/gremlin-server-rest-modern.yaml
@@ -0,0 +1,45 @@
+# 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.
+
+host: localhost
+port: 8182
+threadPoolWorker: 1
+gremlinPool: 8
+scriptEvaluationTimeout: 30000
+channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
+graphs: {
+ graph: ../gremlin-server/conf/tinkergraph-empty.properties}
+plugins:
+ - tinkerpop.tinkergraph
+scriptEngines: {
+ gremlin-groovy: {
+ imports: [java.lang.Math],
+ staticImports: [java.lang.Math.PI],
+ scripts: [../gremlin-server/scripts/generate-modern.groovy]}}
+serializers:
+ - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json
+ - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json
+metrics: {
+ slf4jReporter: {enabled: true, interval: 180000}}
+strictTransactionManagement: false
+threadPoolBoss: 1
+maxInitialLineLength: 4096
+maxHeaderSize: 8192
+maxChunkSize: 8192
+maxContentLength: 65536
+maxAccumulationBufferComponents: 1024
+resultIterationBatchSize: 64
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorComputerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorComputerProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorComputerProvider.java
deleted file mode 100644
index 376ac16..0000000
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorComputerProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tinkerpop.gremlin.driver.remote;
-
-import org.apache.tinkerpop.gremlin.GraphProvider;
-import org.apache.tinkerpop.gremlin.process.computer.Computer;
-import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer;
-
-import java.util.Random;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-@GraphProvider.Descriptor(computer = TinkerGraphComputer.class)
-public class RemoteGraphTranslatorComputerProvider extends RemoteGraphTranslatorProvider {
-
- private final Random RANDOM = new Random();
-
- @Override
- public GraphTraversalSource traversal(final Graph graph) {
- assert graph instanceof RemoteGraph;
- final int state = RANDOM.nextInt(3);
- switch (state) {
- case 0:
- return super.traversal(graph).withComputer();
- case 1:
- return super.traversal(graph).withComputer(Computer.compute(TinkerGraphComputer.class));
- case 2:
- return super.traversal(graph).withComputer(Computer.compute(TinkerGraphComputer.class).workers(1));
- default:
- throw new IllegalStateException("This state should not have occurred: " + state);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorProvider.java
deleted file mode 100644
index 17d7328..0000000
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/RemoteGraphTranslatorProvider.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tinkerpop.gremlin.driver.remote;
-
-import org.apache.tinkerpop.gremlin.groovy.GroovyTranslator;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class RemoteGraphTranslatorProvider extends RemoteGraphProvider {
-
- @Override
- public GraphTraversalSource traversal(final Graph graph) {
- return graph.traversal().withTranslator(GroovyTranslator.of("g"));
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorComputerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorComputerProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorComputerProvider.java
new file mode 100644
index 0000000..9eae953
--- /dev/null
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorComputerProvider.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.GraphProvider;
+import org.apache.tinkerpop.gremlin.process.computer.Computer;
+import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer;
+
+import java.util.Random;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@GraphProvider.Descriptor(computer = TinkerGraphComputer.class)
+public class RemoteGraphGroovyTranslatorComputerProvider extends RemoteGraphGroovyTranslatorProvider {
+
+ private final Random RANDOM = new Random();
+
+ @Override
+ public GraphTraversalSource traversal(final Graph graph) {
+ assert graph instanceof RemoteGraph;
+ final int state = RANDOM.nextInt(3);
+ switch (state) {
+ case 0:
+ return super.traversal(graph).withComputer();
+ case 1:
+ return super.traversal(graph).withComputer(Computer.compute(TinkerGraphComputer.class));
+ case 2:
+ return super.traversal(graph).withComputer(Computer.compute(TinkerGraphComputer.class).workers(1));
+ default:
+ throw new IllegalStateException("This state should not have occurred: " + state);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessComputerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessComputerTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessComputerTest.java
new file mode 100644
index 0000000..a45ab2d
--- /dev/null
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessComputerTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.process.ProcessComputerSuite;
+import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(ProcessComputerSuite.class)
+@GraphProviderClass(provider = RemoteGraphGroovyTranslatorComputerProvider.class, graph = RemoteGraph.class)
+public class RemoteGraphGroovyTranslatorProcessComputerTest {
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessStandardTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessStandardTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessStandardTest.java
new file mode 100644
index 0000000..3c2365c
--- /dev/null
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProcessStandardTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite;
+import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(ProcessStandardSuite.class)
+@GraphProviderClass(provider = RemoteGraphGroovyTranslatorProvider.class, graph = RemoteGraph.class)
+public class RemoteGraphGroovyTranslatorProcessStandardTest {
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProvider.java
new file mode 100644
index 0000000..011d42e
--- /dev/null
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/java/translator/RemoteGraphGroovyTranslatorProvider.java
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+package org.apache.tinkerpop.gremlin.java.translator;
+
+import org.apache.tinkerpop.gremlin.driver.remote.RemoteGraphProvider;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class RemoteGraphGroovyTranslatorProvider extends RemoteGraphProvider {
+
+ @Override
+ public GraphTraversalSource traversal(final Graph graph) {
+ return graph.traversal().withTranslator(GroovyTranslator.of("g"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessComputerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessComputerTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessComputerTest.java
deleted file mode 100644
index c4d79c1..0000000
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessComputerTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tinkerpop.gremlin.remote.process;
-
-import org.apache.tinkerpop.gremlin.GraphProviderClass;
-import org.apache.tinkerpop.gremlin.driver.remote.RemoteGraphTranslatorComputerProvider;
-import org.apache.tinkerpop.gremlin.process.ProcessComputerSuite;
-import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
-import org.junit.runner.RunWith;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-@RunWith(ProcessComputerSuite.class)
-@GraphProviderClass(provider = RemoteGraphTranslatorComputerProvider.class, graph = RemoteGraph.class)
-public class RemoteGraphTranslatorProcessComputerTest {
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessStandardTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessStandardTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessStandardTest.java
deleted file mode 100644
index d3963c1..0000000
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/process/RemoteGraphTranslatorProcessStandardTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tinkerpop.gremlin.remote.process;
-
-import org.apache.tinkerpop.gremlin.GraphProviderClass;
-import org.apache.tinkerpop.gremlin.driver.remote.RemoteGraphTranslatorProvider;
-import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite;
-import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
-import org.junit.runner.RunWith;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-@RunWith(ProcessStandardSuite.class)
-@GraphProviderClass(provider = RemoteGraphTranslatorProvider.class, graph = RemoteGraph.class)
-public class RemoteGraphTranslatorProcessStandardTest {
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-variant/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-variant/pom.xml b/gremlin-variant/pom.xml
deleted file mode 100644
index 8380237..0000000
--- a/gremlin-variant/pom.xml
+++ /dev/null
@@ -1,334 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>tinkerpop</artifactId>
- <version>3.2.1-SNAPSHOT</version>
- </parent>
- <artifactId>gremlin-variant</artifactId>
- <name>Apache TinkerPop :: Gremlin Language Variant</name>
- <dependencies>
- <dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>gremlin-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy</artifactId>
- <version>${groovy.version}</version>
- <classifier>indy</classifier>
- </dependency>
- <dependency>
- <groupId>org.python</groupId>
- <artifactId>jython-standalone</artifactId>
- <version>2.7.1b2</version>
- </dependency>
- <!-- TESTING -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>tinkergraph-gremlin</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>gremlin-groovy</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>gremlin-groovy-test</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>gremlin-test</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>gremlin-server</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <directory>${basedir}/target</directory>
- <finalName>${project.artifactId}-${project.version}</finalName>
- <resources>
- <resource>
- <directory>${basedir}/src/main/resources
- </directory>
- </resource>
- </resources>
- <testResources>
- <testResource>
- <directory>${basedir}/src/test/resources
- </directory>
- </testResource>
- </testResources>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.2.1</version>
- <executions>
- <execution>
- <id>generatePython</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>java</goal>
- </goals>
- <configuration>
- <mainClass>org.apache.tinkerpop.gremlin.python.GenerateGremlinPython</mainClass>
- <arguments>
- <argument>${basedir}/src/main/jython/gremlin_python/gremlin_python.py</argument>
- </arguments>
- </configuration>
- </execution>
- <execution>
- <id>buildPython</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>exec</goal>
- </goals>
- <configuration>
- <executable>python</executable>
- <async>true</async>
- <workingDirectory>${basedir}/src/main/jython</workingDirectory>
- <commandlineArgs>setup.py build --build-lib ${project.build.testOutputDirectory}/Lib</commandlineArgs>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.gmavenplus</groupId>
- <artifactId>gmavenplus-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <goals>
- <goal>addSources</goal>
- <goal>addTestSources</goal>
- <goal>generateStubs</goal>
- <goal>compile</goal>
- <goal>testGenerateStubs</goal>
- <goal>testCompile</goal>
- <goal>removeStubs</goal>
- <goal>removeTestStubs</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <invokeDynamic>true</invokeDynamic>
- </configuration>
- </plugin>
- <plugin>
- <groupId>net.sf.mavenjython</groupId>
- <artifactId>jython-compile-maven-plugin</artifactId>
- <version>1.4</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>jython</goal>
- </goals>
- </execution>
- <execution>
- <id>pythonDependencies</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>jython</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
- <libraries>
- <param>aenum</param>
- <param>requests</param>
- </libraries>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemPropertyVariables>
- <python.home>${project.build.testOutputDirectory}</python.home>
- </systemPropertyVariables>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-clean-plugin</artifactId>
- <version>3.0.0</version>
- <executions>
- <execution>
- <goals>
- <goal>clean</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <filesets>
- <fileset>
- <directory>${basedir}/src/main/jython/gremlin_rest_driver</directory>
- <includes>
- <include>**/*.pyc</include>
- <include>**/*.class</include>
- </includes>
- <excludes>
- <exclude>**/*.py</exclude>
- </excludes>
- <followSymlinks>false</followSymlinks>
- </fileset>
- <fileset>
- <directory>${basedir}/src/main/jython/gremlin_driver</directory>
- <includes>
- <include>**/*.pyc</include>
- <include>**/*.class</include>
- </includes>
- <excludes>
- <exclude>**/*.py</exclude>
- </excludes>
- <followSymlinks>false</followSymlinks>
- </fileset>
- <fileset>
- <directory>${basedir}/src/main/jython/gremlin_python</directory>
- <includes>
- <include>**/*.pyc</include>
- <include>**/*.class</include>
- </includes>
- <excludes>
- <exclude>**/*.py</exclude>
- </excludes>
- <followSymlinks>false</followSymlinks>
- </fileset>
- </filesets>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <profiles>
- <!--
- Provides a way to deploy the gremlinpython GLV to pypi. Requires installation of pip/virtualenv. See the
- developer docs for more information on how to configure these settings to get this profile to work. The profile
- largely uses antrun to execute raw pip/twine/python commands against a copy of what's in the jython directory
- which is copied to target/py.
- -->
- <profile>
- <id>glv-python</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- <property>
- <name>glvPython</name>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <!-- copy files in jython directory to target/py and run virtual env to sandbox python -->
- <execution>
- <id>setup-py-env</id>
- <phase>generate-resources</phase>
- <configuration>
- <tasks>
- <mkdir dir="${project.build.directory}/py/env"/>
- <copy todir="${project.build.directory}/py">
- <fileset dir="src/main/jython"/>
- </copy>
- <exec dir="${project.build.directory}/py" executable="virtualenv" failonerror="true">
- <arg line="env"/>
- </exec>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- <!--
- build/package python source distribution and wheel archive. the version is bound to an
- environment variable that gets used in setup.py to dynamically construct a module
- __version__file
- -->
- <execution>
- <id>package-py</id>
- <phase>package</phase>
- <configuration>
- <tasks>
- <exec dir="${project.build.directory}/py" executable="env/bin/python" failonerror="true">
- <env key="VERSION" value="${project.version}"/>
- <arg line="setup.py sdist"/>
- </exec>
- <exec dir="${project.build.directory}/py" executable="env/bin/python" failonerror="true">
- <env key="VERSION" value="${project.version}"/>
- <arg line="setup.py bdist_wheel"/>
- </exec>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- <!-- deploy to pypi. assumes that ~/.pypirc is configured appropriately -->
-
- <execution>
- <id>deploy-py</id>
- <phase>deploy</phase>
- <configuration>
- <tasks>
- <exec dir="${project.build.directory}/py" executable="env/bin/pip" failonerror="true">
- <arg line="install twine"/>
- </exec>
- <exec dir="${project.build.directory}/py" executable="env/bin/twine" failonerror="true">
- <arg line="upload dist/* -r pypitest"/>
- </exec>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy b/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
deleted file mode 100644
index 9e79739..0000000
--- a/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tinkerpop.gremlin.python
-
-import org.apache.tinkerpop.gremlin.process.computer.Computer
-import org.apache.tinkerpop.gremlin.process.traversal.Operator
-import org.apache.tinkerpop.gremlin.process.traversal.Order
-import org.apache.tinkerpop.gremlin.process.traversal.P
-import org.apache.tinkerpop.gremlin.process.traversal.Pop
-import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions
-import org.apache.tinkerpop.gremlin.process.traversal.Scope
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy
-import org.apache.tinkerpop.gremlin.structure.Column
-import org.apache.tinkerpop.gremlin.structure.Direction
-import org.apache.tinkerpop.gremlin.structure.T
-import org.apache.tinkerpop.gremlin.structure.VertexProperty
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-class GremlinPythonGenerator {
-
- public static void create(final String gremlinPythonFile) {
-
- final StringBuilder pythonClass = new StringBuilder()
-
- pythonClass.append("""'''
-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.
-'''
-""")
-
- final Map<String, String> methodMap = [global: "_global", as: "_as", in: "_in", and: "_and", or: "_or", is: "_is", not: "_not", from: "_from"]
- .withDefault { it }
- final Map<String, String> invertedMethodMap = [:].withDefault { it };
- methodMap.entrySet().forEach { invertedMethodMap.put(it.value, it.key) }
- final List<Class<? extends Enum>> enumList = [VertexProperty.Cardinality, Column, Direction, Operator, Order, Pop, SackFunctions.Barrier, Scope, T]
-
- pythonClass.append("from collections import OrderedDict\n")
- pythonClass.append("from aenum import Enum\n")
- pythonClass.append("statics = OrderedDict()\n\n")
- pythonClass.append("""
-globalTranslator = None
-""").append("\n\n");
-
-//////////////////////////
-// GraphTraversalSource //
-//////////////////////////
- pythonClass.append(
- """class PythonGraphTraversalSource(object):
- def __init__(self, translator, remote_connection=None):
- global globalTranslator
- self.translator = translator
- globalTranslator = translator
- self.remote_connection = remote_connection
- def __repr__(self):
- return "graphtraversalsource[" + str(self.remote_connection) + ", " + self.translator.traversal_script + "]"
-""")
- GraphTraversalSource.getMethods()
- .findAll { !it.name.equals("clone") }
- .collect { it.name }
- .unique()
- .sort { a, b -> a <=> b }
- .each { method ->
- final Class<?> returnType = (GraphTraversalSource.getMethods() as Set).findAll {
- it.name.equals(method)
- }.collect {
- it.returnType
- }[0]
- if (null != returnType) {
- if (Traversal.isAssignableFrom(returnType)) {
- pythonClass.append(
- """ def ${method}(self, *args):
- traversal = PythonGraphTraversal(self.translator, self.remote_connection)
- traversal.translator.addSpawnStep(traversal, "${method}", *args)
- for arg in args:
- if isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
- self.bindings[arg[0]] = arg[1]
- elif isinstance(arg, RawExpression):
- self.bindings.update(arg.bindings)
- return traversal
-""")
- } else if (TraversalSource.isAssignableFrom(returnType)) {
- pythonClass.append(
- """ def ${method}(self, *args):
- source = PythonGraphTraversalSource(self.translator, self.remote_connection)
- source.translator.addSource(source, "${method}", *args)
- for arg in args:
- if isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
- self.bindings[arg[0]] = arg[1]
- elif isinstance(arg, RawExpression):
- self.bindings.update(arg.bindings)
- return source
-""")
- }
- }
- }
- pythonClass.append("\n\n")
-
-////////////////////
-// GraphTraversal //
-////////////////////
- pythonClass.append(
- """class PythonGraphTraversal(object):
- def __init__(self, translator, remote_connection=None):
- self.translator = translator
- self.remote_connection = remote_connection
- self.results = None
- self.last_traverser = None
- self.bindings = {}
- def __repr__(self):
- return self.translator.traversal_script
- def __getitem__(self,index):
- if isinstance(index,int):
- return self.range(index,index+1)
- elif isinstance(index,slice):
- return self.range(index.start,index.stop)
- else:
- raise TypeError("Index must be int or slice")
- def __getattr__(self,key):
- return self.values(key)
- def __iter__(self):
- return self
- def __next__(self):
- return self.next()
- def toList(self):
- return list(iter(self))
- def next(self):
- if self.results is None:
- self.results = self.remote_connection.submit(self.translator.target_language, self.translator.traversal_script, self.bindings)
- if self.last_traverser is None:
- self.last_traverser = next(self.results)
- object = self.last_traverser.object
- self.last_traverser.bulk = self.last_traverser.bulk - 1
- if self.last_traverser.bulk <= 0:
- self.last_traverser = None
- return object
-""")
- GraphTraversal.getMethods()
- .findAll { !it.name.equals("clone") }
- .collect { methodMap[it.name] }
- .unique()
- .sort { a, b -> a <=> b }
- .each { method ->
- final Class<?> returnType = (GraphTraversal.getMethods() as Set).findAll {
- it.name.equals(invertedMethodMap[method])
- }.collect { it.returnType }[0]
- if (null != returnType && Traversal.isAssignableFrom(returnType)) {
- pythonClass.append(
- """ def ${method}(self, *args):
- self.translator.addStep(self, "${method}", *args)
- for arg in args:
- if isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
- self.bindings[arg[0]] = arg[1]
- elif isinstance(arg, RawExpression):
- self.bindings.update(arg.bindings)
- return self
-""")
- }
- };
- pythonClass.append("\n\n")
-
-////////////////////////
-// AnonymousTraversal //
-////////////////////////
- pythonClass.append("class __(object):\n");
- __.getMethods()
- .findAll { Traversal.isAssignableFrom(it.returnType) }
- .collect { methodMap[it.name] }
- .unique()
- .sort { a, b -> a <=> b }
- .each { method ->
- pythonClass.append(
- """ @staticmethod
- def ${method}(*args):
- return PythonGraphTraversal(globalTranslator.getAnonymousTraversalTranslator()).${method}(*args)
-""")
- };
- pythonClass.append("\n\n")
-
- __.class.getMethods()
- .findAll { Traversal.class.isAssignableFrom(it.getReturnType()) }
- .findAll { !it.name.equals("__") && !it.name.equals("clone") }
- .collect { methodMap[it.name] }
- .unique()
- .sort { a, b -> a <=> b }
- .forEach {
- pythonClass.append("def ${it}(*args):\n").append(" return __.${it}(*args)\n\n")
- pythonClass.append("statics['${it}'] = ${it}\n")
- }
- pythonClass.append("\n\n")
-
-///////////
-// Enums //
-///////////
- for (final Class<? extends Enum> enumClass : enumList) {
- pythonClass.append("${enumClass.getSimpleName()} = Enum('${enumClass.getSimpleName()}', '");
- enumClass.getEnumConstants().each { value ->
- pythonClass.append("${methodMap[value.name()]} ");
- }
- pythonClass.deleteCharAt(pythonClass.length() - 1).append("')\n\n")
- enumClass.getEnumConstants().each { value ->
- pythonClass.append("statics['${methodMap[value.name()]}'] = ${value.getDeclaringClass().getSimpleName()}.${methodMap[value.name()]}\n");
- }
- pythonClass.append("\n");
- }
- //////////////
-
- pythonClass.append("""class RawExpression(object):
- def __init__(self, *args):
- self.bindings = dict()
- self.parts = [self._process_arg(arg) for arg in args]
-
- def _process_arg(self, arg):
- if isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
- self.bindings[arg[0]] = arg[1]
- return Raw(arg[0])
- else:
- return Raw(arg)
-""")
-
- pythonClass.append("\n")
- pythonClass.append("""class Raw(object):
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return str(self.value)
-""")
-
- pythonClass.append("\n")
-
- pythonClass.append("""class P(object):
- def __init__(self, operator, value, other=None):
- self.operator = operator
- self.value = value
- self.other = other
-""")
- P.getMethods()
- .findAll { P.class.isAssignableFrom(it.returnType) }
- .findAll { !it.name.equals("or") && !it.name.equals("and") && !it.name.equals("clone") }
- .collect { methodMap[it.name] }
- .unique()
- .sort { a, b -> a <=> b }
- .each { method ->
- pythonClass.append(
- """ @staticmethod
- def ${method}(*args):
- return P("${invertedMethodMap[method]}", *args)
-""")
- };
- pythonClass.append(""" def _and(self, arg):
- return P("_and", arg, self)
- def _or(self, arg):
- return P("_or", arg, self)
-""")
- pythonClass.append("\n")
- P.class.getMethods()
- .findAll { !it.name.equals("clone") }
- .findAll { P.class.isAssignableFrom(it.getReturnType()) }
- .collect { methodMap[it.name] }
- .unique()
- .sort { a, b -> a <=> b }
- .forEach {
- pythonClass.append("def ${it}(*args):\n").append(" return P.${it}(*args)\n\n")
- pythonClass.append("statics['${it}'] = ${it}\n")
- }
- pythonClass.append("\n")
- //////////////
-
- pythonClass.append("statics = OrderedDict(reversed(list(statics.items())))\n")
-
-// save to a python file
- final File file = new File(gremlinPythonFile);
- file.delete()
- pythonClass.eachLine { file.append(it + "\n") }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/49674539/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java b/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java
deleted file mode 100644
index c7bc40a..0000000
--- a/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tinkerpop.gremlin.python;
-
-public class GenerateGremlinPython {
- public static void main(String[] args) {
- String dest;
- if (args.length > 0) {
- dest = args[0];
- } else {
- System.out.println("Usage: java GenerateGremlinPython <path/to/dest>");
- return;
- }
- GremlinPythonGenerator.create(dest);
- }
-}