How to use the ipykernel.zmqshell.ZMQInteractiveShell function in ipykernel

To help you get started, we’ve selected a few ipykernel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twosigma / beakerx / beakerx / beakerx_magics / groovy_magic.py View on Github external
def load_ipython_extension(ipython):
    if isinstance(ipython, ZMQInteractiveShell):
        ipython.register_magics(GroovyMagics)
github google / earthengine-api / python / ee / oauth.py View on Github external
def _in_jupyter_shell():
  """Tests if the code is being executed within Jupyter."""
  try:
    import ipykernel.zmqshell
    return isinstance(IPython.get_ipython(),
                      ipykernel.zmqshell.ZMQInteractiveShell)
  except ImportError:
    return False
  except NameError:
    return False
github ipython / ipykernel / ipykernel / zmqshell.py View on Github external
def init_magics(self):
        super(ZMQInteractiveShell, self).init_magics()
        self.register_magics(KernelMagics)
        self.magics_manager.register_alias('ed', 'edit')
github ipython / ipykernel / ipykernel / ipkernel.py View on Github external
except ImportError:
    _asyncio_runner = None

try:
    from IPython.core.completer import rectify_completions as _rectify_completions, provisionalcompleter as _provisionalcompleter
    _use_experimental_60_completion = True
except ImportError:
    _use_experimental_60_completion = False

_EXPERIMENTAL_KEY_NAME = '_jupyter_types_experimental'


class IPythonKernel(KernelBase):
    shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
                     allow_none=True)
    shell_class = Type(ZMQInteractiveShell)

    use_experimental_completions = Bool(True,
        help="Set this flag to False to deactivate the use of experimental IPython completion APIs.",
    ).tag(config=True)

    user_module = Any()
    def _user_module_changed(self, name, old, new):
        if self.shell is not None:
            self.shell.user_module = new

    user_ns = Instance(dict, args=None, allow_none=True)
    def _user_ns_changed(self, name, old, new):
        if self.shell is not None:
            self.shell.user_ns = new
            self.shell.init_user_ns()
github twosigma / beakerx / beakerx / beakerx_magics / clojure_magic.py View on Github external
def load_ipython_extension(ipython):
    if isinstance(ipython, ZMQInteractiveShell):
        ipython.register_magics(ClojureMagics)
github twosigma / beakerx / beakerx / beakerx_magics / kotlin_magic.py View on Github external
def load_ipython_extension(ipython):
    if isinstance(ipython, ZMQInteractiveShell):
        ipython.register_magics(KotlinMagics)
github h2oai / h2o-3 / h2o-py / h2o / display.py View on Github external
def _in_ipy():  # are we in ipy? then pretty print tables with _repr_html
        if H2ODisplay._jupyter is None:
            try:
                import IPython
                from ipykernel.zmqshell import ZMQInteractiveShell
                ipy = IPython.get_ipython()
                H2ODisplay._jupyter = isinstance(ipy, ZMQInteractiveShell)
            except ImportError:
                H2ODisplay._jupyter = False
        return H2ODisplay._jupyter
github krishnan-r / sparkmonitor / extension / sparkmonitor / kernelextension.py View on Github external
global logger
    logger = logging.getLogger("sparkmonitorkernel")
    logger.setLevel(logging.DEBUG)
    logger.propagate = False
    # For debugging this module - Writes logs to a file
    fh = logging.FileHandler("sparkmonitor_kernelextension.log", mode="w")
    fh.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        "%(levelname)s:  %(asctime)s - %(name)s - %(process)d - %(processName)s - \
        %(thread)d - %(threadName)s\n %(message)s \n")
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    if ipykernel_imported:
        if not isinstance(ipython, zmqshell.ZMQInteractiveShell):
            logger.warn(
                "SparkMonitor: Ipython not running through notebook. So exiting.")
            return
    else:
        return

    ip = ipython
    logger.info("Starting Kernel Extension")
    monitor = ScalaMonitor(ip)
    monitor.register_comm()  # Communication to browser
    monitor.start()

    # Injecting conf into users namespace
    if spark_imported:
        # Get conf if user already has a conf for appending
        conf = ipython.user_ns.get("conf")
github ipython / ipykernel / ipykernel / ipkernel.py View on Github external
from IPython.core import release
from ipython_genutils.py3compat import builtin_mod, PY3
from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
from traitlets import Instance, Type, Any, List

from .comm import CommManager
from .kernelbase import Kernel as KernelBase
from .serialize import serialize_object, unpack_apply_message
from .zmqshell import ZMQInteractiveShell


class IPythonKernel(KernelBase):
    shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
                     allow_none=True)
    shell_class = Type(ZMQInteractiveShell)

    user_module = Any()
    def _user_module_changed(self, name, old, new):
        if self.shell is not None:
            self.shell.user_module = new

    user_ns = Instance(dict, args=None, allow_none=True)
    def _user_ns_changed(self, name, old, new):
        if self.shell is not None:
            self.shell.user_ns = new
            self.shell.init_user_ns()

    # A reference to the Python builtin 'raw_input' function.
    # (i.e., __builtin__.raw_input for Python 2.7, builtins.input for Python 3)
    _sys_raw_input = Any()
    _sys_eval_input = Any()
github vscosta / yap-6.3 / packages / python / yap_kernel / yap_kernel.py View on Github external
"-m", "yap_kernel",
             "-f", "{connection_file}"],
    "display_name": " YAP-6.3",
    "language": "prolog",
    "name": "yap_kernel",
}


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


class YAPKernel(KernelBase):
    shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
                     allow_none=True)
    shell_class = Type(ZMQInteractiveShell )
    user_ns = Instance(dict, args=None, allow_none=True)
    def _user_ns_changed(self, name, old, new):
        if self.shell is not None:
            self.shell.user_ns = new
            self.shell.init_user_ns()

    # A reference to the Python builtin 'raw_input' function.
    # (i.e., __builtin__.raw_input for Python 2.7, builtins.input for Python 3)
    _sys_raw_input = Any()
    _sys_eval_input = Any()


    implementation = 'YAP Kernel'
    implementation_version = '1.0'
    language = 'text'
    language_version = '6.3'