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

PR: Print last line of Pdb code #17089

Merged
merged 13 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions external-deps/spyder-kernels/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/spyder-ide/spyder-kernels.git
branch = 2.x
commit = 7478e850164cbba0de8425110accf9cb1bb66249
parent = b2a48c91215f16f1f01c76789715bbfae8cc4506
commit = 8289aa80fd6ce20e57042e3be5502383c1c4fa11
parent = 2071cf210c6e8d79e27535b78b794a20ed4d57f8
method = merge
cmdver = 0.4.3
15 changes: 11 additions & 4 deletions external-deps/spyder-kernels/spyder_kernels/comms/frontendcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_free_port():
return port


def frontend_request(blocking=True, timeout=None):
def frontend_request(blocking, timeout=None):
"""
Send a request to the frontend.

Expand Down Expand Up @@ -261,8 +261,11 @@ def _remote_callback(self, call_name, call_args, call_kwargs):
"""Call the callback function for the remote call."""
saved_stdout_write = sys.stdout.write
saved_stderr_write = sys.stderr.write
sys.stdout.write = WriteWrapper(saved_stdout_write, call_name)
sys.stderr.write = WriteWrapper(saved_stderr_write, call_name)
thread_id = threading.get_ident()
sys.stdout.write = WriteWrapper(
saved_stdout_write, call_name, thread_id)
sys.stderr.write = WriteWrapper(
saved_stderr_write, call_name, thread_id)
try:
return super(FrontendComm, self)._remote_callback(
call_name, call_args, call_kwargs)
Expand All @@ -274,9 +277,10 @@ def _remote_callback(self, call_name, call_args, call_kwargs):
class WriteWrapper(object):
"""Wrapper to warn user when text is printed."""

def __init__(self, write, name):
def __init__(self, write, name, thread_id):
self._write = write
self._name = name
self._thread_id = thread_id
self._warning_shown = False

def is_benign_message(self, message):
Expand All @@ -293,6 +297,9 @@ def is_benign_message(self, message):

def __call__(self, string):
"""Print warning once."""
if self._thread_id != threading.get_ident():
return self._write(string)

if not self.is_benign_message(string):
if not self._warning_shown:
self._warning_shown = True
Expand Down
31 changes: 21 additions & 10 deletions external-deps/spyder-kernels/spyder_kernels/console/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Standard library imports
from distutils.version import LooseVersion
import logging
import os
import sys
import threading
Expand All @@ -22,9 +23,9 @@
from traitlets.config.loader import LazyConfigValue

# Local imports
from spyder_kernels.py3compat import TEXT_TYPES, to_text_string
from spyder_kernels.comms.frontendcomm import FrontendComm
from spyder_kernels.py3compat import PY3, input
from spyder_kernels.py3compat import (
TEXT_TYPES, to_text_string, PY3, input, TimeoutError)
from spyder_kernels.comms.frontendcomm import FrontendComm, CommError
from spyder_kernels.utils.iofuncs import iofunctions
from spyder_kernels.utils.mpl import (
MPL_BACKENDS_FROM_SPYDER, MPL_BACKENDS_TO_SPYDER, INLINE_FIGURE_FORMATS)
Expand All @@ -34,6 +35,10 @@
if PY3:
import faulthandler


logger = logging.getLogger(__name__)


# Excluded variables from the Variable Explorer (i.e. they are not
# shown at all there)
EXCLUDED_NAMES = ['In', 'Out', 'exit', 'get_ipython', 'quit']
Expand Down Expand Up @@ -88,7 +93,6 @@ def __init__(self, *args, **kwargs):
call_id, handlers[call_id])

self.namespace_view_settings = {}
self._pdb_step = None
self._mpl_backend_error = None
self._running_namespace = None
self._pdb_input_line = None
Expand Down Expand Up @@ -301,13 +305,20 @@ def do_complete(self, code, cursor_pos):
return self.shell.pdb_session.do_complete(code, cursor_pos)
return self._do_complete(code, cursor_pos)

def publish_pdb_state(self):
"""Publish Pdb state."""
if self.shell.pdb_session:
state = dict(namespace_view = self.get_namespace_view(),
var_properties = self.get_var_properties(),
step = self._pdb_step)
def publish_pdb_state(self, step):
"""
Publish Variable Explorer state and Pdb step through
send_spyder_msg.
"""
state = dict(
namespace_view=self.get_namespace_view(),
var_properties=self.get_var_properties(),
step=step
)
try:
self.frontend_call(blocking=False).pdb_state(state)
except (CommError, TimeoutError):
logger.debug("Could not send Pdb state to the frontend.")

def set_spyder_breakpoints(self, breakpoints):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NamespaceManager(object):
"""

def __init__(self, filename, namespace=None, current_namespace=False,
file_code=None):
file_code=None, stack_depth=1):
self.filename = filename
self.ns_globals = namespace
self.ns_locals = None
Expand All @@ -31,6 +31,9 @@ def __init__(self, filename, namespace=None, current_namespace=False,
self._previous_main = None
self._reset_main = False
self._file_code = file_code
ipython_shell = get_ipython()
self.context_globals = ipython_shell.get_global_scope(stack_depth + 1)
self.context_locals = ipython_shell.get_local_scope(stack_depth + 1)

def __enter__(self):
"""
Expand All @@ -40,10 +43,8 @@ def __enter__(self):
ipython_shell = get_ipython()
if self.ns_globals is None:
if self.current_namespace:
# stack_depth = parent of calling function
stack_depth = 2
self.ns_globals = ipython_shell.get_global_scope(stack_depth)
self.ns_locals = ipython_shell.get_local_scope(stack_depth)
self.ns_globals = self.context_globals
self.ns_locals = self.context_locals
if '__file__' in self.ns_globals:
self._previous_filename = self.ns_globals['__file__']
self.ns_globals['__file__'] = self.filename
Expand Down Expand Up @@ -92,13 +93,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.ns_globals.pop('__file__')

if not self.current_namespace:
# stack_depth = parent of calling function
stack_depth = 2
ns_globals = ipython_shell.get_global_scope(stack_depth)
ns_locals = ipython_shell.get_local_scope(stack_depth)
ns_globals.update(self.ns_globals)
if ns_locals and self.ns_locals:
ns_locals.update(self.ns_locals)
self.context_globals.update(self.ns_globals)
if self.context_locals and self.ns_locals:
self.context_locals.update(self.ns_locals)

if self._previous_main:
sys.modules['__main__'] = self._previous_main
Expand Down
Loading