Merge lp:~jtaylor/ubuntu-dev-tools/lp-shell-ipython into lp:~ubuntu-dev/ubuntu-dev-tools/trunk

Proposed by Julian Taylor
Status: Merged
Merged at revision: 1116
Proposed branch: lp:~jtaylor/ubuntu-dev-tools/lp-shell-ipython
Merge into: lp:~ubuntu-dev/ubuntu-dev-tools/trunk
Diff against target: 138 lines (+60/-20)
4 files modified
debian/changelog (+5/-1)
debian/control (+1/-1)
doc/lp-shell.1 (+10/-0)
lp-shell (+44/-18)
To merge this branch: bzr merge lp:~jtaylor/ubuntu-dev-tools/lp-shell-ipython
Reviewer Review Type Date Requested Status
Stefano Rivera Approve
Review via email: mp+71488@code.launchpad.net

Description of the change

use ipython shell instead of normal python for lp-shell when it is available.
ipython is far better suited for interactive use:
http://ipython.org/ipython-doc/stable/interactive/reference.html#interactive-use

ipython is set to default, the regular python shell can be forced with --python

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

I like it!

"an ipython shell" surely :)

please take proper credit in the changelog (dch -a should have added your name)

I'd use "shell" instead of "mode" as the option name. Mode is very broad.

Revision history for this message
Stefano Rivera (stefanor) wrote :

I'd also re-enable that pylint check as soon as possible.

Revision history for this message
Julian Taylor (jtaylor) wrote :

I don't know how to avoid the pylint problem.
The nested try except works fine, but pylint does not seem to be able to handle it.

