diff --git a/src/ipython_shell/__init__.py b/src/ipython_shell/__init__.py index 5b9c675..26bdcb2 100644 --- a/src/ipython_shell/__init__.py +++ b/src/ipython_shell/__init__.py @@ -1,13 +1,14 @@ """Small, side-effect-free API for the in-process IPython runner.""" from .app import App -from .jupyter.app import JupyterApp -from .jupyter.shell import JupyterShell from .events import ( error_from_execution_result, event_from_execution_result, event_from_history_output, ) +from .jupyter.app import JupyterApp +from .jupyter.shell import JupyterShell +from .jupyter.transport import InputRequest, JupyterTransport, KernelMessage from .models import ( AppInfo, CallError, @@ -28,16 +29,10 @@ from .shell import ( run_cell_and_collect, setup_shell, ) -from .jupyter.transport import InputRequest, JupyterTransport, KernelMessage from .utils import generate_good_names __all__ = [ "App", - "JupyterApp", - "JupyterShell", - "JupyterTransport", - "InputRequest", - "KernelMessage", "AppInfo", "CallError", "CallEvent", @@ -46,7 +41,12 @@ __all__ = [ "CallResponse", "CallResult", "CallResultResponse", + "InputRequest", "JSONValue", + "JupyterApp", + "JupyterShell", + "JupyterTransport", + "KernelMessage", "Shell", "ShellInfo", "ShellStatus", diff --git a/src/ipython_shell/jupyter/app.py b/src/ipython_shell/jupyter/app.py index 9f0471a..a0f20d8 100644 --- a/src/ipython_shell/jupyter/app.py +++ b/src/ipython_shell/jupyter/app.py @@ -1,9 +1,9 @@ from collections.abc import AsyncIterator from uuid import uuid4 +from ..utils import generate_good_names from .shell import JupyterShell from .transport import InputRequest, KernelMessage -from ..utils import generate_good_names class JupyterApp: diff --git a/src/ipython_shell/jupyter/transport.py b/src/ipython_shell/jupyter/transport.py index 3745479..320b332 100644 --- a/src/ipython_shell/jupyter/transport.py +++ b/src/ipython_shell/jupyter/transport.py @@ -97,7 +97,9 @@ class JupyterTransport: msg_type=message["msg_type"], parent_id=parent_id, content=dict(message.get("content", {})), - buffers=[bytes(buffer) for buffer in message.get("buffers", [])], + buffers=[ + bytes(buffer) for buffer in message.get("buffers", []) + ], ) if decoded.msg_type == "execute_reply": # The shell reply and IOPub messages use different diff --git a/src/ipython_webapp/jupyter/app.py b/src/ipython_webapp/jupyter/app.py index 09a8d9b..795f343 100644 --- a/src/ipython_webapp/jupyter/app.py +++ b/src/ipython_webapp/jupyter/app.py @@ -36,7 +36,9 @@ def serialize_event(event: KernelMessage | InputRequest) -> dict[str, object]: "msg_type": event.msg_type, "parent_id": event.parent_id, "content": event.content, - "buffers": [base64.b64encode(buffer).decode("ascii") for buffer in event.buffers], + "buffers": [ + base64.b64encode(buffer).decode("ascii") for buffer in event.buffers + ], } diff --git a/tests/test_jupyter_webapp.py b/tests/test_jupyter_webapp.py index 927a140..5cf0575 100644 --- a/tests/test_jupyter_webapp.py +++ b/tests/test_jupyter_webapp.py @@ -47,7 +47,9 @@ class JupyterWebAppTests(unittest.IsolatedAsyncioTestCase): response.headers["content-type"].startswith("application/x-ndjson") ) events = [json.loads(line) for line in response.text.splitlines()] - result = next(event for event in events if event["msg_type"] == "execute_result") + result = next( + event for event in events if event["msg_type"] == "execute_result" + ) self.assertEqual(result["content"]["data"]["text/plain"], "{'answer': 42}") async def test_input_request_can_be_replied_to_while_run_streams(self): @@ -67,7 +69,9 @@ class JupyterWebAppTests(unittest.IsolatedAsyncioTestCase): finally: await shell_app.shutdown() - result = next(event for event in events if event.get("msg_type") == "execute_result") + result = next( + event for event in events if event.get("msg_type") == "execute_result" + ) self.assertEqual(result["content"]["data"]["text/plain"], "'Ada'") diff --git a/tests/test_transport.py b/tests/test_transport.py index c2494e3..5939bc2 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -1,7 +1,11 @@ import asyncio import unittest -from ipython_shell.jupyter.transport import InputRequest, JupyterTransport, KernelMessage +from ipython_shell.jupyter.transport import ( + InputRequest, + JupyterTransport, + KernelMessage, +) class TransportTests(unittest.TestCase): @@ -24,9 +28,7 @@ class AsyncTransportTests(unittest.IsolatedAsyncioTestCase): await transport.start() try: call_id = await transport.execute("2 + 2") - messages = [ - message async for message in transport.messages_for(call_id) - ] + messages = [message async for message in transport.messages_for(call_id)] finally: await transport.shutdown() @@ -72,19 +74,14 @@ class AsyncTransportTests(unittest.IsolatedAsyncioTestCase): await transport.start() try: call_id = await transport.execute( - "import matplotlib.pyplot as plt\n" - "plt.plot([1, 2, 3], [4, 5, 6])" + "import matplotlib.pyplot as plt\nplt.plot([1, 2, 3], [4, 5, 6])" ) - messages = [ - message async for message in transport.messages_for(call_id) - ] + messages = [message async for message in transport.messages_for(call_id)] finally: await transport.shutdown() display = next( - message - for message in messages - if message.msg_type == "display_data" + message for message in messages if message.msg_type == "display_data" ) self.assertIn("image/png", display.content["data"])