Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for interactive environment testing #84

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions cellarium/cas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@ def is_interactive_environment() -> bool:

:return: True if the current environment is interactive, False otherwise
"""
import sys

import __main__

# Check if running in an interactive shell (e.g., IPython, Jupyter)
if hasattr(sys, "ps1"):
return True
# Check if running in a context without a '__file__' attribute, typical of interactive environments
if not hasattr(__main__, "__file__"):
return True
# Check specific interactive environment conditions
try:
# Check if running in IPython or Jupyter by checking the module name
from IPython import get_ipython

if "IPKernelApp" not in get_ipython().config:
# Running in a non-interactive environment.
return False
else:
if "terminal" in get_ipython().config["IPKernelApp"]["connection_file"]:
# Running in an IPython terminal
return True
else:
# Running in a Jupyter environment.
return True
except (ImportError, AttributeError):
# Running in a non-interactive environment.
return False
shell = get_ipython().__class__.__name__
if shell in ["ZMQInteractiveShell", "TerminalInteractiveShell"]:
return True
except NameError:
pass
return False
Loading