Skip to content

Commit

Permalink
shuffle functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed May 22, 2020
1 parent c4d9d8f commit df406e9
Showing 1 changed file with 139 additions and 136 deletions.
275 changes: 139 additions & 136 deletions spyder/plugins/ipythonconsole/widgets/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ def __init__(self, *args, **kwargs):
super(DebuggingWidget, self).__init__(*args, **kwargs)

# --- Public API --------------------------------------------------
def set_spyder_breakpoints(self):
"""Set Spyder breakpoints into a debugging session"""
self.call_kernel(interrupt=True).set_breakpoints(
CONF.get('run', 'breakpoints', {}))

def set_pdb_ignore_lib(self):
"""Set pdb_ignore_lib into a debugging session"""
self.call_kernel(interrupt=True).set_pdb_ignore_lib(
CONF.get('run', 'pdb_ignore_lib', False))

def will_close(self, externally_managed):
"""
Expand All @@ -67,43 +58,7 @@ def will_close(self, externally_managed):
except AttributeError:
pass

def set_pdb_execute_events(self):
"""Set pdb_execute_events into a debugging session"""
self.call_kernel(interrupt=True).set_pdb_execute_events(
CONF.get('run', 'pdb_execute_events', False))

def get_pdb_last_step(self):
"""Get last pdb step retrieved from a Pdb session."""
fname, lineno = self._pdb_frame_loc
if fname is None:
return {}
return {'fname': fname,
'lineno': lineno}

def is_debugging(self):
"""Check if we are debugging."""
return self._pdb_in_loop

def is_waiting_pdb_input(self):
"""Check if we are waiting a pdb input."""
# If the comm is not open, self._pdb_in_loop can not be set
return self._pdb_in_loop and self._waiting_pdb_input

# --- Comm API --------------------------------------------------
def set_pdb_state(self, pdb_state):
"""Set current pdb state."""
if pdb_state is not None and isinstance(pdb_state, dict):
self._refresh_from_pdb(pdb_state)

def get_pdb_settings(self):
"""Get pdb settings"""
return {
"breakpoints": CONF.get('run', 'breakpoints', {}),
"pdb_ignore_lib": CONF.get(
'run', 'pdb_ignore_lib', False),
"pdb_execute_events": CONF.get(
'run', 'pdb_execute_events', False),
}

def set_debug_state(self, is_debugging):
"""Update the debug state."""
Expand All @@ -120,44 +75,6 @@ def set_debug_state(self, is_debugging):

self.sig_pdb_state.emit(self._pdb_in_loop, self.get_pdb_last_step())

def pdb_input(self, prompt, password=None):
"""Get input for a command."""
if self._hidden:
raise RuntimeError(
'Request for pdb input during hidden execution.')

self._update_pdb_prompt(prompt, password)

# The prompt should be printed unless:
# 1. The prompt is already printed (self._reading is True)
# 2. A hidden command is in the queue
print_prompt = (not self._reading
and (len(self._pdb_input_queue) == 0
or not self._pdb_input_queue[0][1]))

if print_prompt:
# Make sure that all output from the SUB channel has been processed
# before writing a new prompt.
self.kernel_client.iopub_channel.flush()
self._waiting_pdb_input = True
self._readline(prompt=prompt, callback=self._pdb_readline_callback,
password=password)
self._executing = False
self._highlighter.highlighting_on = True
# The previous code finished executing
self.executed.emit(self._pdb_prompt)

self._pdb_input_ready = True

# While the widget thinks only one input is going on,
# other functions can be sending messages to the kernel.
# This must be properly processed to avoid dropping messages.
# If the kernel was not ready, the messages are queued.
if len(self._pdb_input_queue) > 0:
args = self._pdb_input_queue.pop(0)
self.pdb_execute(*args)
return

def pdb_execute(self, line, hidden=False, echo_stack_entry=True):
"""Send line to the pdb kernel if possible."""
if not line.strip():
Expand Down Expand Up @@ -200,46 +117,78 @@ def pdb_execute(self, line, hidden=False, echo_stack_entry=True):

self._pdb_input_queue.append((line, hidden, echo_stack_entry))

# ---- Public API (overrode by us) ----------------------------
def execute(self, source=None, hidden=False, interactive=False):
def get_pdb_settings(self):
"""Get pdb settings"""
return {
"breakpoints": CONF.get('run', 'breakpoints', {}),
"pdb_ignore_lib": CONF.get(
'run', 'pdb_ignore_lib', False),
"pdb_execute_events": CONF.get(
'run', 'pdb_execute_events', False),
}

# --- To Sort --------------------------------------------------
def set_spyder_breakpoints(self):
"""Set Spyder breakpoints into a debugging session"""
self.call_kernel(interrupt=True).set_breakpoints(
CONF.get('run', 'breakpoints', {}))

def set_pdb_ignore_lib(self):
"""Set pdb_ignore_lib into a debugging session"""
self.call_kernel(interrupt=True).set_pdb_ignore_lib(
CONF.get('run', 'pdb_ignore_lib', False))

def set_pdb_execute_events(self):
"""Set pdb_execute_events into a debugging session"""
self.call_kernel(interrupt=True).set_pdb_execute_events(
CONF.get('run', 'pdb_execute_events', False))

def _refresh_from_pdb(self, pdb_state):
"""
Executes source or the input buffer, possibly prompting for more
input.
Refresh Variable Explorer and Editor from a Pdb session,
after running any pdb command.
Do not use to run pdb commands (such as `continue`).
Use pdb_execute instead. This will add a '!' in front of the code.
See publish_pdb_state and notify_spyder in spyder_kernels
"""
if self.is_waiting_pdb_input():
if source is None:
if hidden:
# Nothing to execute
return
else:
source = self.input_buffer
else:
if source and source[0] != "!":
source = '!' + source
if not hidden:
self.input_buffer = source
if 'step' in pdb_state and 'fname' in pdb_state['step']:
fname = pdb_state['step']['fname']
lineno = pdb_state['step']['lineno']

if interactive:
# Add a continuation propt if not complete
complete, indent = self._is_pdb_complete(source)
if not complete:
self.do_execute(source, complete, indent)
return
if hidden:
self.pdb_execute(source, hidden)
else:
if self._reading_callback:
self._reading_callback()
# Only step if the location changed
if (fname, lineno) != self._pdb_frame_loc:
self.sig_pdb_step.emit(fname, lineno)

return
if not self._executing:
# Only execute if not executing
return super(DebuggingWidget, self).execute(
source, hidden, interactive)
self._pdb_frame_loc = (fname, lineno)

if 'namespace_view' in pdb_state:
self.set_namespace_view(pdb_state['namespace_view'])

if 'var_properties' in pdb_state:
self.set_var_properties(pdb_state['var_properties'])

def set_pdb_state(self, pdb_state):
"""Set current pdb state."""
if pdb_state is not None and isinstance(pdb_state, dict):
self._refresh_from_pdb(pdb_state)

def get_pdb_last_step(self):
"""Get last pdb step retrieved from a Pdb session."""
fname, lineno = self._pdb_frame_loc
if fname is None:
return {}
return {'fname': fname,
'lineno': lineno}

def is_debugging(self):
"""Check if we are debugging."""
return self._pdb_in_loop

def is_waiting_pdb_input(self):
"""Check if we are waiting a pdb input."""
# If the comm is not open, self._pdb_in_loop can not be set
return self._pdb_in_loop and self._waiting_pdb_input

# ---- Public API (overrode by us) ----------------------------
def reset(self, clear=False):
"""
Resets the widget to its initial state if ``clear`` parameter
Expand Down Expand Up @@ -285,10 +234,6 @@ def _update_pdb_prompt(self, prompt, password):
.format(re.escape(self.other_output_prefix), re.escape(prompt)))
self._pdb_prompt = (prompt, password)

