From c39b7442f965430e179f3b50dd4d172a176e3289 Mon Sep 17 00:00:00 2001 From: Matt Graham Date: Mon, 7 Oct 2024 17:09:53 +0100 Subject: [PATCH] Make progress bars display in pyodide based interactive shells (#18) --- src/mici/progressbars.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mici/progressbars.py b/src/mici/progressbars.py index b5a8227..b21328a 100644 --- a/src/mici/progressbars.py +++ b/src/mici/progressbars.py @@ -32,17 +32,22 @@ ) -def _in_zmq_interactive_shell() -> bool: - """Check if in interactive ZMQ shell which supports updateable displays.""" +def _in_interactive_shell() -> bool: + """Check if in interactive shell which supports updateable displays.""" if not IPYTHON_AVAILABLE: return False if ON_COLAB: return True try: - shell = get_ipython().__class__.__name__ + ipython = get_ipython() + ipython_module = ipython.__module__ + ipython_class = ipython.__class__.__name__ except NameError: return False - return shell == "ZMQInteractiveShell" + return (ipython_module, ipython_class) in { + ("ipykernel.zmqshell", "ZMQInteractiveShell"), + ("pyodide_kernel.interpreter", "Interpreter"), + } class UpdateableDisplay(Protocol): @@ -67,7 +72,7 @@ def _create_display( Returns: Object with `update` method to update displayed content. """ - if _in_zmq_interactive_shell(): + if _in_interactive_shell(): return ipython_display(obj, display_id=True) return FileDisplay(position)