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 c778b44 commit 00f7f7e
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions safety/auth/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from functools import lru_cache
import json
import logging
import sys
from typing import Any, Optional, Dict, Callable, Tuple
from authlib.integrations.requests_client import OAuth2Session
from authlib.integrations.base_client.errors import OAuthError
Expand Down Expand Up @@ -430,24 +431,14 @@ def send(self, request: requests.PreparedRequest, **kwargs: Any) -> requests.Res

@lru_cache(maxsize=1)
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:
from IPython import get_ipython
shell = get_ipython()
if shell:
shell_name = shell.__class__.__name__
if shell_name == "ZMQInteractiveShell":
print("Running in a Jupyter Notebook!")
elif shell_name == "TerminalInteractiveShell":
print("Running in an IPython terminal!")
else:
print("Running in a different IPython environment!")
else:
print("Not running in an IPython environment.")
except ImportError:
print("IPython is not installed. Running in a standard Python environment.")
if shell and 'IPKernelApp' in shell.config:
# Detect Jupyter and Google Colab environments
return True
elif "google.colab" in sys.modules:
return True
except (ImportError, AttributeError):
return False
return False

0 comments on commit 00f7f7e

Please sign in to comment.