mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add help() to the simple repl
Fixes #1789533 [enhancements to the calibre-debug enviroment](https://bugs.launchpad.net/calibre/+bug/1789533)
This commit is contained in:
parent
238c0c6c33
commit
9d1090091f
@ -153,6 +153,17 @@ class Exit:
|
|||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
|
|
||||||
|
class Helper(object):
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "Type help() for interactive help, " \
|
||||||
|
"or help(object) for help about object."
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwds):
|
||||||
|
import pydoc
|
||||||
|
return pydoc.help(*args, **kwds)
|
||||||
|
|
||||||
|
|
||||||
def simple_repl(user_ns={}):
|
def simple_repl(user_ns={}):
|
||||||
if iswindows:
|
if iswindows:
|
||||||
setup_pyreadline()
|
setup_pyreadline()
|
||||||
@ -169,6 +180,7 @@ def simple_repl(user_ns={}):
|
|||||||
for x in ('os', 'sys', 're'):
|
for x in ('os', 'sys', 're'):
|
||||||
user_ns[x] = user_ns.get(x, globals().get(x, locals().get(x)))
|
user_ns[x] = user_ns.get(x, globals().get(x, locals().get(x)))
|
||||||
user_ns['exit'] = Exit()
|
user_ns['exit'] = Exit()
|
||||||
|
user_ns['help'] = Helper()
|
||||||
from code import InteractiveConsole
|
from code import InteractiveConsole
|
||||||
console = InteractiveConsole(user_ns)
|
console = InteractiveConsole(user_ns)
|
||||||
console.runsource('from __future__ import (unicode_literals, division, absolute_import, print_function)')
|
console.runsource('from __future__ import (unicode_literals, division, absolute_import, print_function)')
|
||||||
@ -176,6 +188,7 @@ def simple_repl(user_ns={}):
|
|||||||
|
|
||||||
|
|
||||||
def ipython(user_ns=None):
|
def ipython(user_ns=None):
|
||||||
|
return simple_repl(user_ns=user_ns)
|
||||||
os.environ['IPYTHONDIR'] = ipydir
|
os.environ['IPYTHONDIR'] = ipydir
|
||||||
try:
|
try:
|
||||||
from IPython.terminal.embed import InteractiveShellEmbed
|
from IPython.terminal.embed import InteractiveShellEmbed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user