Skip to content

Commit 3531972

Browse files
committed
Copy payloadpage.page from IPython
IPykernel is the only user, and this will let us remove it from IPython. Closes #1304
1 parent f3f2a60 commit 3531972

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

ipykernel/subshell_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ async def listen_from_control(self, subshell_task: t.Any) -> None:
124124

125125
socket = self._control_shell_channel_socket
126126
while True:
127-
request = await socket.recv_json() # type: ignore[misc]
127+
request = await socket.recv_json()
128128
reply = await self._process_control_request(request, subshell_task)
129-
await socket.send_json(reply) # type: ignore[func-returns-value]
129+
await socket.send_json(reply)
130130

131131
async def listen_from_subshells(self) -> None:
132132
"""Listen for reply messages on inproc sockets of all subshells and resend

ipykernel/zmqshell.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import warnings
2121
from pathlib import Path
2222

23-
from IPython.core import page, payloadpage
23+
from IPython.core import page
2424
from IPython.core.autocall import ZMQExitAutocall
2525
from IPython.core.displaypub import DisplayPublisher
2626
from IPython.core.error import UsageError
@@ -541,10 +541,38 @@ def init_environment(self):
541541
env["PAGER"] = "cat"
542542
env["GIT_PAGER"] = "cat"
543543

544+
def payloadpage_page(self, strg, start=0, screen_lines=0, pager_cmd=None):
545+
"""Print a string, piping through a pager.
546+
547+
This version ignores the screen_lines and pager_cmd arguments and uses
548+
IPython's payload system instead.
549+
550+
Parameters
551+
----------
552+
strg : str or mime-dict
553+
Text to page, or a mime-type keyed dict of already formatted data.
554+
start : int
555+
Starting line at which to place the display.
556+
"""
557+
558+
# Some routines may auto-compute start offsets incorrectly and pass a
559+
# negative value. Offset to 0 for robustness.
560+
start = max(0, start)
561+
562+
data = strg if isinstance(strg, dict) else {"text/plain": strg}
563+
564+
payload = dict(
565+
source="page",
566+
data=data,
567+
start=start,
568+
)
569+
assert self.payload_manager is not None
570+
self.payload_manager.write_payload(payload)
571+
544572
def init_hooks(self):
545573
"""Initialize hooks."""
546574
super().init_hooks()
547-
self.set_hook("show_in_pager", page.as_hook(payloadpage.page), 99)
575+
self.set_hook("show_in_pager", page.as_hook(self.payloadpage_page), 99)
548576

549577
def init_data_pub(self):
550578
"""Delay datapub init until request, for deprecation warnings"""

0 commit comments

Comments
 (0)