Check if we're running in a Jupyter notebook.
()
| 503 | |
| 504 | |
| 505 | def _is_jupyter() -> bool: # pragma: no cover |
| 506 | """Check if we're running in a Jupyter notebook.""" |
| 507 | try: |
| 508 | get_ipython # type: ignore[name-defined] |
| 509 | except NameError: |
| 510 | return False |
| 511 | ipython = get_ipython() # type: ignore[name-defined] |
| 512 | shell = ipython.__class__.__name__ |
| 513 | if ( |
| 514 | "google.colab" in str(ipython.__class__) |
| 515 | or os.getenv("DATABRICKS_RUNTIME_VERSION") |
| 516 | or shell == "ZMQInteractiveShell" |
| 517 | ): |
| 518 | return True # Jupyter notebook or qtconsole |
| 519 | elif shell == "TerminalInteractiveShell": |
| 520 | return False # Terminal running IPython |
| 521 | else: |
| 522 | return False # Other type (?) |
| 523 | |
| 524 | |
| 525 | COLOR_SYSTEMS = { |