Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/nbclassic/__init__.py: 59%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

32 statements  

1import os 

2import sys 

3from ._version import __version__ 

4 

5 

6# Packagers: modify this line if you store the notebook static files elsewhere 

7DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static") 

8 

9 

10NOTEBOOK_V7_DETECTED = False 

11 

12# Notebook shim to ensure notebook extensions backwards compatiblity. 

13 

14try: 

15 from notebook._version import version_info as notebook_version_info 

16except Exception: 

17 notebook_version_info = None 

18 # No notebook python package found. 

19 # Shimming notebook to jupyter_server for notebook extensions backwards compatibility. 

20 # We shim the complete notebook module. 

21 import jupyter_server 

22 sys.modules["notebook"] = jupyter_server 

23 from jupyter_server.base import handlers 

24 from notebook.base import handlers as notebook_handlers 

25 handlers.IPythonHandler = handlers.JupyterHandler 

26 notebook_handlers.IPythonHandler = handlers.JupyterHandler 

27 

28if notebook_version_info is not None: 

29 # Notebook is available on the platform. 

30 # We shim based on the notebook version. 

31 if notebook_version_info >= (7,): 

32 NOTEBOOK_V7_DETECTED = True 

33 from .shim_notebook import shim_notebook 

34 # Shimming existing notebook python package > 6 to jupyter_server. 

35 # For notebook extensions backwards compatibility. 

36 shim_notebook() 

37 # Sanity check for the notebook shim. 

38 from jupyter_server.base.handlers import IPythonHandler as JupyterServerIPythonHandler 

39 assert JupyterServerIPythonHandler.__name__ == "JupyterHandler" 

40 from notebook.base.handlers import IPythonHandler as NotebookIPythonHandler 

41 assert NotebookIPythonHandler.__name__ == "JupyterHandler" or NotebookIPythonHandler.__name__ == "IPythonHandler" 

42 

43 

44# Include both nbclassic/ and nbclassic/templates/. This makes it 

45# possible for users to override a template with a file that inherits from that 

46# template. 

47# 

48# For example, if you want to override a specific block of notebook.html, you 

49# can create a file called notebook.html that inherits from 

50# templates/notebook.html, and the latter will resolve correctly to the base 

51# implementation. 

52DEFAULT_TEMPLATE_PATH_LIST = [ 

53 os.path.dirname(__file__), 

54 os.path.join(os.path.dirname(__file__), "templates"), 

55] 

56 

57 

58def nbclassic_path(): 

59 if NOTEBOOK_V7_DETECTED: 

60 return "/nbclassic" 

61 return "" 

62 

63def _jupyter_server_extension_paths(): 

64 # Locally import to avoid install errors. 

65 from .notebookapp import NotebookApp 

66 

67 return [ 

68 { 

69 'module': 'nbclassic.notebookapp', 

70 'app': NotebookApp, 

71 'name': 'jupyter-nbclassic' 

72 } 

73 ]