Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,18 @@ def _is_jupyter() -> bool: # pragma: no cover
get_ipython # type: ignore[name-defined]
except NameError:
return False

ipython = get_ipython() # type: ignore[name-defined]
ipython_cls_str = str(ipython.__class__)
shell = ipython.__class__.__name__

if (
"google.colab" in str(ipython.__class__)
"google.colab" in ipython_cls_str
or "pyodide" in ipython_cls_str
or os.getenv("DATABRICKS_RUNTIME_VERSION")
or shell == "ZMQInteractiveShell"
):
return True # Jupyter notebook or qtconsole
return True # Jupyter notebook, Jupyterlite or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,15 @@ def isatty(self) -> bool:
assert not console.is_terminal
# Should not have auto-detected
assert not console.file.called_isatty


def test_is_jupyter_in_jupyterlite(monkeypatch):
monkeypatch.setattr(
"rich.console.get_ipython",
type("Interpreter", (object,), {"__module__": "pyodide_kernel.interpreter"}),
raising=False,
)

console = Console(file=io.StringIO(), force_jupyter=None)

assert console.is_jupyter