davisusanibar commented on a change in pull request #131:
URL: https://github.com/apache/arrow-cookbook/pull/131#discussion_r791171531



##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,92 @@
+import os
+import pathlib
+import subprocess
+
+from sphinx.ext.doctest import (Any, Dict, DocTestBuilder, TestcodeDirective,
+                                TestoutputDirective, doctest, sphinx)
+from sphinx.locale import __
+
+
+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
+        path_arrow_project = os.path.join(pathlib.Path.cwd(), "source", "demo")
+
+        # create list of all arrow jar dependencies
+        subprocess.check_call(
+            [
+                "mvn",
+                "-q",
+                "dependency:build-classpath",
+                "-DincludeTypes=jar",
+                "-Dmdep.outputFile=.cp.tmp",
+            ],
+            cwd=path_arrow_project,
+            text=True,
+        )
+        if not os.path.exists(path_arrow_project + "/.cp.tmp"):
+            raise RuntimeError(
+                __("invalid process to create jshell dependencies library")
+            )
+
+        # get list of all arrow jar dependencies
+        with open(os.path.join(path_arrow_project, ".cp.tmp")) as f:
+            stdout_dependency = f.read()
+        if not stdout_dependency:
+            raise RuntimeError(
+                __("invalid process to list jshell dependencies library")
+            )
+
+        # execute java testing code thru jshell and read output
+        proc_jshell_process = subprocess.Popen(
+            ["jshell", "--class-path", stdout_dependency, "-"],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            text=True,
+        )
+        out_java_arrow, err_java_arrow = proc_jshell_process.communicate(code)
+        if err_java_arrow:
+            raise RuntimeError(__("invalid proc ess to run jshell"))
+
+        # continue with python logic code to do java output validation
+        output = "print('" + self.clean_output(out_java_arrow) + "')"

Review comment:
       This PR is to handle java cookbook for create arrow object.
   
   This recommendation was added to baseline PR: 
https://github.com/apache/arrow-cookbook/pull/125/commits/3d82096ade13f80fbc37be274efc7b4f1b0712c4
   
   Please if we could merge that to continue with another cookbooks

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,92 @@
+import os
+import pathlib
+import subprocess
+
+from sphinx.ext.doctest import (Any, Dict, DocTestBuilder, TestcodeDirective,
+                                TestoutputDirective, doctest, sphinx)
+from sphinx.locale import __
+
+
+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
+        path_arrow_project = os.path.join(pathlib.Path.cwd(), "source", "demo")
+
+        # create list of all arrow jar dependencies
+        subprocess.check_call(
+            [
+                "mvn",
+                "-q",
+                "dependency:build-classpath",
+                "-DincludeTypes=jar",
+                "-Dmdep.outputFile=.cp.tmp",
+            ],
+            cwd=path_arrow_project,
+            text=True,
+        )
+        if not os.path.exists(path_arrow_project + "/.cp.tmp"):
+            raise RuntimeError(
+                __("invalid process to create jshell dependencies library")
+            )
+
+        # get list of all arrow jar dependencies
+        with open(os.path.join(path_arrow_project, ".cp.tmp")) as f:
+            stdout_dependency = f.read()
+        if not stdout_dependency:
+            raise RuntimeError(
+                __("invalid process to list jshell dependencies library")
+            )
+
+        # execute java testing code thru jshell and read output
+        proc_jshell_process = subprocess.Popen(
+            ["jshell", "--class-path", stdout_dependency, "-"],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            text=True,
+        )
+        out_java_arrow, err_java_arrow = proc_jshell_process.communicate(code)

Review comment:
       This PR is to handle java cookbook for create arrow object.
   
   Errors related to dash '-' was changed to '/dev/stdin' JDK9 does not support 
dash and JDK11 working weel with dash to cover backward compatibility we move 
to /dev/stdbin
   
   This change was added to baseline PR: 
