From 9d1090091f52764e0070932e82151492f56cafe8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 29 Aug 2018 09:36:34 +0530 Subject: [PATCH] Add help() to the simple repl Fixes #1789533 [enhancements to the calibre-debug enviroment](https://bugs.launchpad.net/calibre/+bug/1789533) --- src/calibre/utils/ipython.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/calibre/utils/ipython.py b/src/calibre/utils/ipython.py index 2017a59013..7685d2e062 100644 --- a/src/calibre/utils/ipython.py +++ b/src/calibre/utils/ipython.py @@ -153,6 +153,17 @@ class Exit: 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={}): if iswindows: setup_pyreadline() @@ -169,6 +180,7 @@ def simple_repl(user_ns={}): for x in ('os', 'sys', 're'): user_ns[x] = user_ns.get(x, globals().get(x, locals().get(x))) user_ns['exit'] = Exit() + user_ns['help'] = Helper() from code import InteractiveConsole console = InteractiveConsole(user_ns) 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): + return simple_repl(user_ns=user_ns) os.environ['IPYTHONDIR'] = ipydir try: from IPython.terminal.embed import InteractiveShellEmbed