rich
rich copied to clipboard
[BUG] Databricks is not identified as Jupyter
You may find a solution to your problem in the docs or issues.
Describe the bug
Databricks is not considered as "Jupyter", therefore JUPYTER_LINES and JUPYTER_COLUMNS has no effect on the console log
Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.
Databricks has a Ipython type InteractiveShell which is neither Ipython or ZMQInteractiveShell

def _is_jupyter() -> bool: # pragma: no cover
"""Check if we're running in a Jupyter notebook."""
try:
get_ipython # type: ignore[name-defined]
except NameError:
return False
ipython = get_ipython() # type: ignore[name-defined]
shell = ipython.__class__.__name__
if "google.colab" in str(ipython.__class__) or shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type (?)
If you're using Rich in a terminal:
python -m rich.diagnose
pip freeze | grep rich
If you're using Rich in a Jupyter Notebook, run the following snippet in a cell and paste the output in your bug report.
from rich.diagnose import report
report()
╭────────────────────── <class 'rich.console.Console'> ───────────────────────╮
│ A high level console interface. │
│ │
│ ╭─────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=80 None> │ │
│ ╰─────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = None │
│ encoding = 'utf-8' │
│ file = <PythonShellImpl.ConsoleBuffer object at 0x7f462b809970> │
│ height = 25 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = False │
│ is_jupyter = False │
│ is_terminal = False │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=80, height=25), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=80, │
│ is_terminal=False, │
│ encoding='utf-8', │
│ max_height=25, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=80, height=25) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 80 │
╰─────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available. │
│ │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│ │
│ truecolor = False │
│ vt = False │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ { │
│ 'TERM': 'unknown', │
│ 'COLORTERM': None, │
│ 'CLICOLOR': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': None, │
│ 'COLUMNS': None, │
│ 'LINES': None, │
│ 'JUPYTER_COLUMNS': '200', │
│ 'JUPYTER_LINES': '50', │
│ 'JPY_PARENT_PID': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Linux"
There is no future proof way of detecting Jupyter that I know of. I'd accept a PR for whatever fudge is required to detect Databricks...
I've dumped the environment variables that are present in a Databricks notebook here
Potentially checking for both this var name and value would be the most reliable apporach:
DATABRICKS_ROOT_VIRTUALENV_ENV = "/databricks/python3"
I'll make a PR if this is ok, try to detect DATABRICKS_ROOT_VIRTUALENV_ENV.
PR created at #2424