def _pdb_readline_callback(self, line):
"""Callback used when the user inputs text in pdb."""
self.pdb_execute(line, echo_stack_entry=True)

def _is_pdb_complete(self, source):
"""
Check if the pdb input is ready to be executed.
Expand All @@ -304,28 +249,86 @@ def _is_pdb_complete(self, source):
indent = indent * ' '
return complete != 'incomplete', indent

def _refresh_from_pdb(self, pdb_state):
def execute(self, source=None, hidden=False, interactive=False):
"""
Refresh Variable Explorer and Editor from a Pdb session,
after running any pdb command.
Executes source or the input buffer, possibly prompting for more
input.
See publish_pdb_state and notify_spyder in spyder_kernels
Do not use to run pdb commands (such as `continue`).
Use pdb_execute instead. This will add a '!' in front of the code.
"""
if 'step' in pdb_state and 'fname' in pdb_state['step']:
fname = pdb_state['step']['fname']
lineno = pdb_state['step']['lineno']
if self.is_waiting_pdb_input():
if source is None:
if hidden:
# Nothing to execute
return
else:
source = self.input_buffer
else:
if source and source[0] != "!":
source = '!' + source
if not hidden:
self.input_buffer = source

# Only step if the location changed
if (fname, lineno) != self._pdb_frame_loc:
self.sig_pdb_step.emit(fname, lineno)
if interactive:
# Add a continuation propt if not complete
complete, indent = self._is_pdb_complete(source)
if not complete:
self.do_execute(source, complete, indent)
return
if hidden:
self.pdb_execute(source, hidden)
else:
if self._reading_callback:
self._reading_callback()

self._pdb_frame_loc = (fname, lineno)
return
if not self._executing:
# Only execute if not executing
return super(DebuggingWidget, self).execute(
source, hidden, interactive)

if 'namespace_view' in pdb_state:
self.set_namespace_view(pdb_state['namespace_view'])
def _pdb_readline_callback(self, line):
"""Callback used when the user inputs text in pdb."""
self.pdb_execute(line, echo_stack_entry=True)

if 'var_properties' in pdb_state:
self.set_var_properties(pdb_state['var_properties'])
def pdb_input(self, prompt, password=None):
"""Get input for a command."""
if self._hidden:
raise RuntimeError(
'Request for pdb input during hidden execution.')

self._update_pdb_prompt(prompt, password)

# The prompt should be printed unless:
# 1. The prompt is already printed (self._reading is True)
# 2. A hidden command is in the queue
print_prompt = (not self._reading
and (len(self._pdb_input_queue) == 0
or not self._pdb_input_queue[0][1]))

if print_prompt:
# Make sure that all output from the SUB channel has been processed
# before writing a new prompt.
self.kernel_client.iopub_channel.flush()
self._waiting_pdb_input = True
self._readline(prompt=prompt, callback=self._pdb_readline_callback,
password=password)
self._executing = False
self._highlighter.highlighting_on = True
# The previous code finished executing
self.executed.emit(self._pdb_prompt)

self._pdb_input_ready = True

# While the widget thinks only one input is going on,
# other functions can be sending messages to the kernel.
# This must be properly processed to avoid dropping messages.
# If the kernel was not ready, the messages are queued.
if len(self._pdb_input_queue) > 0:
args = self._pdb_input_queue.pop(0)
self.pdb_execute(*args)
return

# --- Private API (overrode by us) ----------------------------------------
def _show_prompt(self, prompt=None, html=False, newline=True):
Expand Down

0 comments on commit df406e9

Please sign in to comment.