Coverage for install/scipp/utils/pyshell.py: 0%

7 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-17 01:51 +0000

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Jan-Lukas Wynen 

4 

5 

6def running_in_jupyter() -> bool: 

7 """ 

8 Detect whether Python is running in Jupyter. 

9 

10 Note that this includes not only Jupyter notebooks 

11 but also Jupyter console and qtconsole. 

12 """ 

13 try: 

14 import ipykernel.zmqshell 

15 from IPython import get_ipython # type: ignore[attr-defined] 

16 except ImportError: 

17 # Cannot be Jupyter if IPython is not installed. 

18 return False 

19 

20 return isinstance( 

21 get_ipython(), # type: ignore[no-untyped-call] 

22 ipykernel.zmqshell.ZMQInteractiveShell, 

23 )