https://github.com/apache/arrow-cookbook/pull/125/commits/3d82096ade13f80fbc37be274efc7b4f1b0712c4
   
   Please if we could merge that to continue with another cookbooks

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,92 @@
+import os
+import pathlib
+import subprocess
+
+from sphinx.ext.doctest import (Any, Dict, DocTestBuilder, TestcodeDirective,
+                                TestoutputDirective, doctest, sphinx)
+from sphinx.locale import __
+
+
+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
+        path_arrow_project = os.path.join(pathlib.Path.cwd(), "source", "demo")
+
+        # create list of all arrow jar dependencies
+        subprocess.check_call(
+            [
+                "mvn",
+                "-q",
+                "dependency:build-classpath",
+                "-DincludeTypes=jar",
+                "-Dmdep.outputFile=.cp.tmp",
+            ],
+            cwd=path_arrow_project,
+            text=True,
+        )
+        if not os.path.exists(path_arrow_project + "/.cp.tmp"):
+            raise RuntimeError(
+                __("invalid process to create jshell dependencies library")
+            )
+
+        # get list of all arrow jar dependencies
+        with open(os.path.join(path_arrow_project, ".cp.tmp")) as f:
+            stdout_dependency = f.read()
+        if not stdout_dependency:
+            raise RuntimeError(
+                __("invalid process to list jshell dependencies library")
+            )
+
+        # execute java testing code thru jshell and read output
+        proc_jshell_process = subprocess.Popen(
+            ["jshell", "--class-path", stdout_dependency, "-"],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            text=True,
+        )
+        out_java_arrow, err_java_arrow = proc_jshell_process.communicate(code)
+        if err_java_arrow:
+            raise RuntimeError(__("invalid proc ess to run jshell"))
+
+        # continue with python logic code to do java output validation
+        output = "print('" + self.clean_output(out_java_arrow) + "')"

Review comment:
       Please if we could merge that to continue with another cookbooks: 
https://github.com/apache/arrow-cookbook/pull/125

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,92 @@
+import os
+import pathlib
+import subprocess
+
+from sphinx.ext.doctest import (Any, Dict, DocTestBuilder, TestcodeDirective,
+                                TestoutputDirective, doctest, sphinx)
+from sphinx.locale import __
+
+
+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
+        path_arrow_project = os.path.join(pathlib.Path.cwd(), "source", "demo")
+
+        # create list of all arrow jar dependencies
+        subprocess.check_call(
+            [
+                "mvn",
+                "-q",
+                "dependency:build-classpath",
+                "-DincludeTypes=jar",
+                "-Dmdep.outputFile=.cp.tmp",
+            ],
+            cwd=path_arrow_project,
+            text=True,
+        )
+        if not os.path.exists(path_arrow_project + "/.cp.tmp"):
+            raise RuntimeError(
+                __("invalid process to create jshell dependencies library")
+            )
+
+        # get list of all arrow jar dependencies
+        with open(os.path.join(path_arrow_project, ".cp.tmp")) as f:
+            stdout_dependency = f.read()
+        if not stdout_dependency:
+            raise RuntimeError(
+                __("invalid process to list jshell dependencies library")
+            )
+
+        # execute java testing code thru jshell and read output
+        proc_jshell_process = subprocess.Popen(
+            ["jshell", "--class-path", stdout_dependency, "-"],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            text=True,
+        )
+        out_java_arrow, err_java_arrow = proc_jshell_process.communicate(code)

Review comment:
       Please if we could merge that to continue with another cookbooks: 
https://github.com/apache/arrow-cookbook/pull/125

##########
File path: java/ext/javadoctest.py
##########
@@ -0,0 +1,92 @@
+import os
+import pathlib
+import subprocess
+
+from sphinx.ext.doctest import (Any, Dict, DocTestBuilder, TestcodeDirective,
+                                TestoutputDirective, doctest, sphinx)
+from sphinx.locale import __
+
+
+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
+        path_arrow_project = os.path.join(pathlib.Path.cwd(), "source", "demo")
+
+        # create list of all arrow jar dependencies
+        subprocess.check_call(
+            [
+                "mvn",
+                "-q",
+                "dependency:build-classpath",
+                "-DincludeTypes=jar",
+                "-Dmdep.outputFile=.cp.tmp",
+            ],
+            cwd=path_arrow_project,
+            text=True,
+        )
+        if not os.path.exists(path_arrow_project + "/.cp.tmp"):
+            raise RuntimeError(
+                __("invalid process to create jshell dependencies library")
+            )
+
+        # get list of all arrow jar dependencies
+        with open(os.path.join(path_arrow_project, ".cp.tmp")) as f:
+            stdout_dependency = f.read()
+        if not stdout_dependency:
+            raise RuntimeError(
+                __("invalid process to list jshell dependencies library")
+            )
+
+        # execute java testing code thru jshell and read output
+        proc_jshell_process = subprocess.Popen(
+            ["jshell", "--class-path", stdout_dependency, "-"],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            text=True,
+        )
+        out_java_arrow, err_java_arrow = proc_jshell_process.communicate(code)

Review comment:
       > I think that it we have the chance to remove a constraint just by 
writing to a temporary file that's something we should pursue. One less 
dependency to check.
   
   We were testing that and at the end we cama back to the same to obtain java 
output and also add more execution time for create/read temporary files.
   
   Please let me know if with `/dev/stdbin` that support JDK9 and JDK11 we are 
ok
   
   




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to