Detect Databricks notebook as Jupyter environment

This commit is contained in:
Nok Chan 2022-07-27 16:17:38 +01:00
parent 2ee992b17e
commit 3a5f09743a
1 changed files with 5 additions and 1 deletions

View File

@ -516,7 +516,11 @@ def _is_jupyter() -> bool: # pragma: no cover
return False return False
ipython = get_ipython() # type: ignore[name-defined] ipython = get_ipython() # type: ignore[name-defined]
shell = ipython.__class__.__name__ shell = ipython.__class__.__name__
if "google.colab" in str(ipython.__class__) or shell == "ZMQInteractiveShell": if (
"google.colab" in str(ipython.__class__)
or os.getenv("DATABRICKS_ROOT_VIRTUALENV_ENV")
or shell == "ZMQInteractiveShell"
):
return True # Jupyter notebook or qtconsole return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell": elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython return False # Terminal running IPython