Coverage for haystack/utils/jupyter.py: 67%

9 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-21 13:53 +0000

1# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai> 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4 

5 

6def is_in_jupyter() -> bool: 

7 """ 

8 Returns `True` if in Jupyter or Google Colab, `False` otherwise. 

9 """ 

10 # Inspired by: 

11 # https://github.com/explosion/spaCy/blob/e1249d3722765aaca56f538e830add7014d20e2a/spacy/util.py#L1079 

12 try: 

13 # We don't need to import `get_ipython` as it's always present in Jupyter notebooks 

14 if get_ipython().__class__.__name__ == "ZMQInteractiveShell": # type: ignore[name-defined] 

15 return True # Jupyter notebook or qtconsole 

16 if get_ipython().__class__.__module__ == "google.colab._shell": # type: ignore[name-defined] 

17 return True # Colab notebook 

18 except NameError: 

19 pass # Probably standard Python interpreter 

20 return False