From df0896c5514254e1250c303713a93df7cb29236d Mon Sep 17 00:00:00 2001 From: Leifur Halldor Asgeirsson Date: Wed, 22 Jun 2016 09:34:41 -0400 Subject: [PATCH] gremlin_python: generate/build/deps before tests Code generation is triggered by Maven before tests are run; dependencies (currently aenum, requests) are installed, and the generated package is built into ${project.build.testOutputDirectory}/Lib, which is added to the classpath for the tests via the python.home property. Jython tests import the gremlin_python package instead of importing its modules directly. --- gremlin-variant/pom.xml | 56 +++++++++++++++++++ .../gremlin/python/GenerateGremlinPython.java | 33 +++++++++++ gremlin-variant/src/main/jython/setup.py | 3 +- .../python/JythonScriptEngineSetup.java | 23 +------- 4 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java diff --git a/gremlin-variant/pom.xml b/gremlin-variant/pom.xml index 34f181d256c..838023712a9 100644 --- a/gremlin-variant/pom.xml +++ b/gremlin-variant/pom.xml @@ -99,6 +99,39 @@ + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + generatePython + generate-test-resources + + java + + + org.apache.tinkerpop.gremlin.python.GenerateGremlinPython + + ${basedir}/src/main/jython/gremlin_python/gremlin_python.py + + + + + buildPython + generate-test-resources + + exec + + + python + true + ${basedir}/src/main/jython + setup.py build --build-lib ${project.build.testOutputDirectory}/Lib + + + + org.codehaus.gmavenplus gmavenplus-plugin @@ -132,8 +165,31 @@ jython + + pythonDependencies + generate-test-resources + + jython + + + ${project.build.testOutputDirectory} + + aenum + requests + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.build.testOutputDirectory} + + + org.apache.maven.plugins maven-clean-plugin 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 new file mode 100644 index 00000000000..c7bc40a5c13 --- /dev/null +++ b/gremlin-variant/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.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.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 "); + return; + } + GremlinPythonGenerator.create(dest); + } +} diff --git a/gremlin-variant/src/main/jython/setup.py b/gremlin-variant/src/main/jython/setup.py index d1a0bb1308b..b0a5913180f 100644 --- a/gremlin-variant/src/main/jython/setup.py +++ b/gremlin-variant/src/main/jython/setup.py @@ -48,6 +48,7 @@ description='Gremlin Language Variant for Apache TinkerPop - Gremlin', long_description=open("README").read(), install_requires=[ - 'aenum' + 'aenum', + 'requests' ] ) diff --git a/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/python/JythonScriptEngineSetup.java b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/python/JythonScriptEngineSetup.java index 799f3b23b72..608b40f4f42 100644 --- a/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/python/JythonScriptEngineSetup.java +++ b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/python/JythonScriptEngineSetup.java @@ -23,7 +23,6 @@ import javax.script.ScriptEngine; import javax.script.ScriptException; -import java.io.File; /** * @author Marko A. Rodriguez (http://markorodriguez.com) @@ -35,26 +34,10 @@ private JythonScriptEngineSetup() { public static void setup() { try { - final String rootPackageName = (new File("gremlin-variant").exists() ? "gremlin-variant/" : "") + "src/main/jython/"; - final String gremlinPythonPackageName = rootPackageName + "/gremlin_python"; - final String gremlinDriverPackageName = rootPackageName + "/gremlin_driver"; - final String gremlinRESTDriverPackageName = rootPackageName + "/gremlin_rest_driver"; - final String gremlinPythonModuleName = gremlinPythonPackageName + "/gremlin_python.py"; - GremlinPythonGenerator.create(gremlinPythonModuleName); final ScriptEngine jythonEngine = ScriptEngineCache.get("jython"); - jythonEngine.eval("import sys"); - jythonEngine.eval("sys.path.append('" + gremlinPythonPackageName + "')"); - jythonEngine.eval("sys.path.append('" + gremlinDriverPackageName + "')"); - jythonEngine.eval("sys.path.append('" + gremlinRESTDriverPackageName + "')"); - final String pythonPath = null == System.getenv("JYTHONPATH") ? System.getenv("PYTHONPATH") : System.getenv("JYTHONPATH"); - if (null != pythonPath) { - for (final String path : pythonPath.split(":")) { - jythonEngine.eval("sys.path.append('" + path + "')"); - } - } - jythonEngine.eval("from gremlin_python import *"); - jythonEngine.eval("from gremlin_python import __"); - jythonEngine.eval("from groovy_translator import GroovyTranslator"); + 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);