Differences between revisions 44 and 88 (spanning 44 versions)
Revision 44 as of 2008-01-04 04:29:51
Size: 9664
Editor: c-67-177-212-165
Comment: Added what we need to get modern into trunk
Revision 88 as of 2014-05-22 23:24:19
Size: 2104
Editor: AdamBurke
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Gaps between Jython and Django == == Using Django on Jython ==
Line 3: Line 3:
[http://pipes.yahoo.com/pipes/pipe.info?_id=jroxOD1f3BGgvtiIqGIyXQ RSS Aggregator for blog posts about Django on Jython] Finally, Django works on Jython, without any special patching. Here are the steps to get Django on Jython running:
Line 5: Line 5:
To run Django on Jython, with a PostgreSQL backend, the following steps are necessary:  1. First, get a fresh version of Jython. Any release after 2.5.0 should work fine.
Line 7: Line 7:
 * Use the [https://jython.svn.sourceforge.net/svnroot/jython/branches/modern/ Modern branch] of Jython. This consolidated the bugs, workarounds, and patches found below -- 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.  2. Check out and install Django 1.2.5.
Line 9: Line 9:
 * Use the Django trunk (tested with rev 6992, later should be OK too).     {{{
$ svn co http://code.djangoproject.com/svn/django/trunk/ django
$ cd django
$ jython setup.py install
}}}
    
    You may also like to make an alias for "django-admin.py". Very useful if you also use Django with CPython:
Line 11: Line 17:
 * Apply these two patches, [https://jython.svn.sourceforge.net/svnroot/jython/trunk/sandbox/jbaker/django/dispatch/robustapply.py django.dispatch.robustapply] ([https://hg.leosoto.com/django.jythonport/rev/bb2b9048ed14f72e99c5c133c7ecaaeb0a5c425c diff]) and [https://jython.svn.sourceforge.net/svnroot/jython/trunk/sandbox/jbaker/django/views/debug.py django.views.debug] ([https://hg.leosoto.com/django.jythonport/rev/663bcf5efc31409899fcdc10009bc92df3e1f6b9 diff]) due to Leo Soto. These should be in Django trunk soon.     {{{
$ alias django-admin-jy="jython /path/to/jython-dev/dist/bin/django-admin.py"
}}}
Line 13: Line 21:
 * Copy these three files from CPythonLib to Lib: gettext.py, locale.py, optparse.py. 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 test_gettext.py, but depends on still failing locale.py). But they are very close, and they appear to be fine for Django. Certainly fine for this round of development!
 
 * Use the database backend [https://jython.svn.sourceforge.net/svnroot/jython/trunk/sandbox/jbaker/django/db/backends/postgresql_zxjdbc/ zxjdbc_postgresql], which was contributed by Leo Soto.
 3. Download and install the latest release of django-jython:
Line 17: Line 23:
Here's what works:     {{{
$ wget http://django-jython.googlecode.com/files/django-jython-1.2.0b1.tar.gz
$ tar xvfz django-jython-1.2.0b1.tar.gz
$ cd django-jython-1.2.0b1
$ jython setup.py install
}}}
Line 19: Line 30:
syncdb 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 --noreload for now. We need to document here how to run with [http://www.xhaus.com/modjy/ modjy], which is Alan Kennedy's servlet container for WSGI apps.  4. Start a project.
    {{{
$ django-admin-jy startproject myproject
}}}
Line 21: Line 35:
In running the model unit tests, here are the things we seem to be missing, accounting for most of the approximately 75 failures:  5. Edit `myproject/settings.py` and change the `DATABASE_ENGINE` to `doj.backends.zxjdbc.postgresql`.
Line 23: Line 37:
 * Many doctests are fragile, because they depend on the dict traversal ordering; in Jython, this is different that CPython, and if we adopt {{{ConcurrentHashMap}}}, it's not even repeatable. This is a pervasive bug in Django. At this point, you can follow the great [[http://djangoproject.com/documentation/|Django documentation]], remembering to use the `jython25` command instead of `python`, and the `JYTHONPATH` variable instead of `PYTHONPATH`. Have fun!
Line 25: Line 39:
 * 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 {{{PyUnicode}}}, but there are more places. == Deployment ==
Line 27: Line 41:
 * Problem with the {{{ManagerDescriptor}}} handling, in {{{django.db.models.manager}}}. See http://packages.python.org/django-jython/war-deployment.html
Line 29: Line 43:
 * No decorators yet! (But they are coming soon, and are now available experimentally for Jython.) == Troubleshooting ==
Line 31: Line 45:
There may be some other rough categories, we need to look at the failures more systematically. All that doctest noise is certainly annoying! === Running the test suite on Windows ===
Line 33: Line 47:
---- Seems like there is an issue with popen() on windows, which blocks the Django test suite. You can try skipping the offending test using these two patches (against Django 1.0.2), written by Victor Ng:
Line 35: Line 49:
Before we can push modern into trunk, the following needs to be done:  * http://tinyurl.com/bqfcco
 * http://tinyurl.com/aarjx2
Line 37: Line 52:
 * The test_extcall unit test currently fails. This appears to be a dependency on the dict traversal being the same. 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 produced an improved version for Python 2.6 - we will look at this as a starting point. '''Update (03/04/11): Not sure if this is an issue any longer, please edit if you run into it using the latest versions'''
Line 39: Line 54:
 * Tristan King provided a near complete subset of the functionality for {{{time.strptime}}}, as implemented in org.python.modules.time.Time. This needs to be enhanced. All unit tests in the CPythonLib version of test_time now pass except for {{{strptime}}} -- specifically the conversion specifier {{{'%c'}}} -- so we can also move to that, and discard our Jython version, when this is completed. That should be soon! === Using MS SQL Server ===
Line 41: Line 56:
 * Decide whether we should use {{{ConcurentHashMap}}} or not as the backing hash map for {{{dict}}} and {{{__dict__}}}.

=== Former Major problems ===

(Preserved to show how much we had to go through...)

 * Jython does not support non-str keys in {{{__dict__}}} right now. Jim Baker replaced the custom dictionary in {{{PyStringMap}}} with a {{{HashMap}}} (along Groves' earlier work). This change should resolve this problem. Try the [https://jython.svn.sourceforge.net/svnroot/jython/branches/modern/ modern] branch. Problem encountered in {{{django/utils/_threading_local.py}}}.
 * Something goes wrong with {{{re.compile(u"([\u0080-\uffff])")}}} in {{{django/utils/text.py}}} I think it is a lacking in our array implementation but this needs more investigation.
   * See [http://sourceforge.net/tracker/index.php?func=detail&aid=1544953&group_id=12867&atid=112867 bug 1544953]
 * {{{django/views/debug.py}}} wants to know a function's {{{__module__}}}. functions don't have a {{{__module__}}} attribute in jython yet. [http://sourceforge.net/tracker/index.php?func=detail&aid=1800472&group_id=12867&atid=312867 patch]
 * {{{inspect.getargs()}}} doesn't work.
   * That's because {{{co_code}}} isn't supported by {{{PyTableCode}}}.
     * '''But''', {{{co_code}}} is used by {{{getargs()}}} only to discover anonymous tuple arguments. Commenting such section seems to be enough to get the other cases working.
     * workaround [https://dev.archer.edu.au/projects/kepler/svn/jython-django/trunk/jython-patches/co_code-workaround.patch patch]. just sets {{{co_code = ""}}}. i haven't come across any problems for this inside django yet, but i'm sure it'll break other python code -- TristanKing
 * {{{time}}} module lacks {{{strptime()}}}.
   * workaround [https://dev.archer.edu.au/projects/kepler/svn/jython-django/trunk/jython-patches/time-strptime.patch patch]. this is incomplete, untested, and not optimal but works for the django tutorial -- TristanKing
 * inspect.isclass(time) shouldn't return True [http://sourceforge.net/tracker/index.php?func=detail&aid=1786009&group_id=12867&atid=112867 bug]
   * Django [http://code.djangoproject.com/changeset/6194 works around this] until it's fixed.

=== Former Minor annoyances ===

 * slice should be a type, not a function. [http://sourceforge.net/tracker/index.php?func=detail&aid=1791931&group_id=12867&atid=112867 bug] [http://sourceforge.net/tracker/index.php?func=detail&aid=1798544&group_id=12867&atid=312867 patch]
 * {{{PyBoolean.__tojava__}}} returns an {{{Integer}}}
   * It affects zxJDBC unless a DataHandler sets the right type of boolean parameters. Fortunately, JDBC30DataHandler does this thing, at least on my limited tests -- LeonardoSoto
 * Jython does not have {{{__builtins__}}} as a module. Django adds "_" as a convenience method for calling gettext in {{{django/conf/__init__.py}}}.
    * According to the Python docs, {{{__builtins__}}} is a implementation detail and shouldn't be used by portable applications, so it's a Django problem. (See note about {{{__builtins__}}} here: http://docs.python.org/ref/naming.html)
 * Jython methods are not descriptors. It seems a implementation detail. [http://code.djangoproject.com/ticket/5664 django patch]
 * Jython classes which extend dict cannot be compared to a dict. [https://sourceforge.net/tracker/index.php?func=detail&aid=1804011&group_id=12867&atid=112867 bug] [https://dev.archer.edu.au/projects/kepler/changeset/149?format=diff&new=149 django patch]
 * Jython doesn't recognize {{{__unicode__}}} methods assigned to instances.
    * But, this is the only {{{__*__}}} method where CPython allows this, and it's not documented anywhere. So, it's a implementation detail and should be fixed on Django. [http://code.djangoproject.com/ticket/5560 django patch]

=== Already Fixed ===

(And many more!)

 * Jython does not have {{{sys.stdout.isatty}}}. Jython should get added to the exclusions around that call in {{{django/core/management.py}}} (win32 and 'Pocket PC' are already excluded).
   * Fixed in [http://code.djangoproject.com/changeset/6032 Django changeset 6032]
 * stringmap (or the {{{__dict__}}} implementation) needs a {{{pop(o)}}} method.
 * Jython lists and tuples don't have {{{__iter__}}} .
   * Fixed in [http://code.djangoproject.com/changeset/6211 Django changeset 6211]
 * Jython does not have {{{os.getpid()}}}.
   * Django workarounds it now.
 * Jython does not have {{{os.W_OK}}} needed in {{{django/core/management.py}}}. This probably will not be hard to add this since {{{java.io.File}}} has a {{{canWrite()}}}.
   * {{{os.chmod}}} should be implemented too (After checking for write permissions, Django will try to change them if necessary).
     * That's hard. Maybe Django shouldn't check for permissions if running on Jython.
   * Django don't check or change file permissions when running on Jython now
 * The {{{U}}} (Universal newlines) flag for {{{open()}}} isn't recognized on Jython
 * Unicode string interpolation doesn't work
 * {{{object}}} has a {{{__unicode__}}} attribute (it doesn't on CPython) [https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1800378&group_id=12867 bug] [https://sourceforge.net/tracker/?func=detail&atid=312867&aid=1800381&group_id=12867 patch] -- TristanKing
 * metaclasses need to know the {{{__module__}}} of its classes [http://sourceforge.net/tracker/index.php?func=detail&aid=1781500&group_id=12867&atid=112867 bug] [http://sourceforge.net/tracker/index.php?func=detail&aid=1789137&group_id=12867&atid=312867 patch]
The Django-Jython 1.2.0b1 release is in beta as of 03/04/11. It should be compatible with Oracle, MySQL, and PostgreSQL. If you need to use MS SQL Server, you will still need to use Django version 1.1.x until otherwise noted.

Using Django on Jython

Finally, Django works on Jython, without any special patching. Here are the steps to get Django on Jython running:

  1. First, get a fresh version of Jython. Any release after 2.5.0 should work fine.
  2. Check out and install Django 1.2.5.
    • $ svn co http://code.djangoproject.com/svn/django/trunk/ django
      $ cd django
      $ jython setup.py install
      You may also like to make an alias for "django-admin.py". Very useful if you also use Django with CPython:
      $ alias django-admin-jy="jython /path/to/jython-dev/dist/bin/django-admin.py"
  3. Download and install the latest release of django-jython:
    • $ wget http://django-jython.googlecode.com/files/django-jython-1.2.0b1.tar.gz
      $ tar xvfz django-jython-1.2.0b1.tar.gz
      $ cd django-jython-1.2.0b1
      $ jython setup.py install
  4. Start a project.
    • $ django-admin-jy startproject myproject
  5. Edit myproject/settings.py and change the DATABASE_ENGINE to doj.backends.zxjdbc.postgresql.

At this point, you can follow the great Django documentation, remembering to use the jython25 command instead of python, and the JYTHONPATH variable instead of PYTHONPATH. Have fun!

Deployment

See http://packages.python.org/django-jython/war-deployment.html

Troubleshooting

Running the test suite on Windows

Seems like there is an issue with popen() on windows, which blocks the Django test suite. You can try skipping the offending test using these two patches (against Django 1.0.2), written by Victor Ng:

Update (03/04/11): Not sure if this is an issue any longer, please edit if you run into it using the latest versions

Using MS SQL Server

The Django-Jython 1.2.0b1 release is in beta as of 03/04/11. It should be compatible with Oracle, MySQL, and PostgreSQL. If you need to use MS SQL Server, you will still need to use Django version 1.1.x until otherwise noted.

DjangoOnJython (last edited 2014-05-22 23:24:19 by AdamBurke)