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 85df65b commit 60dbecd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions safety/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,15 @@ def is_jupyter_notebook() -> bool:
try:
from IPython import get_ipython
shell = get_ipython()
# Check for the presence of 'IPKernelApp', indicating a Jupyter notebook environment.
return 'IPKernelApp' in shell.config

# Ensure that get_ipython() returned a valid shell instance
if shell is None:
return False

# Check for presence of 'IPKernelApp', indicating a Jupyter notebook environment.
# This excludes cases where IPython is used in non-notebook environments.
return shell.__class__.__name__ == 'ZMQInteractiveShell'

except (ImportError, NameError, AttributeError):
# IPython is not available or has no `config` attribute; likely not a notebook.
return False
# IPython is not available, or the shell instance lacks required attributes.
return False

0 comments on commit 60dbecd

Please sign in to comment.