This is an automated email from the ASF dual-hosted git repository.

ningk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 15770b3fe23 [BEAM-13670] Upgraded ipython from v7 to v8 (#17529)
15770b3fe23 is described below

commit 15770b3fe23b2c1f634eac8e8f460df546eb3a10
Author: Ning Kang <ningkang0...@gmail.com>
AuthorDate: Tue May 3 14:35:44 2022 -0700

    [BEAM-13670] Upgraded ipython from v7 to v8 (#17529)
    
    * Replaced deprecated IPython.core.display package imports with
    IPython.display.
    * IPython v8 is not compatible with Python<=3.7, default setup file to
    still use v7 if Python version is lower than 3.7.
---
 .../runners/interactive/display/display_manager.py         |  2 +-
 .../runners/interactive/display/pcoll_visualization.py     |  8 ++++----
 .../runners/interactive/display/pipeline_graph.py          |  2 +-
 .../runners/interactive/interactive_environment.py         |  8 ++++----
 sdks/python/apache_beam/runners/interactive/utils.py       | 14 +++++++-------
 sdks/python/apache_beam/runners/interactive/utils_test.py  |  8 ++++----
 sdks/python/setup.py                                       |  4 +++-
 7 files changed, 24 insertions(+), 22 deletions(-)

diff --git 
a/sdks/python/apache_beam/runners/interactive/display/display_manager.py 
b/sdks/python/apache_beam/runners/interactive/display/display_manager.py
index 84df9713564..e1f24830422 100644
--- a/sdks/python/apache_beam/runners/interactive/display/display_manager.py
+++ b/sdks/python/apache_beam/runners/interactive/display/display_manager.py
@@ -154,7 +154,7 @@ class DisplayManager(object):
         self._pipeline_graph.update_pcollection_stats(self._pcollection_stats)
 
         if IPython:
-          from IPython.core import display
+          from IPython import display
           display.clear_output(True)
           rendered_graph = self._renderer.render_pipeline_graph(
               self._pipeline_graph)
diff --git 
a/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py 
b/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
index f3179788a86..693abb2aeee 100644
--- a/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
+++ b/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
@@ -39,10 +39,10 @@ from apache_beam.transforms.window import IntervalWindow
 
 try:
   from IPython import get_ipython  # pylint: disable=import-error
-  from IPython.core.display import HTML  # pylint: disable=import-error
-  from IPython.core.display import Javascript  # pylint: disable=import-error
-  from IPython.core.display import display  # pylint: disable=import-error
-  from IPython.core.display import display_javascript  # pylint: 
disable=import-error
+  from IPython.display import HTML  # pylint: disable=import-error
+  from IPython.display import Javascript  # pylint: disable=import-error
+  from IPython.display import display  # pylint: disable=import-error
+  from IPython.display import display_javascript  # pylint: 
disable=import-error
   from facets_overview.generic_feature_statistics_generator import 
GenericFeatureStatisticsGenerator  # pylint: disable=import-error
   from timeloop import Timeloop  # pylint: disable=import-error
 
diff --git 
a/sdks/python/apache_beam/runners/interactive/display/pipeline_graph.py 
b/sdks/python/apache_beam/runners/interactive/display/pipeline_graph.py
index a94113df17c..92cb108bc46 100644
--- a/sdks/python/apache_beam/runners/interactive/display/pipeline_graph.py
+++ b/sdks/python/apache_beam/runners/interactive/display/pipeline_graph.py
@@ -122,7 +122,7 @@ class PipelineGraph(object):
     rendered_graph = self._renderer.render_pipeline_graph(self)
     if ie.current_env().is_in_notebook:
       try:
-        from IPython.core import display
+        from IPython import display
         display.display(display.HTML(rendered_graph))
       except ImportError:  # Unlikely to happen when is_in_notebook.
         logging.warning(
diff --git 
a/sdks/python/apache_beam/runners/interactive/interactive_environment.py 
b/sdks/python/apache_beam/runners/interactive/interactive_environment.py
index 78b6de920cf..5f3552f6770 100644
--- a/sdks/python/apache_beam/runners/interactive/interactive_environment.py
+++ b/sdks/python/apache_beam/runners/interactive/interactive_environment.py
@@ -673,8 +673,8 @@ class InteractiveEnvironment(object):
        all jQuery plugins are set.
     """
     try:
-      from IPython.core.display import Javascript
-      from IPython.core.display import display_javascript
+      from IPython.display import Javascript
+      from IPython.display import display_javascript
       display_javascript(
           Javascript(
               _JQUERY_WITH_DATATABLE_TEMPLATE.format(customized_script='')))
@@ -695,8 +695,8 @@ class InteractiveEnvironment(object):
     especially the output areas of notebook cells.
     """
     try:
-      from IPython.core.display import Javascript
-      from IPython.core.display import display_javascript
+      from IPython.display import Javascript
+      from IPython.display import display_javascript
       display_javascript(
           Javascript(_HTML_IMPORT_TEMPLATE.format(hrefs=html_hrefs)))
     except ImportError:
diff --git a/sdks/python/apache_beam/runners/interactive/utils.py 
b/sdks/python/apache_beam/runners/interactive/utils.py
index fbbb4168acd..71305a5d976 100644
--- a/sdks/python/apache_beam/runners/interactive/utils.py
+++ b/sdks/python/apache_beam/runners/interactive/utils.py
@@ -228,8 +228,8 @@ class IPythonLogHandler(logging.Handler):
   def emit(self, record):
     try:
       from html import escape
-      from IPython.core.display import HTML
-      from IPython.core.display import display
+      from IPython.display import HTML
+      from IPython.display import display
       display(HTML(_INTERACTIVE_LOG_STYLE))
       display(
           HTML(
@@ -269,8 +269,8 @@ class ProgressIndicator(object):
 
   def __enter__(self):
     try:
-      from IPython.core.display import HTML
-      from IPython.core.display import display
+      from IPython.display import HTML
+      from IPython.display import display
       from apache_beam.runners.interactive import interactive_environment as ie
       if ie.current_env().is_in_notebook:
         display(HTML(self.spinner_template.format(id=self._id)))
@@ -283,9 +283,9 @@ class ProgressIndicator(object):
 
   def __exit__(self, exc_type, exc_value, traceback):
     try:
-      from IPython.core.display import Javascript
-      from IPython.core.display import display
-      from IPython.core.display import display_javascript
+      from IPython.display import Javascript
+      from IPython.display import display
+      from IPython.display import display_javascript
       from apache_beam.runners.interactive import interactive_environment as ie
       if ie.current_env().is_in_notebook:
         script = self.spinner_removal_template.format(id=self._id)
diff --git a/sdks/python/apache_beam/runners/interactive/utils_test.py 
b/sdks/python/apache_beam/runners/interactive/utils_test.py
index 9667fed63f3..66ad6aa5833 100644
--- a/sdks/python/apache_beam/runners/interactive/utils_test.py
+++ b/sdks/python/apache_beam/runners/interactive/utils_test.py
@@ -210,7 +210,7 @@ class IPythonLogHandlerTest(unittest.TestCase):
     # loggings from child loggers will be propagated to the interactive "root"
     # logger which is set to INFO level that gets handled by the sole log
     # handler IPythonLogHandler which is set to NOTSET. The effect will be
-    # everything >= info level will be logged through IPython.core.display to
+    # everything >= info level will be logged through IPython.display to
     # all frontends connected to current kernel.
     dummy_logger = logging.getLogger('apache_beam.runners.interactive.dummy1')
     dummy_logger.info('info')
@@ -259,7 +259,7 @@ class ProgressIndicatorTest(unittest.TestCase):
       self, mocked_is_in_notebook, unused):
     mocked_is_in_notebook.return_value = False
 
-    with patch('IPython.core.display.display') as mocked_display:
+    with patch('IPython.display.display') as mocked_display:
 
       @utils.progress_indicated
       def progress_indicated_dummy():
@@ -277,8 +277,8 @@ class ProgressIndicatorTest(unittest.TestCase):
       self, mocked_is_in_notebook, unused):
     mocked_is_in_notebook.return_value = True
 
-    with patch('IPython.core.display.HTML') as mocked_html,\
-      patch('IPython.core.display.Javascript') as mocked_js:
+    with patch('IPython.display.HTML') as mocked_html,\
+      patch('IPython.display.Javascript') as mocked_js:
       with utils.ProgressIndicator('enter', 'exit'):
         mocked_html.assert_called()
       mocked_js.assert_called()
diff --git a/sdks/python/setup.py b/sdks/python/setup.py
index e2233c575d9..b808c87405c 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -206,7 +206,9 @@ GCP_REQUIREMENTS = [
 INTERACTIVE_BEAM = [
     'facets-overview>=1.0.0,<2',
     'google-cloud-dataproc>=3.0.0,<3.2.0',
-    'ipython>=7,<8',
+    # IPython>=8 is not compatible with Python<=3.7
+    'ipython>=7,<8;python_version<="3.7"',
+    'ipython>=8,<9;python_version>"3.7"',
     'ipykernel>=6,<7',
     'ipywidgets>=7.6.5,<8',
     # Skip version 6.1.13 due to

Reply via email to