()
| 68 | |
| 69 | |
| 70 | def 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 | |
| 97 | def prompt_select(message: str, choices: list[Any]) -> Any: |
no outgoing calls
no test coverage detected