Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reliance on IPython's coloransi #924

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions ipyparallel/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,37 +154,18 @@ def __repr__(self):

return f"<ExecuteReply[{self.execution_count}]: {text_out}>"

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):
p.text(self._plaintext())
Expand Down