[IPython-dev] Jython support in ipython

Jim Baker jbaker at zyasoft.com
Fri Oct 22 17:53:35 EDT 2010


As of r7164 of Jython, which will be part of 2.5.2rc2 (and hopefully the
last release candidate for Jython 2.5.2!), we have what looks decent support
for readline emulation for Jython, sufficient to run a minimally modified
version of ipython 0.10.1, including colorization (which is not reproduced
when copied here for whatever reason from my terminal):

Python 2.5.2rc1 (trunk:7162:7163M, Oct 21 2010, 20:58:50)
Type "copyright", "credits" or "license" for more information.

IPython 0.10.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import java

In [2]: java.awt.L

java.awt.Label                 java.awt.LayoutManager
java.awt.LayoutManager2
java.awt.LinearGradientPaint   java.awt.List

In [2]: java.awt.L


There are of course a number of outstanding issues. Most of these are
because I haven't yet tried to learn the ipython codebase:

   1. setup.py has to be modified to support os.name == 'java', otherwise we
   get an unsupported OS on install. Running directly with ipython.py is not an
   issue.
   2. Doing something like
   In [2]: print java.awt
   results in AttributeError: CommandCompiler instance has no attribute
   'compiler'. I assume ipython is using the compiler module here to help in
   its magic support. Ideally we would be using the ast/_ast modules, both of
   which Jython 2.5 supports. I haven't looked at the 0.11 work to see if that
   helps here, but this is probably the biggest issue for Jython support.
   3. OS integration relies on dispatches against os.name. In Jython, this
   will always be 'java', but for the underlying OS, and its resources, we need
   to know if its 'nt' or 'posix', which comes from os._name im Jython. I've
   previously played with replacing os.name everywhere with an os_name()
   function, defined in platutils that does the following. However it's not a
   complete fix (colorization is impacted), so it needs to be done more
   carefully.
   4. Pretty minor - we only support emulating readline.parse_and_bind("tab:
   complete"); other binds are converted to (ignored) warnings. In the future,
   we should be enhancing our readline support through the underlying JLine
   console so that this is possible. Otherwise, I think the readline emulation
   is currently complete.
   5. It's not *Python* 2.5.2rc1 (trunk:7162:7163M, Oct 21 2010, 20:58:50),
   is it? ;)


My goal in this last phase of work was just to get sufficient
*readline*emulation to run ipython, so this part has been
accomplished. But of course
we should also look at really supporting *ipython* too:

   1. Create a jython-ipython fork on github, then make it available from
   PyPI. My current plan is to target against the 0.10.1 tag, but if it makes
   more sense to go with 0.11 (especially AST support), then please tell me.
   More unit tests would be especially a good reason, especially if they use
   pexpect. Jython does not directly support pexpect, because we lack access to
   pseudo ttys, but we can use such CPython-only modules transparently from
   Jython via execnet (
   http://codespeak.net/execnet/example/test_info.html#remote-exec-a-module-avoiding-inlined-source-part-ii
   ).
   2. Merge this fork back into ipython at some point in the future. Among
   other things, the ZMQ work should also be feasible to port to Jython when it
   makes sense.
   3. Support additional Java integration, such as Swing. Maybe this is a
   separate plugin?


- Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20101022/13a7c1a7/attachment.html>


More information about the IPython-dev mailing list