<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>Front Range Pythoneering</title>
    <link>http://www.zyasoft.com/pythoneering</link>
    <description>A static blog engine/compiler</description>
    <pubDate>Tue, 14 Sep 2010 05:47:13 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Jython 2.5.2 Beta 2 is Released</title>
      <link>http://www.zyasoft.com/pythoneering/2010/09/jython-2.5.2-beta-2-is-released</link>
      <pubDate>Mon, 13 Sep 2010 23:47:13 MDT</pubDate>
      <category><![CDATA[Jython]]></category>
      <category><![CDATA[2.5.x]]></category>
      <guid isPermaLink="true">http://www.zyasoft.com/pythoneering/2010/09/jython-2.5.2-beta-2-is-released</guid>
      <description>Jython 2.5.2 Beta 2 is Released</description>
      <content:encoded><![CDATA[<div class="document">
<p>On behalf of the <a class="reference external" href="http://www.jython.org">Jython</a> development team, I
would like to announce the second beta release of the 2.5.2 version of
Jython. Our current plan is that this will be the last beta of 2.5.2,
but this will depend on bug reports.</p>
<p>Download the installer JAR from <a class="reference external" href="http://sourceforge.net/projects/jython/">SourceForge</a>. Here are the checksums:</p>
<blockquote>
<ul class="simple">
<li>MD5, 560b43678059fd41a374a9487517235c</li>
<li>SHA1, 0c41db0e5d275bff80a2c4f9bc3de2e48969d0a6</li>
</ul>
</blockquote>
<p>The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to
run. Please try it out and report any bugs at <a class="reference external" href="http://bugs.jython.org">http://bugs.jython.org</a>.</p>
<p>This release fixes bugs related to resource leaks, Java integration,
and a number of other issues. See the <a class="reference external" href="https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython/NEWS">NEWS</a>
for more details. In particular, we did not completely fix the bug,
<a class="reference external" href="http://bugs.jython.org/issue1327">Classloaders cannot GC, which exhausts permgen</a>. Jython uses instances of
<cite>ThreadState</cite> to manage its execution state, including frames,
exceptions, and the global namespace.  The <cite>ThreadState</cite> also
indirectly refers to the <cite>ClassLoader</cite> objects used by Jython. Such
usage can cause resource leaks when a Jython application is restarted
under certain app containers, because the <cite>ThreadState</cite> often may not
removed by the app server's thread pool. This is because <cite>ThreadState</cite>
itself is managed by Java's <cite>ThreadLocal</cite>.</p>
<p>Fixing this problem without a backwards breaking API change appears to
be difficult. Therefore we recommend exploring workarounds, such as
the one published in this <a class="reference external" href="http://weblogs.java.net/blog/jjviana/archive/2010/06/09/dealing-glassfish-301-memory-leak-or-threadlocal-thread-pool-bad-ide">blog post</a>,
which also goes into these issues in more depth.</p>
<p>Jython 2.6 will introduce <strong>limited</strong> backwards breaking API changes, so
it will be possible to fully resolve this bug, and related issues, in
that version instead. In a future blog post, I will address what we
can do with respect to <cite>ThreadState</cite> in our 2.6. work.</p>
<p>Let's turn to more on what has been fixed or extended in 2.5.2. In
particular, I would like to highlight the following:</p>
<blockquote>
<ul>
<li><p class="first"><a class="reference external" href="https://scripting.dev.java.net/">JSR 223</a> (<a class="reference external" href="http://download.oracle.com/javase/6/docs/api/javax/script/package-summary.html">javax.script</a>)
support was introduced in 2.5.1, but it's now fully usable and is
supported by such solutions as <a class="reference external" href="http://restx.mulesoft.org/">RESTx</a>, which runs on <a class="reference external" href="http://www.mulesoft.org/">Mule ESB</a>. In particular, we bundle our own JSR
223-compliant engine to interface with Jython. Much thanks goes to
<a class="reference external" href="http://www.ifcx.org/">Jim White</a> who kept pushing us -- and other <a class="reference external" href="http://jira.codehaus.org/browse/GROOVY-1594">implementations</a> -- on this and
provided us with the starting code; <a class="reference external" href="http://web.sabi.net/nriley/">Nicholas Riley</a>, who did much of the work on the
Jython development team; and the many beta testers who provided
valuable advice and bug reports. JSR 223 is an important,
cross-language integration point.</p>
</li>
<li><p class="first">Python functions can be directly passed to Java methods that take a
single method interface (such as <cite>Callable</cite> or <cite>Runnable</cite>). This
means you can now pass a callback function, usually a closure,
instead wrapping it in a class implementing that interface. <a class="reference external" href="http://www.thobe.org/">Tobias
Ivarsson</a> implemented this feature.</p>
</li>
<li><p class="first">The <cite>collections.defaultdict</cite> type is now fully threadsafe. This
change continues a trend with our 2.5.0 release to provide strong
support for concurrent Python code. Previously any default values
could be overwritten by competing threads. CPython is able to
implicitly provide the same guarantees, but only on built-in type
factories, by the fact that code is serialized through the use of
its Global Interpreter Lock (GIL). Jython now uses <a class="reference external" href="http://code.google.com/p/guava-libraries/">Google Guava's</a> support for
collections. In particular, we leverage <a class="reference external" href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/MapMaker.html#makeComputingMap(com.google.common.base.Function)">atomically computed
function maps</a>.</p>
</li>
<li><p class="first">Jython's console now supports completing user input upon pressing the
&lt;TAB&gt; key. Using <a class="reference external" href="http://jline.sourceforge.net/">JLine</a>, which we
have bundled since 2.5.0, means completion works on both Windows
and Unix-derived platforms (including Linux and OS X). Use it just
like in CPython:</p>
<pre class="literal-block">
import readline
import rlcompleter
readline.parse_and_bind(&quot;tab: complete&quot;)
</pre>
<p>Usually you would do this in a setup script or a Python shell like
IPython.  For now, you will also need to change a property
setting. See the <a class="reference external" href="http://bugs.jython.org/issue1133">tracking issue</a> on the specifics, but we hope
to have this and IPython support complete, so to speak, by 2.5.2
final.</p>
<p>Such completion is particularly useful in navigating Java APIs,
most of which tend to be complex.</p>
</li>
<li><p class="first">You can now call a Java constructor using keyword arguments.
Geoffrey French contributed the patch for this nice <a class="reference external" href="http://bugs.jython.org/issue1503">feature</a>. It will also be the last new
feature implemented in the 2.5.x versions!</p>
</li>
</ul>
</blockquote>
<p>There are many other features and bug fixes, some small, some
large. We will look at these in future posts, as well as some
outstanding bugs we should be able to fix before the final release.</p>
<p>And -- last but not least -- please help spread the word:</p>
<p>Organizations using Jython 2.2.1, or earlier, should test their code
against 2.5.2 beta 2 now so that bug fixes and/or workarounds may be
identified. In particular, please note the following:</p>
<blockquote>
<ul class="simple">
<li>No additional work is anticipated on Jython 2.2.</li>
<li>Jython 2.5.2 is the last release in Jython 2.5.x series that will
address non-severe issues. Further enhancements in Java
integration, for instance, will be seen in 2.6.</li>
<li>Jython 2.6 development will begin immediately following the 2.5.2
release. Jython 2.6 will require the use of JDK 6. We are hoping
for some significant performance gains by being able to use
<cite>invokedynamic</cite> support, either directly or through a back port of
that support to JDK 6. More also on that in a future post.</li>
</ul>
</blockquote>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Back to Blogging!</title>
      <link>http://www.zyasoft.com/pythoneering/2010/09/back-to-blogging!</link>
      <pubDate>Sun, 12 Sep 2010 19:23:00 MDT</pubDate>
      <category><![CDATA[Meta]]></category>
      <guid isPermaLink="true">http://www.zyasoft.com/pythoneering/2010/09/back-to-blogging!</guid>
      <description>Back to Blogging!</description>
      <content:encoded><![CDATA[<div class="document">
<p>I'm blogging again. And trying out <a class="reference external" href="http://blogofile.com">Blogofile</a>
to make that happen. This blog is going to start rather sparse looking, and I
need to backfill in my old blog posts. But I will get there.</p>
<p>A couple of points on the tool chain I'm trying out here.</p>
<p>I have chosen to use <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> as the markup
language. Since I co-authored <a class="reference external" href="http://jythonbook.com">The Definitive Guide to Jython</a> (available on <a class="reference external" href="http://www.amazon.com/Definitive-Guide-Jython-Python-Platform/dp/1430225270">Amazon.com</a>
too!) in rst, this should come as no surprise. Using rst doesn't get
in the way, I can easily include code fragments, and I can add the
styling outside of the document. Then readily track with Mercurial. I
would like to describe some more of this tool chain for writing books
at some point, it was actually quite nice.</p>
<p>I had previously used <a class="reference external" href="http://www.blogger.com">blogger.com</a>, going
back to using it before the Google acquisition. Originally this
particular blog, Front Range Pythoneering, was just used for
announcements of the user group I was until recently leading, which is
called the <a class="reference external" href="http://www.meetup.com/frpythoneers/">Front Range Pythoneers</a>, not too surprisingly. As I
became involved in Jython development, I started to use blogger.com as
well for some blog posts. It was handy. But blogger.com was
not. Working around it for posting code with a toolchain that included
<em>rst2html</em> was not so much fun. When they stopped supporting external
web sites, it finally forced me to switch. Unfortunately it also took
me some time to make the switch too, so that further stymied my
blogging, beyond the usual lack of time.</p>
<p>Naturally I really don't like it when the tools get in the way!</p>
<p>For this, Blogofile seems like a good choice. Setup so far has been
reasonably easy, and I certainly don't have to be committed to it
long-term. I'll try to update here on my thoughts about it as I get
more experience with it.</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Trac on Jython - Genshi Support</title>
      <link>http://www.zyasoft.com/pythoneering/2009/07/trac-on-jython-genshi-support.html</link>
      <pubDate>Sat, 11 Jul 2009 18:18:00 MDT</pubDate>
      <category><![CDATA[Jython]]></category>
      <category><![CDATA[PBCVM]]></category>
      <category><![CDATA[AST]]></category>
      <guid>http://www.zyasoft.com/pythoneering/2009/07/trac-on-jython-genshi-support.html</guid>
      <description>Trac on Jython - Genshi Support</description>
      <content:encoded><![CDATA[<div class="document">
<p>(I was going to add this as a comment to NixDev Open Source Blog but the commenting system for that blog is currently broken.
So here's my response, and maybe it will get me to start blogging here again too.)</p>
<p>There has been less interest in Genshi from Jython development as of late,
probably because Mako is a very good alternative for Turbogears 2 and Pylons.
But you need Genshi for Trac, so here's what you might do:</p>
<blockquote>
<ul class="simple">
<li>expat. Jython 2.5 has an implementation of expat (Lib/xml/parses/expat.py) that wraps SAX
sufficiently that all of the unit tests for ElementTree pass. The only
problem is that it's somewhat slow, since the wrapper is in Python.
I would see that as a starting point to selective rewriting in Java, which
is much easier to do in Jython than in CPython. Perhaps with just a little more emulation work it will also work with Genshi?</li>
<li>AST. Jython 2.5 implements the standard _ast and ast (the latter actually part of 2.6, but we needed it!)
modules; we do not have any support for the older compiler module. I don't know the status of changeset 31
to support AST, but if it has been incorporated, or can be, we can work with this part then.</li>
<li>CPython bytecode. Lastly Jython 2.5 implements a CPython bytecode VM.
This has been tested by compiling the entire regression test suite into CPython byte code
(with CPython, we don't yet have a compiler for this path!), and except
for some cases around code introspection and minor differences in floating point
representation (which is an artifact of using CPython for the compilation process),
it passes. So you should be able to generate bytecode and just have it run.
Look at Lib/test/test_pbcvm.py for some details here.</li>
</ul>
</blockquote>
<p>Good luck! Feel free to ask any questions on the jython-dev mailing list or #jython on IRC.</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Flipping the 2.5 Bit for Jython</title>
      <link>http://www.zyasoft.com/pythoneering/2008/06/flipping-25-bit-for-jython.html</link>
      <pubDate>Tue, 24 Jun 2008 10:59:00 MDT</pubDate>
      <category><![CDATA[Jython]]></category>
      <category><![CDATA[2.5.x]]></category>
      <guid>http://www.zyasoft.com/pythoneering/2008/06/flipping-25-bit-for-jython.html</guid>
      <description>Flipping the 2.5 Bit for Jython</description>
      <content:encoded><![CDATA[<div class="document">
<p>Something worth pointing out; as of 8 AM this morning (MDT) in rev 4748, Frank Wierzbicki flipped the bits and pronounced this about the ASM branch:</p>
<pre class="literal-block">
jbaker:~/jythondev/asm jbaker$ dist/bin/jython
Jython 2.5a0+ (asm:4750, Jun 24 2008, 10:56:16)
[Java HotSpot(TM) Client VM (&quot;Apple Computer, Inc.&quot;)] on java1.5.0_13
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt;
</pre>
<p>Yesterday there were easily the most commits we have seen in the Jython project. The real threshold was reached when we incorporated the UTF-16 and new-style exception branches into this branch, fixed the grammar to support most incremental parses, while repointing the standard library to CPythonLib 2.5. Along with a flurry of other fixes!</p>
<p>There's a lot more to go, but this should be an encouraging sign for everyone interested in Jython!</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Adopting UTF-16</title>
      <link>http://www.zyasoft.com/pythoneering/2008/06/utf-16-jython-2.html</link>
      <pubDate>Tue, 24 Jun 2008 10:13:00 MDT</pubDate>
      <category><![CDATA[Jython]]></category>
      <category><![CDATA[Unicode]]></category>
      <guid>http://www.zyasoft.com/pythoneering/2008/06/utf-16-jython-2.html</guid>
      <description>Adopting UTF-16</description>
      <content:encoded><![CDATA[<div class="document">
<p>Jython 2.5 standardizes on Java 5 as the base version for its implementation. Jython has always mapped both <cite>unicode</cite> and <cite>str</cite> types to <cite>java.lang.String</cite>, but the semantics of <cite>String</cite> changed as of Java 5. Instead of encoding characters as UCS-2, that is just the basic multlingual plane of 65536 code points, Java - like .Net - adopted the UTF-16 encoding. UTF-16 can represent all 1114112 Unicode code points (<cite>U+0</cite> to <cite>U+10FFFF</cite>), except for isolated surrogates (<cite>U+D800</cite> to <cite>U+DFFF</cite>). These surrogates act as escape characters in the UTF-16 encoding.</p>
<p>This makes things somewhat more complicated, to put it mildly. And this is without even considering combining characters!</p>
<p>Instead of a simple uniform encoding that we see in the narrow (UCS-2) or wide (UCS-4) builds of CPython, we get a variable-length encoding. And unlike UTF-8, it's usually not too efficient. In addition, we lose the ability to represent the isolated surrogates. Finally, because UTF-16 is so very close to UCS-2, it's prone to bugs.</p>
<p>Here's the implementation strategy we adopted. In supporting the <cite>unicode</cite> type with <cite>PyUnicode</cite>, we first determine if it's in the basic plane or not:</p>
<pre class="literal-block">
private enum Plane {
    UNKNOWN, BASIC, ASTRAL
}

private volatile Plane plane = Plane.UNKNOWN;

public boolean isBasicPlane() {
    if (plane == Plane.BASIC) {
        return true;
    } else if (plane == Plane.UNKNOWN) {
        plane = (string.length() == getCodePointCount()) ? Plane.BASIC : Plane.ASTRAL;
    }
    return plane == Plane.BASIC;
}
</pre>
<p><cite>getCodePointCount</cite> is in turn implemented using <cite>String#codePointCount</cite>. Like other code point methods, it decodes any surrogate pairs.</p>
<p>String immutability means we can cache the result in the volatile field <cite>plane</cite>; idempotence of this operation ensures consistency. This allows us to equate code units (<cite>char</cite>) to code points (<cite>int</cite>), and use the implementations provided by <cite>PyString</cite>. As it turns out, this was always done before, the only difference between <cite>str</cite> and <cite>unicode</cite> was in the encoding rules.</p>
<p>In the rather rare case it isn't, we read with <cite>String#codePointAt</cite> and write with <cite>StringBuilder#appendCodePoint</cite> using iterators. A seemingly good alternative would be to use <cite>String#offsetByCodePoints</cite>. Too bad it <a class="reference external" href="http://ed-merks.blogspot.com/2007/02/jdk-bugs-to-fix-or-not-to-fix.html">doesn't reliably work</a>. So instead we have our iterator implementations, lots and lots of them. And sometimes crazy stuff like this, seen in the implementation of <cite>PyUnicode#unicode_strip</cite>:</p>
<pre class="literal-block">
return new PyUnicode(new ReversedIterator(
    new StripIterator(sep,
        new ReversedIterator(
            new StripIterator(sep,
                newSubsequenceIterator())))));
</pre>
<p>If <cite>strip</cite> method was used extensively on strings that weren't in the basic plane, it might make sense to rewrite this to decode to an <cite>int[]</cite> buffer. But that's not likely to be case.</p>
<p>That's also the reason we avoid making the basic plane test unless we have to. There are many situations where Unicode can pass in and out of Jython - specifically to/from Java - without us caring about what planes its characters are drawn from. We assume some overhead from boxing with PyUnicode (although HotSpot mitigates the indirection cost), but we don't have to overdo it by computing this test on construction.</p>
<p>When comparing this with CPython, we do lose the ability to include isolated surrogate code points in Unicode strings. There are even some unit tests for this case. But ultimately this seemed like an implementation detail like testing ref counting, one certainly not worth time spent supporting.</p>
<p>It's worth mentioning that one alternative is to create our own representation, much like JRuby. Ruby's strings are mutable, unlike Python's. This forced the issue for the JRuby developers, because Ruby, like Python, needs good string performance. So JRuby uses byte arrays for strings, although they do use UTF-16 encoded, interned <cite>java.lang.String</cite>'s to uniquely represent symbols (<cite>:xyz</cite>). Given that symbols are not strings, this works well. Ruby doesn't say anything about the encoding of such strings (ouch!), but JRuby does assume they're UTF-8 encoded when <a class="reference external" href="http://headius.blogspot.com/2007/04/paving-road-to-jruby-10-unicode.html">crossing the boundary with Java</a>.</p>
<p>Supporting widened Unicode means having support for this in regular expressions. The first step was to just widen the SRE engine used by Jython to represent characters with <cite>int</cite> instead of <cite>short</cite>. So we always unpack to <cite>int</cite> in this case; see <cite>strip</cite> above. This engine is a direct translation of the CPython equivalent: it's a mini-VM, much like the pickle VM, and regexes are compiled to SRE bytecode. In the future, we may consider using JRuby's implementation (Joni, a port of Oniguruma to Java), but the devil is in supporting some specifics to Python. As was seen in the CPython case, it was quite straightforward to just doing the widening.</p>
<p>At this point, the biggest outstanding issue is backporting the changes to SRE to support wide character classes (aka big character sets), a pickle problem, as well as various bug fixes. A total of 4 test cases are currently failing in test_re.</p>
<p>And then that's it, at least until we start doing performance profiling.</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Realizing Jython 2.5</title>
      <link>http://www.zyasoft.com/pythoneering/2008/06/realizing-jython-25.html</link>
      <pubDate>Fri, 20 Jun 2008 21:43:00 MDT</pubDate>
      <category><![CDATA[Jython]]></category>
      <category><![CDATA[2.5.x]]></category>
      <guid>http://www.zyasoft.com/pythoneering/2008/06/realizing-jython-25.html</guid>
      <description>Realizing Jython 2.5</description>
      <content:encoded><![CDATA[<div class="document">
<p><a class="reference external" href="http://www.jython.org/Project/roadmap.html">Jython 2.5</a> is really, finally, unbelievably coming together. This is the next release of Jython, after last summer's 2.2. In a nutshell, we have completed all new language features using an Antlr parser, except for absolute imports. All bytecode generation work, now using an ASM backend, is done. Of course, there are many outstanding bugs. And Python is not just a core language; we need to support fully the fact that &quot;batteries are included&quot;. But let's look at where we are. Through the prism of what's new in <a class="reference external" href="http://www.python.org/doc/2.3/whatsnew/">2.3</a>, <a class="reference external" href="http://www.python.org/doc/2.4.3/whatsnew/whatsnew24.html">2.4</a>, and <a class="reference external" href="http://docs.python.org/whatsnew/whatsnew25.html">2.5</a>, here's what working:</p>
<blockquote>
<ul class="simple">
<li>2.3: sets (PEP 218), generators (255), source code encoding (263), universal newline (278), enumerate (279), logging (282), Boolean (285), distutils (301), new import hooks (302), pickle enhancements (307), extended slices, datetimes, optparse. Still to go: csv, removing a dictionary in builtin that ensures that interned strings don't get in GC'ed (pre-2.3 behavior!, it helps to read what's new). Also various string, Unicode, and regex changes are mostly done in a separate utf16 branch that I'm currently in the midst of merging against trunk.</li>
<li>2.4: unifying long integers (237), generator expressions (289), string.Template (292, but also needs new utf16 work), decorators (318), reverse iteration (322), subprocess module (324), multi-line imports (328), removal of OverflowWarning, min &amp; max with keyword support, sorted. But we still need partial import with sys.modules, and I'm sure some more stuff I forgot. Decimal and -m support are working in student branches, we just need to incorporate.</li>
<li>2.5: conditional expressions (308), partial functional (309, but we're cheating with a pure-Python version), distutils metadata (314), unified try/except/finally (341), coroutines and other generator functionality (342), with-statement, including contextlib (343), any, all. But we haven't done the exceptions remapping to new-style classes, absolute and relative imports, or all of the context manager support, such as in file. ctypes was a proposed Google Summer of Code project, but apparently PyPy has some work that's 95% the way there; we will talk with them at EuroPython. We need to look into what is necessary to make ElementTree work. sqlite3 depends on ctypes. As I was writing this, I tried out wsgiref; it works and I just committed it to the asm branch. (At some point, we will repoint everything like this to CPythonLib, but for now we are mixing it up as we go. Bear with us!)</li>
</ul>
</blockquote>
<p>Even quit() and exit() now work; I don't know when these oh-so-major features were added. We even now support large string constants. And of course, who can forget our support for the GIL (global interpreter lock) in Jython, something that Tobias Ivarsson, my Google Summer of Code student who is now working on an advanced compiler, added to __future__ as an Easter egg:</p>
<pre class="literal-block">
&gt;&gt;&gt; from __future__ import GIL
Traceback (most recent call last):
  (no code object) at line 0
  File &quot;&lt;stdin&gt;&quot;, line 0
SyntaxError: Never going to happen!
</pre>
<p>I would imagine that's definitive, we go against Java's native threads and compile to Java bytecode. It would be hard to have a GIL, even if we wanted one.</p>
<p>However, we are just turning the corner. The The Antlr parser in the asm branch currently does not support partial parses, and this breaks not only interactive sessions but doctests. Until this is solved - and <a class="reference external" href="http://fwierzbicki.blogspot.com/">Frank Wierzbicki</a> is working like <a class="reference external" href="http://twitter.com/fwierzbicki">mad</a> on this - we can't merge this branch onto trunk. But that should happen very soon.</p>
<p>With few exceptions, we simply go against the standard Python unit tests. Straightforward, cunning, or devious, we have labored against these unit tests. And in others, we have used Python as our foil: we support the same 2.5 AST parse tree, and we know this by comparing our parses with CPython's for all of the standard library - including those unit tests.</p>
<p>There's a lot more going on. I can't say enough about the work done by <a class="reference external" href="http://cnapalm.blogspot.com/">Charlie Groves</a>, <a class="reference external" href="http://dunderboss.blogspot.com/">Philip Jenvey</a>, <a class="reference external" href="http://www.xhaus.com/alan/python/index.html">Alan Kennedy</a>, <a class="reference external" href="http://web.sabi.net/nriley/">Nicholas Riley</a>, and others to make this happen.  <a class="reference external" href="http://blog.leosoto.com/">Leo Soto</a>, my other GSoC student, is making amazing progress on <a class="reference external" href="http://dojstatus.leosoto.com/">supporting Django on Jython</a>, while finding and fixing bugs in Jython itself. Supporting Django forces us to find those gaps in compatibility. Similar efforts are going on with Pylons, TurboGears 2 (Ariane Paola, GSoC), and Zope (<a class="reference external" href="https://launchpad.net/~codingmaster">Georgy Berdyshev</a>, GSoC). I'm also working on greenlet/Stackless support and involved in a collaboration with <a class="reference external" href="http://ece.colorado.edu/~siek/">Jeremy Siek</a> and Joe Angell at the University of Colorado to add <a class="reference external" href="http://ece.colorado.edu/~siek/dls08igtlc.pdf">gradual typing</a>] (yes types! but only when you want to) to Jython. We have a T2000 contributed by Sun to let us see how much concurrency - in this case 32 hardware threads, 64 GB of memory - Jython can take advantage of. And so on.</p>
<p>Back to work!</p>
<p><strong>Updates - 2008-06-24</strong>: we have support for new-style exceptions, the parser is now usable (but there are a couple of bugs left there), and Unicode support has been updated to UTF-16. See this posting, <a class="reference external" href="/pythoneering/2008/06/flipping-25-bit-for-jython.html">Flipping the 2.5 Bit for Jython</a>.</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Django on Jython - Minding the Gap</title>
      <link>http://www.zyasoft.com/pythoneering/2008/01/django-on-jython-minding-gap.html</link>
      <pubDate>Thu, 03 Jan 2008 21:59:00 MST</pubDate>
      <category><![CDATA[Jython]]></category>
      <category><![CDATA[2.5.x]]></category>
      <guid>http://www.zyasoft.com/pythoneering/2008/01/django-on-jython-minding-gap.html</guid>
      <description>Django on Jython - Minding the Gap</description>
      <content:encoded><![CDATA[<div class="document">
<div class="section" id="summary">
<h1>Summary</h1>
<p>The most important thing to know about Django on Jython is that we are almost there, and with clean code. End-to-end functionality is demonstrated by the admin tool running in full CRUD, along with a substantial number of unit tests and syncdb. But this has been achieved by so far requiring only 6 lines of code in changes to Django trunk. (There will be more, however, see below.)</p>
</div>
<div class="section" id="running-on-jython">
<h1>Running on Jython</h1>
<p>To run Django on Jython, with a PostgreSQL backend, the following steps are necessary:</p>
<blockquote>
<ul class="simple">
<li>Use the Modern branch of Jython. This consolidated the bugs, workarounds, and patches of numerous people -- plus a bunch more -- in a stable, almost-ready-to-be-merged-into-trunk version of Jython. The most important aspect is that we have tried to make Jython conform more to CPython, using Django as our guide, although there are some gaps -- especially if Django already had incorporated fixes. Our driving goal is to converge on these gaps over time. Please note that is intended to be stable, performant code.</li>
<li>Use the Django trunk (tested with rev 6992, later should be OK too).</li>
<li>Apply these two patches, <cite>django.dispatch.robustapply</cite> (diff) and <cite>django.views.debug</cite> (diff) due to Leo Soto. I would imagine these will be in Django trunk soon.</li>
<li>Copy these three files from CPythonLib to Lib: <cite>gettext.py</cite>, <cite>locale.py</cite>, <cite>optparse.py</cite>. Please note that these files are only partially working on Jython, that's why they haven't been promoted yet (gettext.py actually works, as verified by <cite>test_gettext.py</cite>, but depends on still failing <cite>locale.py</cite>). But they are very close, and they appear to be fine for Django. Certainly fine for this round of development!</li>
<li>Use the database backend <cite>zxjdbc_postgresql</cite>, which was contributed by Leo Soto. Frank Wierzbicki has an experimental backend for MySQL, this should be incorporated soon.</li>
</ul>
</blockquote>
</div>
<div class="section" id="status">
<h1>Status</h1>
<p>Here's what works:</p>
<p><cite>syncdb</cite> and the very cool Django admin run; many unit tests pass. You can run with internationalization enabled. You do need to run the dev server with <cite>--noreload</cite> for now. We need to document here how to run with <cite>modjy</cite>, which is Alan Kennedy's servlet container for WSGI apps.</p>
<p>In running the model unit tests, here are the things we seem to be missing, accounting for most of the approximately 75 failures:</p>
<blockquote>
<ul class="simple">
<li>Many doctests are fragile, because they depend on the <cite>dict</cite> traversal ordering; in Jython, this is different that CPython, and if we adopt <cite>ConcurrentHashMap</cite>, it's not even repeatable. This would seem to be a pervasive bug in Django.</li>
<li>We still have some encoding problems, again seen in doctests. An example where output is expected to be lower case hex, not upper case. I fixed the problem in <cite>PyUnicode</cite>, but there are more places.</li>
<li>Problem with the <cite>ManagerDescriptor</cite> handling, in <cite>django.db.models.manager</cite>.</li>
<li>No decorators yet! (But they are coming soon, and are now available experimentally for Jython in the newcompiler work I have been leading.)</li>
</ul>
</blockquote>
<p>There may be some other rough categories, we need to look at the failures more systematically. All that doctest noise is certainly annoying!</p>
</div>
<div class="section" id="next-steps">
<h1>Next Steps</h1>
<p>On the Django front, get more of the unit tests running!</p>
<p>Before we can push modern into trunk, the following needs to be done:</p>
<blockquote>
<ul class="simple">
<li>The <cite>test_extcall</cite> unit test currently fails. This appears to be a dependency on dict traversal being repeatable, a bad assumption. However, it's a mind bending test. The 2.3 version is particularly problematic because it's not modular at all. Google's GHOP has just produced an improved version for Python 2.6 - we will look at this as a starting point.</li>
<li>Tristan King provided a near complete subset of the functionality for <cite>time.strptime</cite>, as implemented in <cite>org.python.modules.time.Time</cite>. This needs to be enhanced. I just tested this, and all unit tests in the CPythonLib version of <cite>test_time</cite> now pass except for <cite>strptime</cite> -- specifically the conversion specifier <cite>'%c'</cite> -- so we can also move to that, and discard our Jython version, when this is completed. That should be soon!</li>
<li>Decide whether we should use <cite>ConcurentHashMap</cite> or not as the backing hash map for <cite>dict</cite> and <cite>__dict__</cite>. CHM introduces creation overhead, but it should prove to be far more scalable on multicore systems. The programming model is also far nicer with respect to Jython.</li>
</ul>
</blockquote>
<p><strong>Updates - 2008-06-24</strong>: I should have put this up a while ago, but Django on Jython is becoming a reality. Most importantly, Leo Soto is working with me through the Google Summer of Code on this project. The modern branch was merged into a trunk earlier this year, and has since been retired. CHM in fact has the right semantics, something I may discuss at a future point. Django has redone the doctest dict literals that were causing problems, and Leo provided a general solution when used with XML/XHTML.</p>
<p><strong>Updates - 2010-09-13</strong>: Django on Jython is a standard <a class="reference external" href="http://pypi.python.org/pypi/django-jython">PyPI project</a>. The best reference for it can be found in our <a class="reference external" href="http://www.jython.org/jythonbook/en/1.0/JythonDjango.html">Jython book</a>. Jython 2.5.2 is about out. The previous release fixed pretty much all of the other issues. And using <cite>ConcurrentHashMap</cite> has been a very good decision!</p>
</div>
</div>
]]></content:encoded>
    </item>
  </channel>
</rss>
