Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make progress bars display in pyodide based interactive shells #18

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading