From 3f6eceb74fd9cd5bb9a8b18e26a32d52f1f92f96 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 Jul 2012 19:10:01 +0530 Subject: [PATCH] Remove dependency on IPython --- setup/installer/linux/freeze2.py | 2 +- setup/installer/osx/app/main.py | 4 -- setup/installer/windows/notes.rst | 2 +- src/calibre/utils/ipython.py | 80 +++++-------------------------- 4 files changed, 14 insertions(+), 74 deletions(-) diff --git a/setup/installer/linux/freeze2.py b/setup/installer/linux/freeze2.py index 4fa7e4fc47..2aa5504bc6 100644 --- a/setup/installer/linux/freeze2.py +++ b/setup/installer/linux/freeze2.py @@ -12,7 +12,7 @@ import sys, os, shutil, platform, subprocess, stat, py_compile, glob, \ from setup import Command, modules, basenames, functions, __version__, \ __appname__ -SITE_PACKAGES = ['IPython', 'PIL', 'dateutil', 'dns', 'PyQt4', 'mechanize', +SITE_PACKAGES = ['PIL', 'dateutil', 'dns', 'PyQt4', 'mechanize', 'sip.so', 'BeautifulSoup.py', 'cssutils', 'encutils', 'lxml', 'sipconfig.py', 'xdg', 'dbus', '_dbus_bindings.so', 'dbus_bindings.py', '_dbus_glib_bindings.so'] diff --git a/setup/installer/osx/app/main.py b/setup/installer/osx/app/main.py index 7a600287e3..8898cae4fa 100644 --- a/setup/installer/osx/app/main.py +++ b/setup/installer/osx/app/main.py @@ -483,10 +483,6 @@ class Py2App(object): shutil.rmtree(tdir) shutil.rmtree(os.path.join(self.site_packages, 'calibre', 'plugins')) self.remove_bytecode(join(self.resources_dir, 'Python', 'site-packages')) - # Create dummy IPython README_STARTUP - with open(join(self.site_packages, - 'IPython/config/profile/README_STARTUP'), 'wb') as f: - f.write('\n') @flush def add_modules_from_dir(self, src): diff --git a/setup/installer/windows/notes.rst b/setup/installer/windows/notes.rst index 91d658cfe2..8cf55cef78 100644 --- a/setup/installer/windows/notes.rst +++ b/setup/installer/windows/notes.rst @@ -30,7 +30,7 @@ If there are no windows binaries already compiled for the version of python you Run the following command to install python dependencies:: - easy_install --always-unzip -U ipython mechanize pyreadline python-dateutil dnspython cssutils clientform pycrypto + easy_install --always-unzip -U mechanize pyreadline python-dateutil dnspython cssutils clientform pycrypto Install BeautifulSoup 3.0.x manually into site-packages (3.1.x parses broken HTML very poorly) diff --git a/src/calibre/utils/ipython.py b/src/calibre/utils/ipython.py index d53a74a5c2..20e8c5160c 100644 --- a/src/calibre/utils/ipython.py +++ b/src/calibre/utils/ipython.py @@ -7,84 +7,29 @@ __license__ = 'GPL v3' __copyright__ = '2012, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import sys, os +import os from calibre.constants import iswindows, config_dir, get_version ipydir = os.path.join(config_dir, ('_' if iswindows else '.')+'ipython') -def old_ipython(user_ns=None): # {{{ - old_argv = sys.argv - sys.argv = ['ipython'] - if user_ns is None: - user_ns = locals() - os.environ['IPYTHONDIR'] = ipydir - if not os.path.exists(ipydir): - os.makedirs(ipydir) - for x in ('', '.ini'): - rc = os.path.join(ipydir, 'ipythonrc'+x) - if not os.path.exists(rc): - open(rc, 'wb').write(' ') - UC = ''' -import IPython.ipapi -ip = IPython.ipapi.get() +BANNER = ('Welcome to the interactive calibre shell!\n') -# You probably want to uncomment this if you did %upgrade -nolegacy -import ipy_defaults +def simple_repl(user_ns={}): + try: + import readline + readline + except ImportError: + pass -import os, re, sys - -def main(): - # Handy tab-completers for %cd, %run, import etc. - # Try commenting this out if you have completion problems/slowness - import ipy_stock_completers - - # uncomment if you want to get ipython -p sh behaviour - # without having to use command line switches - - import ipy_profile_sh - - - # Configure your favourite editor? - # Good idea e.g. for %edit os.path.isfile - - import ipy_editors - - # Choose one of these: - - #ipy_editors.scite() - #ipy_editors.scite('c:/opt/scite/scite.exe') - #ipy_editors.komodo() - #ipy_editors.idle() - # ... or many others, try 'ipy_editors??' after import to see them - - # Or roll your own: - #ipy_editors.install_editor("c:/opt/jed +$line $file") - - ipy_editors.kate() - - o = ip.options - # An example on how to set options - #o.autocall = 1 - o.system_verbose = 0 - o.confirm_exit = 0 - -main() - ''' - uc = os.path.join(ipydir, 'ipy_user_conf.py') - if not os.path.exists(uc): - open(uc, 'wb').write(UC) - from IPython.Shell import IPShellEmbed - ipshell = IPShellEmbed(user_ns=user_ns) - ipshell() - sys.argv = old_argv -# }}} + import code + code.interact(BANNER, raw_input, user_ns) def ipython(user_ns=None): try: import IPython from IPython.config.loader import Config except ImportError: - return old_ipython(user_ns=user_ns) + return simple_repl(user_ns=user_ns) if not user_ns: user_ns = {} c = Config() @@ -97,8 +42,7 @@ def ipython(user_ns=None): r'{color.Green}|\#> '%get_version()) c.PromptManager.in2_template = r'{color.Green}|{color.LightGreen}\D{color.Green}> ' c.PromptManager.out_template = r'<\#> ' - c.TerminalInteractiveShell.banner1 = ('Welcome to the interactive calibre' - ' shell!\n\n') + c.TerminalInteractiveShell.banner1 = BANNER c.PromptManager.justify = True c.TerminalIPythonApp.ipython_dir = ipydir os.environ['IPYTHONDIR'] = ipydir