From df2a9b5a7ef3773a6748cb1d4f06b9ff2b6387db Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Fri, 7 Feb 2025 13:30:17 +0100 Subject: [PATCH 1/2] Remove reliance on IPython's coloransi I'm nuking it in IPython 9.0 in favor of a lit of list of pairs of token and text, and having pygments/prompt_toolkit use formatting. In the and this module will likely not exists in IPython 9.0 --- ipyparallel/client/client.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/ipyparallel/client/client.py b/ipyparallel/client/client.py index 4236cd5a..7754b106 100644 --- a/ipyparallel/client/client.py +++ b/ipyparallel/client/client.py @@ -26,7 +26,6 @@ from IPython.core.profiledir import ProfileDir, ProfileDirError from IPython.paths import get_ipython_dir from IPython.utils.capture import RichOutput -from IPython.utils.coloransi import TermColors from IPython.utils.path import compress_user from jupyter_client.localinterfaces import is_local_ip, localhost from jupyter_client.session import Session @@ -155,36 +154,19 @@ def __repr__(self): return f"" - def _plaintext(self): + def _plaintext(self) -> str: execute_result = self.metadata['execute_result'] or {'data': {}} text_out = execute_result['data'].get('text/plain', '') if not text_out: return '' - ip = get_ipython() - if ip is None: - colors = "NoColor" - else: - colors = ip.colors - - if colors == "NoColor": - out = normal = "" - else: - out = TermColors.Red - normal = TermColors.Normal - if '\n' in text_out and not text_out.startswith('\n'): # add newline for multiline reprs text_out = '\n' + text_out - return ''.join( - [ - out, - f"Out[{self.metadata['engine_id']}:{self.execution_count}]: ", - normal, - text_out, - ] + return ( + f"Out[{self.metadata['engine_id']}:{self.execution_count}]: {text_out}", ) def _repr_pretty_(self, p, cycle): From 590bfa37b6a33bd1314ee855b8b2056a1799ffa3 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Fri, 7 Feb 2025 05:49:57 -0800 Subject: [PATCH 2/2] Apply suggestions from code review --- ipyparallel/client/client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ipyparallel/client/client.py b/ipyparallel/client/client.py index 7754b106..b47e60c0 100644 --- a/ipyparallel/client/client.py +++ b/ipyparallel/client/client.py @@ -165,9 +165,7 @@ def _plaintext(self) -> str: # add newline for multiline reprs text_out = '\n' + text_out - return ( - f"Out[{self.metadata['engine_id']}:{self.execution_count}]: {text_out}", - ) + return f"Out[{self.metadata['engine_id']}:{self.execution_count}]: {text_out}" def _repr_pretty_(self, p, cycle): p.text(self._plaintext())