Skip to content

Commit

Permalink
Don't call get_ipython during import
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Oct 15, 2024
1 parent 5a56925 commit 24e0009
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pyviz_comms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
import traceback
import json
import builtins

try:
from StringIO import StringIO
Expand All @@ -24,13 +25,10 @@ def _jupyter_labextension_paths():
'dest': data['name']
}]

try:
get_ipython()
except NameError:
get_ipython = None
_in_ipython = hasattr(builtins, '__IPYTHON__')

# Setting this so we can check the launched jupyter has pyviz_comms installed
if not (get_ipython and sys.argv[0].endswith('ipykernel_launcher.py')):
if not (_in_ipython and sys.argv[0].endswith('ipykernel_launcher.py')):
os.environ['_PYVIZ_COMMS_INSTALLED'] = '1'

# nb_mime_js is used to enable the necessary mime type support in classic notebook
Expand All @@ -56,14 +54,12 @@ class extension(param.ParameterizedFunction):
_repeat_execution_in_cell = False

def __new__(cls, *args, **kwargs):
try:
exec_count = get_ipython().execution_count
if _in_ipython:
exec_count = get_ipython().execution_count # noqa: F821
extension._repeat_execution_in_cell = (exec_count == cls._last_execution_count)
# Update the last count on this base class only so that every new instance
# creation obtains the updated count.
extension._last_execution_count = exec_count
except Exception:
pass
return param.ParameterizedFunction.__new__(cls, *args, **kwargs)

@classmethod
Expand Down

0 comments on commit 24e0009

Please sign in to comment.