Remove dependency on IPython

This commit is contained in:
Kovid Goyal 2012-07-09 19:10:01 +05:30
parent f9b221461c
commit 3f6eceb74f
4 changed files with 14 additions and 74 deletions

View File

@ -12,7 +12,7 @@ import sys, os, shutil, platform, subprocess, stat, py_compile, glob, \
from setup import Command, modules, basenames, functions, __version__, \ from setup import Command, modules, basenames, functions, __version__, \
__appname__ __appname__
SITE_PACKAGES = ['IPython', 'PIL', 'dateutil', 'dns', 'PyQt4', 'mechanize', SITE_PACKAGES = ['PIL', 'dateutil', 'dns', 'PyQt4', 'mechanize',
'sip.so', 'BeautifulSoup.py', 'cssutils', 'encutils', 'lxml', 'sip.so', 'BeautifulSoup.py', 'cssutils', 'encutils', 'lxml',
'sipconfig.py', 'xdg', 'dbus', '_dbus_bindings.so', 'dbus_bindings.py', 'sipconfig.py', 'xdg', 'dbus', '_dbus_bindings.so', 'dbus_bindings.py',
'_dbus_glib_bindings.so'] '_dbus_glib_bindings.so']

View File

@ -483,10 +483,6 @@ class Py2App(object):
shutil.rmtree(tdir) shutil.rmtree(tdir)
shutil.rmtree(os.path.join(self.site_packages, 'calibre', 'plugins')) shutil.rmtree(os.path.join(self.site_packages, 'calibre', 'plugins'))
self.remove_bytecode(join(self.resources_dir, 'Python', 'site-packages')) 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 @flush
def add_modules_from_dir(self, src): def add_modules_from_dir(self, src):

View File

@ -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:: 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) Install BeautifulSoup 3.0.x manually into site-packages (3.1.x parses broken HTML very poorly)

View File

@ -7,84 +7,29 @@ __license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import sys, os import os
from calibre.constants import iswindows, config_dir, get_version from calibre.constants import iswindows, config_dir, get_version
ipydir = os.path.join(config_dir, ('_' if iswindows else '.')+'ipython') ipydir = os.path.join(config_dir, ('_' if iswindows else '.')+'ipython')
def old_ipython(user_ns=None): # {{{ BANNER = ('Welcome to the interactive calibre shell!\n')
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()
# You probably want to uncomment this if you did %upgrade -nolegacy def simple_repl(user_ns={}):
import ipy_defaults try:
import readline
readline
except ImportError:
pass
import os, re, sys import code
code.interact(BANNER, raw_input, user_ns)
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
# }}}
def ipython(user_ns=None): def ipython(user_ns=None):
try: try:
import IPython import IPython
from IPython.config.loader import Config from IPython.config.loader import Config
except ImportError: except ImportError:
return old_ipython(user_ns=user_ns) return simple_repl(user_ns=user_ns)
if not user_ns: if not user_ns:
user_ns = {} user_ns = {}
c = Config() c = Config()
@ -97,8 +42,7 @@ def ipython(user_ns=None):
r'{color.Green}|\#> '%get_version()) r'{color.Green}|\#> '%get_version())
c.PromptManager.in2_template = r'{color.Green}|{color.LightGreen}\D{color.Green}> ' c.PromptManager.in2_template = r'{color.Green}|{color.LightGreen}\D{color.Green}> '
c.PromptManager.out_template = r'<\#> ' c.PromptManager.out_template = r'<\#> '
c.TerminalInteractiveShell.banner1 = ('Welcome to the interactive calibre' c.TerminalInteractiveShell.banner1 = BANNER
' shell!\n\n')
c.PromptManager.justify = True c.PromptManager.justify = True
c.TerminalIPythonApp.ipython_dir = ipydir c.TerminalIPythonApp.ipython_dir = ipydir
os.environ['IPYTHONDIR'] = ipydir os.environ['IPYTHONDIR'] = ipydir