Differences between revisions 31 and 105 (spanning 74 versions)
Revision 31 as of 2006-05-03 17:50:33
Size: 6000
Editor: KhalidZuberi
Comment: update for svn migration
Revision 105 as of 2012-06-24 06:24:54
Size: 7545
Editor: JeffAllen
Comment: New page on buffer protocol
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## Please edit system and help pages ONLY in the moinmaster wiki! For more
## information, please see MoinMaster:MoinPagesEditorGroup.
## Please edit (or translate) system/help pages on the moinmaster wiki ONLY.
## For more information, please see MoinMaster:MoinPagesEditorGroup.
##master-page:Unknown-Page
##master-date:Unknown-Date
#acl MoinPagesEditorGroup:read,write,delete,revert All:read
#format wiki
#language en
This is an introduction to developing Jython, just to get someone started. It doesn't cover the source code in any depth or discuss the design behind Jython. It's purely aimed at getting a development environment set up. It's definitely not complete so feel free to make it better!
<<TableOfContents>>
Line 11: Line 4:
BrianZimmer, incept: 2005-01-31 == Mercurial ==
  * Check out a copy of the Jython source with [[http://mercurial.selenic.com/|Mercurial]], available on most *nix systems or with Cygwin on Windows.
  * You can use the command line tool `hg`, or [[http://mercurial.selenic.com/wiki/OtherTools#Graphical_user_interfaces|GUI clients are available]] on most platforms.
  * !NetBeans, Eclipse and other Java IDEs also integrate Mercurial support. Eclipse users should see JythonDeveloperGuide/EclipseNotes.
  * Browse the source code on the Web at http://hg.python.org/jython or at the official mirror on BitBucket, at http://bitbucket.org/jython/jython.
  * To obtain the a copy of the ''current development'' source, clone the repo via:
    {{{ hg clone http://hg.python.org/jython }}}
  * It's easy to create your own fork of the repo on BitBucket, visit http://bitbucket.org/jython/jython and click on 'Fork'
  * Attach patches to issues in the [[http://bugs.jython.org/|Jython bug tracker]].
    * Also, you can upload them to http://codereview.appspot.com (the Jython repository is already registered).
Line 13: Line 15:
This is an introduction to developing Jython, just to get someone started. It doesn't cover in any depth the source code or the design behind Jython. It's purely aimed at getting a development environment setup. It's definitely not complete so feel free to make it better! == Subversion (Historical) ==

When Jython first followed CPython into use of Mercurial as the repository, it continued to reference a part of the CPython source at {{{ https://svn.python.org }}} as a "sub-repository". This meant you still needed [[http://subversion.apache.org | Subversion]] installed. As of 20 March 2012, the Jython Mercurial repository contains a snapshot of CPython libs in the 2.2, 2.5, and default branches.

You therefore only need the following advice if you are somehow working with an old repository.

The following advice is based on experience using Mercurial 1.9, [[http://sliksvn.com| Slik Subversion]] and Windows 7 (AMDx64). Other tools and operating systems exist. An installation
that gives you the command 'svn' on your path is sufficient.

If you do not have Subversion installed (and on the PATH) the Mercurial {{{hg clone}}} command will terminate with the message: {{{
abort: The system cannot find the file specified
}}}
at the point where it attempts to read the sub-repository, specified in the files {{{ .hgsub }}} and {{{ .hgsubstate }}}.

A second requirement is that Subversion should accept the SSL certificate from the site svn.python.org. If you have
not used Subversion already to access the site, you may find that the {{{ hg clone }}} command hangs at the point where it attempts to read the sub-repository. A simple solution is to visit the site once from the command line as follows: {{{
svn info https://svn.python.org/projects/python/branches/release26-maint/Lib/
}}}
Subversion will issue a warning about the certificate, and you will be able to "accept permanently" the site's certificate. The Mercurial clone operation should not now hang.

If you see the sub-directory {{{ CPythonLib }}} created in your local repository, then the call to Subversion by Mercurial was a success. (It can take a few minutes to complete.)
Line 16: Line 38:
''' SVN ''' == Ant ==
Line 18: Line 40:
  * http://subversion.tigris.org/
  * available on most *nix systems or with cygwin on Windows
  * GUI clients are available on most platforms
  * Eclipse users, see JythonDeveloperGuide/EclipseNotes
  * can browse the current source archive at http://svn.sourceforge.net/viewcvs.cgi/jython/
    
  * to obtain the a copy of the ''current development'' source, checkout from trunk:
    {{{
    svn co https://svn.sourceforge.net/svnroot/jython/trunk/jython
    }}}
  * [[http://ant.apache.org/|Ant]] is a Java-based tool used to build Jython from source.
  * Eclipse users, see [[/EclipseNotes#ANT|Eclipse Ant notes]]
  * Download the latest version (Jython requires Ant 1.7 or later to build) and install it so Ant's `bin` directory is somewhere in your path.
  * To build Jython, run `ant` in the top-level Jython directory (which contains the Ant file `build.xml`).
  * The results of the build appear in the `dist` subdirectory.
Line 29: Line 46:
  For ''2.1 Stable'', the last stable release:
    {{{
    svn co https://svn.sourceforge.net/svnroot/jython/tags/Release_2_1/jython
    }}}
== Tests ==
The Jython build process generates an executable Bash script, `dist/bin/jython`, to make it easy to launch your build of Jython. It works on Unix-like platforms (including Mac OS X and Cygwin).
Line 34: Line 49:
  For ''2.2 Alpha 1'', the last alpha release:
    {{{
    svn co https://svn.sourceforge.net/svnroot/jython/tags/Release_2_2alpha1/jython
    }}}
If you're using Windows without Cygwin, use the batch file `dist/bin/jython.bat` instead.
Line 39: Line 51:
  * Patches should be posted to the [http://sourceforge.net/tracker/?group_id=12867&atid=312867 jython patch tracker] as forward unified diffs. This can be done for example using ''svn diff'' from the command line, just plain ''diff -u'', or using the eclipse ''Team->Create Patch feature''. [TODO: write better patch submission guidelines, similar to http://www.python.org/dev/patches/).

''' Python '''

  * http://www.python.org/2.2.3/
  * Jython uses Python's standard library where possible. This means you will need a working copy of Python source files for the stdlib. We currently use Python 2.2 so you can grab the files from here if you don't already have 2.2 installed.


''' JavaCC '''

  * https://javacc.dev.java.net/
  * Parser generator for Java. Generally needed only for working on parser.
  * It's not really required that you install this so I'd skip it.
  * The latest version is JDK 1.5 compatible (uses 'e' rather than 'enum' as variable name).


''' Ant '''

  * http://ant.apache.org/ A Java-based build tool.
  * Eclipse users, see [wiki:Self:/JythonDeveloperGuide/EclipseNotes#ANT Eclipse ANT notes]
  * The Makefiles in the repository are old and will be removed.
  * Download the latest version and install so the bin/ is somewhere in your path.
  * The build.xml is the file containing the compiler directives
  * It uses a file called ant.properties to override default paths; here's mine:
    {{{
    build.compiler=modern
    debug=on
    optimize=off

    javaccHome=/Users/bzimmer/Library/Java/Extras/javacc-3.2

    ht2html.dir=
    #python.home=
    python.lib=/sw/lib/python2.2
    python.exe=/sw/bin/python2.2

    ### zxJDBC ###
    oracle.jar=
    mysql.jar=/Users/bzimmer/Library/Java/Extras/mysql-connector-java-3.1.6-bin.jar
    informix.jar=
    postgresql.jar=/Users/bzimmer/Library/Java/Extras/pg74.215.jdbc2.jar
    jdbc.jar=
    servlet.jar=
    }}}


''' Jars '''

  * Jython uses many optional jars
  * These are not required for building locally but are for deployment with the installer
  * The ant script takes care of conditional compilation

''' IDEs '''

  * Any Java IDE will work
    * IntelliJ
    * Eclipse see /EclipseNotes
    * Vim
    * ...

''' Tests '''
 After you've built the project, you may want to set up an excutable file on your path to make it easy to launch your build of jython. This file will need to:
 *Set the python home property to the `dist` directory of your build (otherwise, you'll get import errors on the standard lib stuff).
 *Execute the `jython.jar` in the `dist` produced by the build.
Here's a batch file that runs the built jython.jar (for windows): [[Anchor(sampleBatch)]]
{{{
:: jytip.bat
@echo off
set ARGS=

:: concatenate all the command line args into one
:loop
if [%1] == [] goto end
        set ARGS=%ARGS% %1
        shift
        goto loop
:end

:: this is mine...
:: java -Dpython.home=C:\\workspace\\JythonTip\\jython\\dist -jar
::<cont> c:\workspace\JythonTip\jython\dist\jython.jar %ARGS%
:: fill in <placeholders> below:
java -Dpython.home=<path to dist directory>\\dist -jar <path to dist directory>\dist\jython.jar %ARGS%
}}}
Line 126: Line 54:
    * Jython's Lib/test
    * Jython's bugtests repository
    * Python2.2's Lib/test
  * Run the particular test or you can run the whole suite by running `regrtest.py` with the `-a` option
    * Jython's `dist/Lib/test` (populated by the build process)
    * Jython's `bugtests` subdirectory (included with the development sources)
  * Run a particular test, or the whole Python test suite with `ant regrtest`.
Line 131: Line 58:
''' Directory layout '''
Note the following describes the current trunk. If you are working from an older tag, src doesn't exist and src/com and src/org are moved up a level.
See TestingJython for some more details.
Line 134: Line 60:
  * src/com : zxJDBC related sources"
  * Demo : demo sources for the website and such"
  * Doc : the website documentation"
  * installer : the current installer which apparently no longer works"
  * Lib : the python source files for Jython standard library implementations
  * Lib/test : test cases
  * Misc : random scripts which are not all used; some generate source
  * src/org : top level package for python and apache (used for regex)
  * Tools : JythonC and Freeze
== Directory layout ==
Note the following describes the current trunk/jython. If you are working from an older tag, src doesn't exist and src/com and src/org are moved up a level.
Line 144: Line 63:
''' Coding Guidance '''   * `src/org` : top level package for python
  * `src/com` : zxJDBC related sources
  * `src/shell` : launcher scripts
  * `src/templates`: java source generator & related templates, used to update portions of java classes elsewhere in the source tree
  * `Demo` : demo sources for the website and such
  * `Doc` : the website documentation (see /WebsiteBuilderSetup to build the http://jython.org website)
  * `Lib` : the python source files for Jython standard library implementations
  * `Lib/test` : test cases
  * `Misc` : random scripts which are not all used; some generate source
  * `Tools` : JythonC and Freeze
  * `CPythonLib` : Lib directory from the corresponding version of cpython, via svn:externals
  * `bugtests` : additional test cases covering bug reports
Line 146: Line 76:
== Coding guidance ==

  * /PortingPythonModulesToJython : A good starting task for a Jython developer
Line 147: Line 80:
  * PatchGuidelines : How to make a patch for submission to the tracker

== How things work ==
  * ImplementNewType : Implementing a new type (a beginner's notes)
  * ImplementSequenceType : Implementing a new sequence type
Line 148: Line 86:
  * JythonClassesInJava : How to write a Jython class in Java   * PythonTypesInJava : How to make a Jython type in Java (2.5 and later), mostly about the type exposer
  * JythonClassesInJava : How to make a Jython class in Java (pre-2.2, deprecated)
  * /AttributeLookupMethods : Some explanation for the different methods to lookup attributes on PyObject.
  * /ImplementingStrAndRepr : Tips for implementation of `__str__` and `__unicode__` in Java.
  * IntegerConversion : Basics of converting PyObject numbers to Java primitives
  * /UsingPyNewStringFromPythonCode : On the corner case of converting a Java String to a Python String.
  * GeneratedDerivedClasses : {{{gderived.py}}}, a tool used when implementing new types
  * BufferProtocol : Design of a Jython equivalent to the CPython buffer protocol (buffer API)
Line 150: Line 95:
== Other stuff ==
Line 151: Line 97:
    * WebsiteBuilderSetup : How to get the pieces setup to edit and build the Jython website
 * VersionTransition : Why some tests are excluded in going to a new version and how to go about fixing them
 * /RegressionTestNotes : Some notes the regression tests
 * /PleaseAdoptMe : Tasks looking for volunteers
 * HowToReleaseJython : Checklist for building a release and updating the website
 * SvnToHgMigration : Notes on the migration to Mercurial

== Tasks ==

  * PerformanceEnhancements : Ideas on how to speedup Jython
  * CodebaseCleanup : Tasks/general guidelines on keeping the codebase clean

=== Porting external projects to Jython ===

 * DjangoOnJython
 * MercurialOnJython
 * SqlAlchemyOnJython
 * SetuptoolsOnJython
 * PylonsOnJython
 * TwistedOnJython

This is an introduction to developing Jython, just to get someone started. It doesn't cover the source code in any depth or discuss the design behind Jython. It's purely aimed at getting a development environment set up. It's definitely not complete so feel free to make it better!

Mercurial

Subversion (Historical)

When Jython first followed CPython into use of Mercurial as the repository, it continued to reference a part of the CPython source at  https://svn.python.org  as a "sub-repository". This meant you still needed Subversion installed. As of 20 March 2012, the Jython Mercurial repository contains a snapshot of CPython libs in the 2.2, 2.5, and default branches.

You therefore only need the following advice if you are somehow working with an old repository.

The following advice is based on experience using Mercurial 1.9, Slik Subversion and Windows 7 (AMDx64). Other tools and operating systems exist. An installation that gives you the command 'svn' on your path is sufficient.

If you do not have Subversion installed (and on the PATH) the Mercurial hg clone command will terminate with the message:

abort: The system cannot find the file specified

at the point where it attempts to read the sub-repository, specified in the files  .hgsub  and  .hgsubstate .

A second requirement is that Subversion should accept the SSL certificate from the site svn.python.org. If you have not used Subversion already to access the site, you may find that the  hg clone  command hangs at the point where it attempts to read the sub-repository. A simple solution is to visit the site once from the command line as follows:

svn info https://svn.python.org/projects/python/branches/release26-maint/Lib/

Subversion will issue a warning about the certificate, and you will be able to "accept permanently" the site's certificate. The Mercurial clone operation should not now hang.

If you see the sub-directory  CPythonLib  created in your local repository, then the call to Subversion by Mercurial was a success. (It can take a few minutes to complete.)

Ant

  • Ant is a Java-based tool used to build Jython from source.

  • Eclipse users, see Eclipse Ant notes

  • Download the latest version (Jython requires Ant 1.7 or later to build) and install it so Ant's bin directory is somewhere in your path.

  • To build Jython, run ant in the top-level Jython directory (which contains the Ant file build.xml).

  • The results of the build appear in the dist subdirectory.

Tests

The Jython build process generates an executable Bash script, dist/bin/jython, to make it easy to launch your build of Jython. It works on Unix-like platforms (including Mac OS X and Cygwin).

If you're using Windows without Cygwin, use the batch file dist/bin/jython.bat instead.

Now you're ready to run tests...

  • There are a couple different places to find test cases
    • Jython's dist/Lib/test (populated by the build process)

    • Jython's bugtests subdirectory (included with the development sources)

  • Run a particular test, or the whole Python test suite with ant regrtest.

See TestingJython for some more details.

Directory layout

Note the following describes the current trunk/jython. If you are working from an older tag, src doesn't exist and src/com and src/org are moved up a level.

  • src/org : top level package for python

  • src/com : zxJDBC related sources

  • src/shell : launcher scripts

  • src/templates: java source generator & related templates, used to update portions of java classes elsewhere in the source tree

  • Demo : demo sources for the website and such

  • Doc : the website documentation (see /WebsiteBuilderSetup to build the http://jython.org website)

  • Lib : the python source files for Jython standard library implementations

  • Lib/test : test cases

  • Misc : random scripts which are not all used; some generate source

  • Tools : JythonC and Freeze

  • CPythonLib : Lib directory from the corresponding version of cpython, via svn:externals

  • bugtests : additional test cases covering bug reports

Coding guidance

How things work

Other stuff

Tasks

Porting external projects to Jython

JythonDeveloperGuide (last edited 2014-07-26 16:06:40 by HenningJacobs)