If ipython 0.11 is installed (available https://launchpad.net/~jtaylor/+archive/ipython-dev) it will error out with "IPython does not have name Shell", although that code is never executed with 0.11 available.
It gets it right when 0.10.2 is installed.

1121. By Julian Taylor

doc/lp-shell.1: fix typo

1122. By Julian Taylor

lp-shell: rename options.mode to options.shell

1123. By Julian Taylor

fix changelog

Revision history for this message
Stefano Rivera (stefanor) wrote :

I just mean throw in an enable-msg again afterwards.

Revision history for this message
Julian Taylor (jtaylor) wrote :

the disable annotation is scoped, its only valid for the except block

Revision history for this message
Stefano Rivera (stefanor) wrote :

oh, I didn't know it worked like that :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-07-25 17:37:30 +0000
3+++ debian/changelog 2011-08-14 16:58:24 +0000
4@@ -1,8 +1,12 @@
5 ubuntu-dev-tools (0.128) UNRELEASED; urgency=low
6
7+ [ Stefano Rivera ]
8 * ubuntutools.builder: Detect missing builder and fail early.
9
10- -- Stefano Rivera <stefanor@debian.org> Mon, 25 Jul 2011 19:36:41 +0200
11+ [ Julian Taylor ]
12+ * lp-shell: use ipython shell if available
13+
14+ -- Julian Taylor <jtaylor.debian@googlemail.com> Sun, 14 Aug 2011 18:56:52 +0200
15
16 ubuntu-dev-tools (0.127) unstable; urgency=low
17
18
19=== modified file 'debian/control'
20--- debian/control 2011-06-25 15:53:44 +0000
21+++ debian/control 2011-08-14 16:58:24 +0000
22@@ -57,7 +57,7 @@
23 python-gnupginterface,
24 python-soappy,
25 reportbug (>= 3.39ubuntu1)
26-Suggests: python-simplejson | python (>= 2.7), qemu-user-static
27+Suggests: ipython, python-simplejson | python (>= 2.7), qemu-user-static
28 Description: useful tools for Ubuntu developers
29 This is a collection of useful tools that Ubuntu developers use to make their
30 packaging work a lot easier.
31
32=== modified file 'doc/lp-shell.1'
33--- doc/lp-shell.1 2010-12-03 12:54:28 +0000
34+++ doc/lp-shell.1 2011-08-14 16:58:24 +0000
35@@ -5,6 +5,8 @@
36 .SH SYNOPSIS
37 .B lp\-shell
38 .RB [ \-a ]
39+.RB [ \-\-python ]
40+.RB [ \-\-ipython ]
41 .RI [ service ]
42 .RI [ "LP API version" ]
43
44@@ -34,6 +36,14 @@
45 .B \-a
46 Login anonymously into Launchpad.
47
48+.TP
49+.B \-\-ipython
50+Use an ipython shell if available (default).
51+
52+.TP
53+.B \-\-python
54+Use a regular python shell.
55+
56 .SH AUTHORS
57 .B lp\-shell
58 was written by Martin Pitt <martin.pitt@ubuntu.com>.
59
60=== modified file 'lp-shell'
61--- lp-shell 2010-12-27 20:54:31 +0000
62+++ lp-shell 2011-08-14 16:58:24 +0000
63@@ -33,6 +33,13 @@
64 opt_parser.add_option('-a', action='store_true',
65 dest='anonymous', default=False,
66 help='Login anonymously into LP.')
67+ opt_parser.add_option('--ipython',action='store_const',
68+ dest='shell',const='ipython', default="ipython",
69+ help='Use ipython shell (default).')
70+ opt_parser.add_option('--python',action='store_const',
71+ dest='shell',const='python',
72+ help='Use python shell.')
73+
74
75 (options, args) = opt_parser.parse_args()
76
77@@ -63,24 +70,43 @@
78
79 banner += '\nNote: LP can be accessed through the "lp" object.'
80
81- class CompleterConsole(code.InteractiveConsole):
82- def __init__(self):
83- local = {'lp': launchpad}
84- code.InteractiveConsole.__init__(self, locals=local)
85- try:
86- import readline
87- except ImportError:
88- print 'I: readline module not available.'
89- else:
90- import rlcompleter
91- readline.parse_and_bind("tab: complete")
92-
93- # Disable default apport hook, as lp-shell is intended for interactive use
94- # and thus exceptions often bubble up to the top level.
95- sys.excepthook = sys.__excepthook__
96-
97- console = CompleterConsole()
98- console.interact(banner)
99+ sh = None
100+ if options.shell == "ipython":
101+ try:
102+ try: # ipython >= 0.11
103+ from IPython.frontend.terminal.embed import InteractiveShellEmbed
104+ sh = InteractiveShellEmbed(banner2=banner, user_ns={'lp': launchpad})
105+ except ImportError: # ipython < 0.11
106+ # pylint does not handle nested try-except, disable import error
107+ # pylint: disable-msg=E0611
108+ from IPython.Shell import IPShellEmbed
109+ sh = IPShellEmbed(argv=[], user_ns={'lp': launchpad})
110+ sh.set_banner(sh.IP.BANNER + '\n' + banner)
111+ sh.excepthook = sys.__excepthook__
112+ except ImportError:
113+ print "E: ipython not available. Using normal python shell."
114+
115+ if sh:
116+ sh()
117+ else:
118+ class CompleterConsole(code.InteractiveConsole):
119+ def __init__(self):
120+ local = {'lp': launchpad}
121+ code.InteractiveConsole.__init__(self, locals=local)
122+ try:
123+ import readline
124+ except ImportError:
125+ print 'I: readline module not available.'
126+ else:
127+ import rlcompleter
128+ readline.parse_and_bind("tab: complete")
129+
130+ # Disable default apport hook, as lp-shell is intended for interactive use
131+ # and thus exceptions often bubble up to the top level.
132+ sys.excepthook = sys.__excepthook__
133+
134+ console = CompleterConsole()
135+ console.interact(banner)
136
137 if __name__ == '__main__':
138 main()

Subscribers

People subscribed via source and target branches

to status/vote changes: