update yap_kernel
lbfgs
This commit is contained in:
Vitor Santos Costa
2018-10-15 13:48:49 +01:00
parent 127ebb2523
commit b31493c777
26 changed files with 1721 additions and 1591 deletions

View File

@@ -3,20 +3,19 @@ import sys
from yap_ipython.core.debugger import Pdb
from yap_ipython.yapi import YAPCompleter
#from .ptutils import IPythonPTCompleter
from yap_ipython.core.completer import IPCompleter
from .ptutils import IPythonPTCompleter
from .shortcuts import suspend_to_bg, cursor_in_leading_ws
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import (Condition, HasFocus, HasSelection,
ViInsertMode, EmacsInsertMode)
from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.filters import (Condition, has_focus, has_selection,
vi_insert_mode, emacs_insert_mode)
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
from prompt_toolkit.token import Token
from prompt_toolkit.shortcuts import create_prompt_application
from prompt_toolkit.interface import CommandLineInterface
from pygments.token import Token
from prompt_toolkit.shortcuts.prompt import PromptSession
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.formatted_text import PygmentsTokens
class TerminalPdb(Pdb):
@@ -26,46 +25,40 @@ class TerminalPdb(Pdb):
self.pt_init()
def pt_init(self):
def get_prompt_tokens(cli):
def get_prompt_tokens():
return [(Token.Prompt, self.prompt)]
def patch_stdout(**kwargs):
return self.pt_cli.patch_stdout_context(**kwargs)
if self._ptcomp is None:
compl = IPCompleter(shell=self.shell,
namespace={},
global_namespace={},
parent=self.shell,
)
self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)
self._ptcomp = IPythonPTCompleter(compl)
kbmanager = KeyBindingManager.for_prompt()
supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
)(suspend_to_bg)
kb = KeyBindings()
supports_suspend = Condition(lambda: hasattr(signal, 'SIGTSTP'))
kb.add('c-z', filter=supports_suspend)(suspend_to_bg)
if self.shell.display_completions == 'readlinelike':
kbmanager.registry.add_binding(Keys.ControlI,
filter=(HasFocus(DEFAULT_BUFFER)
& ~HasSelection()
& ViInsertMode() | EmacsInsertMode()
& ~cursor_in_leading_ws
))(display_completions_like_readline)
multicolumn = (self.shell.display_completions == 'multicolumn')
kb.add('tab', filter=(has_focus(DEFAULT_BUFFER)
& ~has_selection
& vi_insert_mode | emacs_insert_mode
& ~cursor_in_leading_ws
))(display_completions_like_readline)
self._pt_app = create_prompt_application(
self.pt_app = PromptSession(
message=(lambda: PygmentsTokens(get_prompt_tokens())),
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
key_bindings_registry=kbmanager.registry,
key_bindings=kb,
history=self.shell.debugger_history,
completer= self._ptcomp,
completer=self._ptcomp,
enable_history_search=True,
mouse_support=self.shell.mouse_support,
get_prompt_tokens=get_prompt_tokens,
display_completions_in_columns=multicolumn,
style=self.shell.style
complete_style=self.shell.pt_complete_style,
style=self.shell.style,
inputhook=self.shell.inputhook,
)
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -92,7 +85,7 @@ class TerminalPdb(Pdb):
self._ptcomp.ipy_completer.namespace = self.curframe_locals
self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
try:
line = self.pt_cli.run(reset_current_buffer=True).text
line = self.pt_app.prompt() # reset_current_buffer=True)
except EOFError:
line = 'EOF'
line = self.precmd(line)