aaltay commented on a change in pull request #11338: [BEAM-7923] Screendiff 
Integration Tests
URL: https://github.com/apache/beam/pull/11338#discussion_r406325631
 
 

 ##########
 File path: 
sdks/python/apache_beam/runners/interactive/testing/integration/notebook_executor.py
 ##########
 @@ -0,0 +1,131 @@
+#
+# 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.
+#
+
+"""Module to execute jupyter notebooks and gather the output into renderable
+HTML files."""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import os
+import shutil
+
+from apache_beam.runners.interactive.utils import obfuscate
+
+try:
+  import nbformat
+  from nbconvert.preprocessors import ExecutePreprocessor
+  _interactive_integration_ready = True
+except ImportError:
+  _interactive_integration_ready = False
+
+
+class NotebookExecutor(object):
+  """Executor that reads notebooks, executes it and gathers outputs into static
+  HTML pages that can be served."""
+  def __init__(self, path):
+    # type: (str) -> None
+
+    assert _interactive_integration_ready, (
+        '[interactive_test] dependency is not installed.')
+    assert os.path.exists(path), '{} does not exist.'.format(path)
+    self._paths = []
+    if os.path.isdir(path):
+      for root, _, files in os.walk(path):
+        for filename in files:
+          if filename.endswith('.ipynb'):
+            self._paths.append(os.path.join(root, filename))
+    elif path.endswith('.ipynb'):
+      self._paths.append(path)
+    assert len(
+        self._paths) > 0, ('No notebooks to be executed under{}'.format(path))
+    self._dir = os.path.dirname(self._paths[0])
+    self._output_html_dir = os.path.join(self._dir, 'output')
+    self.cleanup()
+    self._output_html_paths = {}
+    self._notebook_path_to_execution_id = {}
+
+  def cleanup(self):
+    """Cleans up the output folder."""
+    _cleanup(self._output_html_dir)
+
+  def execute(self):
 
 Review comment:
   OK this is fair.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to