diff --git a/src/ipython_shell/__init__.py b/src/ipython_shell/__init__.py index b22d9ad..5fbbdf2 100644 --- a/src/ipython_shell/__init__.py +++ b/src/ipython_shell/__init__.py @@ -7,8 +7,8 @@ from .events import ( event_from_history_output, ) from .jupyter.app import JupyterApp -from .jupyter.shell import JupyterShell from .jupyter.messages import JupyterMessage, KernelMessage, ParsedJupyterMessage +from .jupyter.shell import JupyterShell from .jupyter.transport import InputRequest, JupyterTransport from .models import ( AppInfo, @@ -46,9 +46,9 @@ __all__ = [ "InputRequest", "JSONValue", "JupyterApp", + "JupyterMessage", "JupyterShell", "JupyterTransport", - "JupyterMessage", "KernelMessage", "ParsedJupyterMessage", "Shell", diff --git a/src/ipython_shell/jupyter/__init__.py b/src/ipython_shell/jupyter/__init__.py index 1cf1724..e6ca641 100644 --- a/src/ipython_shell/jupyter/__init__.py +++ b/src/ipython_shell/jupyter/__init__.py @@ -18,17 +18,17 @@ from .shell import JupyterShell from .transport import InputRequest, JupyterTransport __all__ = [ - "InputRequest", "DisplayDataMessage", "ErrorMessage", "ExecuteReplyMessage", "ExecuteResultMessage", + "InputRequest", "InputRequestMessage", "JupyterApp", "JupyterMessage", - "KernelMessage", "JupyterShell", "JupyterTransport", + "KernelMessage", "KnownJupyterMessage", "ParsedJupyterMessage", "StatusMessage", diff --git a/src/ipython_shell/jupyter/messages.py b/src/ipython_shell/jupyter/messages.py index 6530879..8bc7bea 100644 --- a/src/ipython_shell/jupyter/messages.py +++ b/src/ipython_shell/jupyter/messages.py @@ -2,20 +2,19 @@ from typing import Annotated, ClassVar, Final, Literal from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError - type JupyterChannel = Literal["iopub", "shell", "stdin"] type MessageStatus = Literal["ok", "error", "abort"] -STREAM: Final[Literal["stream"]] = "stream" -DISPLAY_DATA: Final[Literal["display_data"]] = "display_data" -UPDATE_DISPLAY_DATA: Final[Literal["update_display_data"]] = "update_display_data" -EXECUTE_RESULT: Final[Literal["execute_result"]] = "execute_result" -ERROR: Final[Literal["error"]] = "error" -STATUS: Final[Literal["status"]] = "status" -EXECUTE_INPUT: Final[Literal["execute_input"]] = "execute_input" -CLEAR_OUTPUT: Final[Literal["clear_output"]] = "clear_output" -EXECUTE_REPLY: Final[Literal["execute_reply"]] = "execute_reply" -INPUT_REQUEST: Final[Literal["input_request"]] = "input_request" +STREAM: Final = "stream" +DISPLAY_DATA: Final = "display_data" +UPDATE_DISPLAY_DATA: Final = "update_display_data" +EXECUTE_RESULT: Final = "execute_result" +ERROR: Final = "error" +STATUS: Final = "status" +EXECUTE_INPUT: Final = "execute_input" +CLEAR_OUTPUT: Final = "clear_output" +EXECUTE_REPLY: Final = "execute_reply" +INPUT_REQUEST: Final = "input_request" class MimeContent(BaseModel): diff --git a/src/ipython_shell/jupyter/transport.py b/src/ipython_shell/jupyter/transport.py index 4fbc4d5..3a1ad57 100644 --- a/src/ipython_shell/jupyter/transport.py +++ b/src/ipython_shell/jupyter/transport.py @@ -11,8 +11,6 @@ from .messages import ( ExecuteReplyMessage, InputRequestMessage, JupyterChannel, - JupyterMessage, - KernelMessage, ParsedJupyterMessage, StatusMessage, parse_jupyter_message, @@ -116,7 +114,9 @@ class JupyterTransport: async def execute(self, code: str) -> str: """Submit one cell and return its Jupyter message ID.""" if self._reader_failure is not None: - raise RuntimeError("JupyterTransport channel reader failed") from self._reader_failure + raise RuntimeError( + "JupyterTransport channel reader failed" + ) from self._reader_failure if self.client is None: raise RuntimeError("JupyterTransport has not been started") @@ -131,7 +131,9 @@ class JupyterTransport: ) -> AsyncIterator[ParsedJupyterMessage | InputRequest]: """Yield decoded output, input, and completion messages for one call.""" if self._reader_failure is not None: - raise RuntimeError("JupyterTransport channel reader failed") from self._reader_failure + raise RuntimeError( + "JupyterTransport channel reader failed" + ) from self._reader_failure if self.client is None: raise RuntimeError("JupyterTransport has not been started") if self._active_call != call_id: diff --git a/src/st_demo/app.py b/src/st_demo/app.py index 6015ee3..6b27f34 100644 --- a/src/st_demo/app.py +++ b/src/st_demo/app.py @@ -10,7 +10,6 @@ from pathlib import Path from uuid import uuid4 from ipython_shell.jupyter import InputRequest, JupyterApp, ParsedJupyterMessage - from st_demo.ui import event_to_record, latex_body, preferred_mime @@ -28,7 +27,9 @@ class _CallFailed: @dataclass class _BackgroundCall: - events: queue.Queue[ParsedJupyterMessage | InputRequest | _CallFinished | _CallFailed] + events: queue.Queue[ + ParsedJupyterMessage | InputRequest | _CallFinished | _CallFailed + ] task: Future[None] | None = None diff --git a/src/st_demo/ui.py b/src/st_demo/ui.py index 3a69b7a..c6b842b 100644 --- a/src/st_demo/ui.py +++ b/src/st_demo/ui.py @@ -13,7 +13,6 @@ from ipython_shell.jupyter.messages import ( ) from ipython_shell.jupyter.transport import InputRequest - MIME_PRIORITY: Final[tuple[str, ...]] = ( "text/html", "image/svg+xml", diff --git a/tests/test_info.py b/tests/test_info.py index fbce68e..d410951 100644 --- a/tests/test_info.py +++ b/tests/test_info.py @@ -2,10 +2,10 @@ import unittest from fastapi.testclient import TestClient +from ipython_agent.ipython_wrapper import get_app_info from ipython_mcp.app import app as mcp_app from ipython_shell import App, AppInfo from ipython_webapp.app import app as web_app -from ipython_agent.ipython_wrapper import get_app_info class AppInfoTests(unittest.IsolatedAsyncioTestCase): diff --git a/tests/test_jupyter_app.py b/tests/test_jupyter_app.py index cfe66d7..ed5a565 100644 --- a/tests/test_jupyter_app.py +++ b/tests/test_jupyter_app.py @@ -3,8 +3,8 @@ import re import unittest from ipython_shell.jupyter.app import JupyterApp -from ipython_shell.jupyter.shell import JupyterShell from ipython_shell.jupyter.messages import ExecuteResultMessage +from ipython_shell.jupyter.shell import JupyterShell from ipython_shell.jupyter.transport import InputRequest diff --git a/tests/test_transport.py b/tests/test_transport.py index 1b82af0..d46ee5c 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -211,12 +211,10 @@ 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) + message async for message in transport.messages_for(call_id) ] finally: await transport.shutdown()