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 046437b
Showing 1 changed file with 99 additions and 96 deletions.
195 changes: 99 additions & 96 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 Down Expand Up @@ -200,46 +155,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 @@ -304,28 +291,44 @@ 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']

# Only step if the location changed
if (fname, lineno) != self._pdb_frame_loc:
self.sig_pdb_step.emit(fname, lineno)

self._pdb_frame_loc = (fname, 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

if 'namespace_view' in pdb_state:
self.set_namespace_view(pdb_state['namespace_view'])
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()

if 'var_properties' in pdb_state:
self.set_var_properties(pdb_state['var_properties'])
return
if not self._executing:
# Only execute if not executing
return super(DebuggingWidget, self).execute(
source, hidden, interactive)

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

0 comments on commit 046437b

Please sign in to comment.