Skip to content

Commit

Permalink
Make progress bars display in pyodide based interactive shells (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-graham authored Oct 7, 2024
1 parent 533ddc3 commit c39b744
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/mici/progressbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down

0 comments on commit c39b744

Please sign in to comment.