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):<div>
<br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="'courier new', monospace">Python 2.5.2rc1 (trunk:7162:7163M, Oct 21 2010, 20:58:50) </font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">Type "copyright", "credits" or "license" for more information.</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">IPython 0.10.1 -- An enhanced Interactive Python.</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">? -> Introduction and overview of IPython's features.</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">%quickref -> Quick reference.</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">help -> Python's own help system.</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">object? -> Details about 'object'. ?object also works, ?? prints more.</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">In [1]: import java</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">In [2]: java.awt.L </font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">java.awt.Label java.awt.LayoutManager java.awt.LayoutManager2</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">java.awt.LinearGradientPaint java.awt.List</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">In [2]: java.awt.L</font></div>
</div></blockquote><div><br></div><div>There are of course a number of outstanding issues. Most of these are because I haven't yet tried to learn the ipython codebase:</div><div><ol><li>setup.py has to be modified to support <a href="http://os.name">os.name</a> == 'java', otherwise we get an unsupported OS on install. Running directly with ipython.py is not an issue.</li>
<li>Doing something like<br><font class="Apple-style-span" face="'courier new', monospace">In [2]: print java.awt</font><br>results in <font class="Apple-style-span" face="'courier new', monospace">AttributeError: CommandCompiler instance has no attribute 'compiler'</font>. 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.</li>
<li>OS integration relies on dispatches against <a href="http://os.name">os.name</a>. 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 <a href="http://os.name">os.name</a> 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.</li>
<li>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.</li>
<li>It's not <b>Python</b> 2.5.2rc1 (trunk:7162:7163M, Oct 21 2010, 20:58:50), is it? ;)</li></ol></div><div><br></div><div>My goal in this last phase of work was just to get sufficient <u>readline</u> emulation to run ipython, so this part has been accomplished. But of course we should also look at really supporting <u>ipython</u> too:</div>
<div><ol><li>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 (<a href="http://codespeak.net/execnet/example/test_info.html#remote-exec-a-module-avoiding-inlined-source-part-ii">http://codespeak.net/execnet/example/test_info.html#remote-exec-a-module-avoiding-inlined-source-part-ii</a>).</li>
<li>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.</li><li>Support additional Java integration, such as Swing. Maybe this is a separate plugin?</li>
</ol></div><div><br></div><div>- Jim</div><meta charset="utf-8">