Skip to content

Commit

Permalink
Resolve more circular dependencies in rascal.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
max-veit committed Mar 23, 2021
1 parent 2b6b4ab commit 3fd4b5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
25 changes: 6 additions & 19 deletions bindings/rascal/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,14 @@
dump_obj,
load_obj,
)
from .misc import is_notebook

# Warning potential dependency loop: FPS imports models, which imports KRR,
# which imports this file again
from .fps import fps, FPSFilter

# function to redirect c++'s standard output to python's one
from ..lib._rascal.utils import ostream_redirect
from ..lib import utils
from copy import deepcopy
from .cur import CURFilter
from .scorer import get_score, print_score

# function to redirect c++'s standard output to python's one
ostream_redirect = utils.__dict__["ostream_redirect"]


def is_notebook():
from IPython import get_ipython

try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
17 changes: 17 additions & 0 deletions bindings/rascal/utils/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Miscellaneous useful utilities"""


def is_notebook():
"""Is this being run inside an IPython Notebook?"""
from IPython import get_ipython

try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter

0 comments on commit 3fd4b5c

Please sign in to comment.