Beispiel #1
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._eventloop = IOLoop.current()
        self._key = generate_id(size=32).encode('utf-8')
        self._execution_lock = Lock(loop=self._eventloop.asyncio_loop)
        self._inner_state_lock = Lock(loop=self._eventloop.asyncio_loop)
        self._dep_tracker = DependencyTracker()
        self._exec_unit_container = ExecUnitContainer()
        self.formatter = DisplayFormatter()
        self.manager_ns = BuiltInManager()
        self.manager_ns.global_ns['__builtins__'] = builtin_mods.__dict__
        self.manager_ns.global_ns['show_graph'] = self._show_graph
        self._execution_ctx = Executor(self._exec_unit_container,
                                       manager_ns=self.manager_ns)
        self.KernelTB = ultratb.AutoFormattedTB(mode='Plain',
                                                color_scheme='LightBG',
                                                tb_offset=1,
                                                debugger_cls=None)
        self._execution_queue = Queue(loop=self._eventloop.asyncio_loop)
        builtin_mods.show_graph = self._show_graph
        # mapping from variable name (target id) to (request id, generator
        # object)
        self._registered_generators = dict()

        self._eventloop.spawn_callback(self._execution_loop)
Beispiel #2
0
 def init_display_formatter(self):
     if INLINE_OUTPUT_SUPPORTED:
         self.display_formatter = DisplayFormatter(parent=self)
         self.configurables.append(self.display_formatter)
         self.display_formatter.ipython_display_formatter.enabled = True
     else:
         super(PyDevTerminalInteractiveShell, self).init_display_formatter()
Beispiel #3
0
def _acquire_formatter():
    try:
        # If the user is in ipython, get their configured display_formatter
        ip = get_ipython()  # NOQA
        return ip.display_formatter
    except NameError:
        # otherwise use the default
        return DisplayFormatter()
Beispiel #4
0
def postprocess(cell_outputs, saved_cell_outputs, verbose=True, cell_n=None):
    """Unify outputs and saved_outputs to make them comparable.

    Side effects:
    1) Print outputs
    2) Reinitiate logging object
    """
    if saved_cell_outputs is None:
        saved_cell_outputs = defaultdict(lambda: None)

    cell_outputs["stderr"], cell_outputs["stdout"] = (
        cell_outputs["stderr"].getvalue(),
        cell_outputs["stdout"].getvalue(),
    )
    if verbose:
        print(
            "-----> stderr of Cell %d:" % cell_n,
            cell_outputs["stderr"],
            "-----> stdout of Cell %d:" % cell_n,
            cell_outputs["stdout"],
            sep="\n",
        )
    root_logger = logging.getLogger()

    # Reinitiate the logging object
    for handl in root_logger.handlers:
        root_logger.removeHandler(handl)
    logging.basicConfig()

    if saved_cell_outputs["stdout"] is None:
        saved_cell_outputs["stdout"] = ""

    if saved_cell_outputs["stderr"] is None:
        saved_cell_outputs["stderr"] = ""

    cell_outputs["stderr"] = escape_ansi(cell_outputs["stderr"])

    if cell_outputs["display_data"] is None:
        cell_outputs["display_data"] = ""
    if saved_cell_outputs["display_data"] is None:
        saved_cell_outputs["display_data"] = "''"
        # elif isinstance(cell_outputs, str):
        #   cell_outputs = "'" + cell_outputs + "'"

    celltest_disp = DisplayFormatter()
    cell_outputs["display_data"] = celltest_disp.format(
        cell_outputs["display_data"], include="text/plain")[0]["text/plain"]

    return cell_outputs, saved_cell_outputs
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._key = generate_id(size=32).encode('utf-8')
        self._eventloop = IOLoop.current().asyncio_loop
        self._inner_state_lock = Lock(loop=self._eventloop)
        self._dep_tracker = DependencyTracker()
        self._exec_unit_container = ExecUnitContainer()
        self.formatter = DisplayFormatter()
        self.ns_manager = BuiltInManager()
        self.initialize_builtins()
        self._execution_ctx = Executor(self._exec_unit_container,
                                       ns_manager=self.ns_manager)
        self.KernelTB = ultratb.AutoFormattedTB(mode='Plain',
                                                color_scheme='LightBG',
                                                tb_offset=1,
                                                debugger_cls=None)

        # mapping from variable name (target id) to (request id, generator
        # object)
        self._registered_generators = dict()
Beispiel #6
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Ensure the kernel we work with uses Futures on recv, so we can await them
        self.context = ctx = Context.instance()

        # Our subscription to messages from the kernel we launch
        self.iosub = ctx.socket(zmq.SUB)
        self.iosub.subscribe = b""

        # From kernelapp.py, shell_streams are typically shell_stream, control_stream
        self.shell_stream = self.shell_streams[0]

        # Start with no child kernel
        self.child_kernel = None

        self.kernel_config = None

        self.acquiring_kernel = asyncio.Lock()
        self.kernel_launched = asyncio.Event()

        self.display_formatter = DisplayFormatter()
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import print_function

import matplotlib
from matplotlib.backends.backend_agg import new_figure_manager, FigureCanvasAgg  # analysis: ignore
from matplotlib._pylab_helpers import Gcf

from ipykernel.pylab.config import InlineBackend
from IPython.core.formatters import DisplayFormatter
from IPython.core.pylabtools import select_figure_formats
import IPython
import IPython.display
import IPython.core.display
df = DisplayFormatter()


# fake thing which select_figure_formats will work on
class qshell():
    def __init__(self, df=None):
        self.display_formatter = df


qpubcallback = None
qclearcallback = None
qipythoncallback = None
shell = qshell(df)
select_figure_formats(shell, {
    'png'
})  #,'svg','jpeg','pdf','retina'}) /more means multiple output mime types?
Beispiel #8
0
 def __init__(self, **k):
     # connect with kdb
     super().__init__(**k)
     self._formatter = DisplayFormatter()
Beispiel #9
0
def publish_to_display(obj):
    output, _ = DisplayFormatter().format(obj)
    publish_display_data(output)