Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SafetyQuincyF committed Oct 31, 2024
1 parent bac03cc commit ce77001
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions safety/auth/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import lru_cache
from IPython import get_ipython
import json
import logging
from typing import Any, Optional, Dict, Callable, Tuple
Expand Down Expand Up @@ -433,12 +432,15 @@ def send(self, request: requests.PreparedRequest, **kwargs: Any) -> requests.Res
def is_jupyter_notebook() -> bool:
"""
Check if the code is being executed inside a Jupyter Notebook.
Returns:
bool: True if running in a Jupyter notebook, False otherwise.
"""
try:
ipython_instance = get_ipython()
return 'IPKernelApp' in ipython_instance.config
except (ImportError, AttributeError):
from IPython import get_ipython
shell = get_ipython()
# Check for the presence of 'IPKernelApp', indicating a Jupyter notebook environment.
return 'IPKernelApp' in shell.config
except (NameError, AttributeError):
# IPython is not available or has no `config` attribute; likely not a notebook.
return False

0 comments on commit ce77001

Please sign in to comment.