MCPcopy
hub / github.com/p-e-w/heretic / is_notebook

Function is_notebook

src/heretic/utils.py:70–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68
69
70def is_notebook() -> bool:
71 # Check for specific environment variables (Colab, Kaggle).
72 # This is necessary because when running as a subprocess (e.g. !heretic),
73 # get_ipython() might not be available or might not reflect the notebook environment.
74 if os.getenv("COLAB_GPU") or os.getenv("KAGGLE_KERNEL_RUN_TYPE"):
75 return True
76
77 # Check IPython shell type (for library usage).
78 try:
79 from IPython import get_ipython # ty:ignore[unresolved-import]
80
81 shell = get_ipython()
82 if shell is None:
83 return False
84
85 shell_name = shell.__class__.__name__
86 if shell_name in ["ZMQInteractiveShell", "Shell"]:
87 return True
88
89 if "google.colab" in str(shell.__class__):
90 return True
91
92 return False
93 except (ImportError, NameError, AttributeError):
94 return False
95
96
97def prompt_select(message: str, choices: list[Any]) -> Any:

Callers 4

prompt_selectFunction · 0.85
prompt_textFunction · 0.85
prompt_pathFunction · 0.85
prompt_passwordFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected