lidavidm commented on a change in pull request #125:
URL: https://github.com/apache/arrow-cookbook/pull/125#discussion_r787838122



##########
File path: java/CONTRIBUTING.rst
##########
@@ -0,0 +1,38 @@
+Bulding the Java Cookbook
+=========================
+
+The java cookbook uses the Sphinx documentation system.

Review comment:
       ```suggestion
   The Java cookbook uses the Sphinx documentation system.
   ```

##########
File path: CONTRIBUTING.md
##########
@@ -28,7 +28,8 @@ how to make your recipes testable.
 
  * [Contributing to Python Cookbook](python/CONTRIBUTING.rst)
  * [Contributing to R Cookbook](r/CONTRIBUTING.md)
- 
+ * [Contributing to Java Cookbook](java/CONTRIBUTING.md)

Review comment:
       nit, but maybe keep this alphabetized?

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,64 @@
+from sphinx.ext.doctest import *
+from sphinx.locale import __
+import subprocess
+from subprocess import Popen,PIPE
+import os
+
+class JavaTestDirective(TestDirective):
+    pass
+
+class JavaDocTestBuilder(DocTestBuilder):
+    """
+    Runs java test snippets in the documentation.
+    """
+    name = 'javadoctest'
+    epilog = __('Java testing of doctests in the sources finished, look at the 
'
+                'results in %(outdir)s/output.txt.')
+    def compile(self, code: str, name: str, type: str, flags: Any, 
dont_inherit: bool) -> Any:
+        # go to project that contains all your arrow maven dependencies
+        cwd = os.getcwd()
+        os.chdir('./source/demo')
+
+        # create list of all arrow jar dependencies
+        proc_mvn_dependency = subprocess.Popen(['mvn', '-q', 
'dependency:build-classpath', '-DincludeTypes=jar', 
'-Dmdep.outputFile=.cp.tmp'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
text=True)
+        stdout_mvn, stderr_mvn = proc_mvn_dependency.communicate()
+        if not os.path.exists('.cp.tmp'):
+            raise RuntimeError(__('invalid process to create jshell 
dependencies library'))
+
+        # get list of all arrow jar dependencies
+        proc_get_dependency = subprocess.Popen(['cat', '.cp.tmp'], 
stdout=subprocess.PIPE, text=True)
+        stdout_dependency, stderr_dependency = 
proc_get_dependency.communicate()
+        if not stdout_dependency:
+            raise RuntimeError(__('invalid process to list jshell dependencies 
library'))
+
+        # execute java testing code thru jshell and read output
+        proc_java_arrow_code = subprocess.Popen(['echo', '' + code], 
stdout=subprocess.PIPE)
+        proc_jshell_process = subprocess.Popen(['jshell', '--class-path', 
stdout_dependency, '-'], stdin=proc_java_arrow_code.stdout, 
stdout=subprocess.PIPE, text=True)
+        proc_java_arrow_code.stdout.close()
+        stdout_java_arrow, stderr_java_arrow = 
proc_jshell_process.communicate()
+        if stderr_java_arrow:
+            raise RuntimeError(__('invalid process to run jshell por arrow 
project'))
+
+        # continue with python logic code to do java output validation battle 
tested
+        output = 'print('+stdout_java_arrow+')'
+
+        # go to default directory 
+        os.chdir(cwd)
+
+        # continue with sphinx default logic
+        return compile(output, name, self.type, flags, dont_inherit)
+
+def setup(app: "ArrowSphinx") -> Dict[str, Any]:
+    app.add_directive('testcode', TestcodeDirective)
+    app.add_directive('testoutput', TestoutputDirective)

Review comment:
       Where are these classes actually defined?

##########
File path: build/index.html
##########
@@ -41,6 +41,7 @@ <h1>Apache Arrow Cookbook</h1>
                        <li><a href="cpp/index.html">C++ Cookbook</a></li>
                        <li><a href="py/index.html">Python Cookbook</a></li>
                        <li><a href="r/index.html">R Cookbook</a></li>
+                       <li><a href="java/index.html">Java Cookbook</a></li>

Review comment:
       nit, but maybe keep this alphabetized?

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,64 @@
+from sphinx.ext.doctest import *
+from sphinx.locale import __
+import subprocess
+from subprocess import Popen,PIPE
+import os
+
+class JavaTestDirective(TestDirective):

Review comment:
       Is this used?

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,64 @@
+from sphinx.ext.doctest import *
+from sphinx.locale import __
+import subprocess
+from subprocess import Popen,PIPE
+import os
+
+class JavaTestDirective(TestDirective):
+    pass
+
+class JavaDocTestBuilder(DocTestBuilder):
+    """
+    Runs java test snippets in the documentation.
+    """
+    name = 'javadoctest'
+    epilog = __('Java testing of doctests in the sources finished, look at the 
'
+                'results in %(outdir)s/output.txt.')
+    def compile(self, code: str, name: str, type: str, flags: Any, 
dont_inherit: bool) -> Any:
+        # go to project that contains all your arrow maven dependencies
+        cwd = os.getcwd()
+        os.chdir('./source/demo')

Review comment:
       `subprocess.Popen` lets you set the CWD, maybe we can use that instead 
of setting the process's working directory?

##########
File path: java/source/demo/pom.xml
##########
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+
+    <groupId>org.example</groupId>
+    <artifactId>demo</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <arrow.version>6.0.0</arrow.version>
+        <arrow.flight.version>0.15.1</arrow.flight.version>

Review comment:
       0.15.1? Well, this value is unused in the first place - we should remove 
it




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to