From 20bd4531e2249b798a92a6fdf32c14da7cdf30cf Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Tue, 8 Oct 2024 15:18:22 +0530 Subject: [PATCH 01/14] importing display function from IPython.display to display the map image --- python/grass/jupyter/map.py | 4 ++-- python/grass/jupyter/map3d.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index 013ff693470..a8178c22e9b 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -188,9 +188,9 @@ def wrapper(**kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image # pylint: disable=import-outside-toplevel + from IPython.display import Image, display # pylint: disable=import-outside-toplevel - return Image(self._filename) + return display(Image(self._filename)) def save(self, filename): """Saves a PNG image of map to the specified *filename*""" diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index dd373f315a7..1ee09e0fb8c 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -232,6 +232,6 @@ def render(self, **kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image # pylint: disable=import-outside-toplevel + from IPython.display import Image,display # pylint: disable=import-outside-toplevel - return Image(self._filename) + return display(Image(self._filename)) From e95c87d965575fffca79545bd1ddb739e54140cf Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Thu, 17 Oct 2024 16:06:53 +0530 Subject: [PATCH 02/14] grass.jupyter:Add _repr_pretty_ for better Jupyter/Quarto integration --- python/grass/jupyter/map.py | 12 +++++++++++- python/grass/jupyter/map3d.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index a8178c22e9b..e65fb64b015 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -190,7 +190,17 @@ def show(self): # Lazy import to avoid an import-time dependency on IPython. from IPython.display import Image, display # pylint: disable=import-outside-toplevel - return display(Image(self._filename)) + return Image(self._filename) + def _repr_pretty_(self, p, cycle): + """Pretty representation of the object in IPython/Jupyter.""" + # Lazy import to avoid an import-time dependency on IPython. + from IPython.display import Image, display # pylint: disable=import-outside-toplevel + + if cycle: + p.text("Map(...)") + else: + display(Image(self._filename)) + def save(self, filename): """Saves a PNG image of map to the specified *filename*""" diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 1ee09e0fb8c..810affd39e5 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -234,4 +234,15 @@ def show(self): # Lazy import to avoid an import-time dependency on IPython. from IPython.display import Image,display # pylint: disable=import-outside-toplevel - return display(Image(self._filename)) + return Image(self._filename) + + def _repr_pretty_(self, p, cycle): + """Pretty representation of the object in IPython/Jupyter.""" + # Lazy import to avoid an import-time dependency on IPython. + from IPython.display import Image, display # pylint: disable=import-outside-toplevel + + if cycle: + p.text("Map(...)") + else: + display(Image(self._filename)) + From e5fb33ce15b7b02413486491cff88a75ed2ef1e0 Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Thu, 17 Oct 2024 18:10:06 +0530 Subject: [PATCH 03/14] grass.jupyter:update show() to return Image object instead of calling display() --- python/grass/jupyter/map.py | 2 +- python/grass/jupyter/map3d.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index e65fb64b015..b860cf13526 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -188,7 +188,7 @@ def wrapper(**kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image, display # pylint: disable=import-outside-toplevel + from IPython.display import Image # pylint: disable=import-outside-toplevel return Image(self._filename) def _repr_pretty_(self, p, cycle): diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 810affd39e5..46f336b1be4 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -232,7 +232,7 @@ def render(self, **kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image,display # pylint: disable=import-outside-toplevel + from IPython.display import Image # pylint: disable=import-outside-toplevel return Image(self._filename) From fb89f80c0182da61678cf375f427e64f9ea9cbee Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Fri, 18 Oct 2024 18:10:51 +0530 Subject: [PATCH 04/14] git commit -m "Remove empty line as suggested by ruff" --- python/grass/jupyter/map3d.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 46f336b1be4..1093b27c384 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -235,7 +235,6 @@ def show(self): from IPython.display import Image # pylint: disable=import-outside-toplevel return Image(self._filename) - def _repr_pretty_(self, p, cycle): """Pretty representation of the object in IPython/Jupyter.""" # Lazy import to avoid an import-time dependency on IPython. @@ -245,4 +244,3 @@ def _repr_pretty_(self, p, cycle): p.text("Map(...)") else: display(Image(self._filename)) - From 66157e09b36b157bf5da8d8e8f212b843b67cb2c Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sat, 19 Oct 2024 16:41:12 +0530 Subject: [PATCH 05/14] refactor: remove return from show() and use display() for inline rendering --- python/grass/jupyter/map.py | 14 ++------------ python/grass/jupyter/map3d.py | 12 ++---------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index b860cf13526..7e86c6c6d36 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -188,19 +188,9 @@ def wrapper(**kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image # pylint: disable=import-outside-toplevel - - return Image(self._filename) - def _repr_pretty_(self, p, cycle): - """Pretty representation of the object in IPython/Jupyter.""" - # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image, display # pylint: disable=import-outside-toplevel - - if cycle: - p.text("Map(...)") - else: - display(Image(self._filename)) + from IPython.display import Image,display # pylint: disable=import-outside-toplevel + display(Image(self._filename)) def save(self, filename): """Saves a PNG image of map to the specified *filename*""" diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 1093b27c384..ece06dc9340 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -232,15 +232,7 @@ def render(self, **kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image # pylint: disable=import-outside-toplevel - - return Image(self._filename) - def _repr_pretty_(self, p, cycle): - """Pretty representation of the object in IPython/Jupyter.""" - # Lazy import to avoid an import-time dependency on IPython. from IPython.display import Image, display # pylint: disable=import-outside-toplevel - if cycle: - p.text("Map(...)") - else: - display(Image(self._filename)) + display(Image(self._filename)) + From 0cc242ad236c030780808c5b7d5a0c27137bf9c0 Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sat, 19 Oct 2024 20:11:12 +0530 Subject: [PATCH 06/14] Removed empty line as suggested by ruff --- python/grass/jupyter/map3d.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index ece06dc9340..d8e9698349b 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -235,4 +235,3 @@ def show(self): from IPython.display import Image, display # pylint: disable=import-outside-toplevel display(Image(self._filename)) - From 05d9b90515c9e9ce05c00c80a882a7a27adacfd5 Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sat, 19 Oct 2024 22:47:06 +0530 Subject: [PATCH 07/14] style: reformat import statements as suggested by black --- python/grass/jupyter/map3d.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index d8e9698349b..29b67523190 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -232,6 +232,8 @@ def render(self, **kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image, display # pylint: disable=import-outside-toplevel - + from IPython.display import ( + Image, + display, + ) # pylint: disable=import-outside-toplevel display(Image(self._filename)) From 9db48cd54a939a9e4af111078b007d050095f0aa Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sat, 19 Oct 2024 22:52:03 +0530 Subject: [PATCH 08/14] Fix formatting of imports and remove duplicate display line --- python/grass/jupyter/map3d.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 29b67523190..8995689a3f9 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -233,7 +233,8 @@ def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. from IPython.display import ( - Image, - display, + Image, + display, ) # pylint: disable=import-outside-toplevel + display(Image(self._filename)) From 084d2467b32a63f609f6d9db88b8819cb3e29076 Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sun, 20 Oct 2024 11:20:46 +0530 Subject: [PATCH 09/14] Update .pylintrc: fix overgeneral-exceptions and remove no-self-use option. --- .pylintrc | 7 ++++--- python/grass/jupyter/map.py | 6 ++++-- python/grass/jupyter/map3d.py | 1 - 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.pylintrc b/.pylintrc index b260c0fd401..0f8da6303d4 100644 --- a/.pylintrc +++ b/.pylintrc @@ -104,7 +104,7 @@ disable=raw-checker-failed, expression-not-assigned, self-assigning-variable, unspecified-encoding, - no-self-use, + #no-self-use, inconsistent-return-statements, invalid-name, broad-except, @@ -652,5 +652,6 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "BaseException, Exception". -overgeneral-exceptions=BaseException, - Exception +overgeneral-exceptions=builtins.BaseException, + builtins.Exception + diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index 7e86c6c6d36..261734404f5 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -188,8 +188,10 @@ def wrapper(**kwargs): def show(self): """Displays a PNG image of map""" # Lazy import to avoid an import-time dependency on IPython. - from IPython.display import Image,display # pylint: disable=import-outside-toplevel - + from IPython.display import ( + Image, + display, # pylint: disable=import-outside-toplevel + ) display(Image(self._filename)) def save(self, filename): diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 8995689a3f9..630be65e99e 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -236,5 +236,4 @@ def show(self): Image, display, ) # pylint: disable=import-outside-toplevel - display(Image(self._filename)) From 53e86f9e185b9c48da908f99217eea42d0dba57e Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sun, 20 Oct 2024 11:51:14 +0530 Subject: [PATCH 10/14] git commit -m "Fix formatting issues in parsetab.py" --- .pylintrc | 6 +++--- python/grass/jupyter/map.py | 1 + python/grass/jupyter/map3d.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 0f8da6303d4..2303baed81d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -104,7 +104,7 @@ disable=raw-checker-failed, expression-not-assigned, self-assigning-variable, unspecified-encoding, - #no-self-use, + no-self-use, inconsistent-return-statements, invalid-name, broad-except, @@ -652,6 +652,6 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "BaseException, Exception". -overgeneral-exceptions=builtins.BaseException, - builtins.Exception +overgeneral-exceptions=BaseException,Exception + diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index 261734404f5..0dfdcbe9592 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -192,6 +192,7 @@ def show(self): Image, display, # pylint: disable=import-outside-toplevel ) + display(Image(self._filename)) def save(self, filename): diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 630be65e99e..8995689a3f9 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -236,4 +236,5 @@ def show(self): Image, display, ) # pylint: disable=import-outside-toplevel + display(Image(self._filename)) From 6aef31cec38d602329a31690fb031a289a2563a5 Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sun, 20 Oct 2024 12:16:55 +0530 Subject: [PATCH 11/14] Fix import organization based on review suggestion --- python/grass/jupyter/map.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/grass/jupyter/map.py b/python/grass/jupyter/map.py index 0dfdcbe9592..261734404f5 100644 --- a/python/grass/jupyter/map.py +++ b/python/grass/jupyter/map.py @@ -192,7 +192,6 @@ def show(self): Image, display, # pylint: disable=import-outside-toplevel ) - display(Image(self._filename)) def save(self, filename): From d16bbf33a576bd81e3fa6d1ec97875e6a8b76cc1 Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sun, 20 Oct 2024 12:19:46 +0530 Subject: [PATCH 12/14] Fix import organization based on review suggestion --- python/grass/jupyter/map3d.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/grass/jupyter/map3d.py b/python/grass/jupyter/map3d.py index 8995689a3f9..630be65e99e 100644 --- a/python/grass/jupyter/map3d.py +++ b/python/grass/jupyter/map3d.py @@ -236,5 +236,4 @@ def show(self): Image, display, ) # pylint: disable=import-outside-toplevel - display(Image(self._filename)) From ebc6a716b3269c9d18b2b5b0cda6f22cc4e9b33d Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Mon, 21 Oct 2024 21:17:27 +0530 Subject: [PATCH 13/14] Fix formatting display line --- .pylintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 2303baed81d..b7f4b4d9e5e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -652,6 +652,7 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "BaseException, Exception". -overgeneral-exceptions=BaseException,Exception +overgeneral-exceptions=BaseException, + Exception From e6a13958452a96c53311d389824a774b7338cb5b Mon Sep 17 00:00:00 2001 From: rohannallamadge Date: Sun, 27 Oct 2024 23:48:28 +0530 Subject: [PATCH 14/14] Fix formatting display line --- .pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index b7f4b4d9e5e..853eb773736 100644 --- a/.pylintrc +++ b/.pylintrc @@ -654,5 +654,4 @@ min-public-methods=1 # "BaseException, Exception". overgeneral-exceptions=BaseException, Exception - - + \ No newline at end of file