Package: sk.recipe.jython
This is aBuildoutrecipe that automates the download, configuration, and
deployment ofJython, thePythonenvironment implemented inJava.IntroductionJava is a statically-typed, object-oriented, compiled programming language with
a vast standard application programmer interface (API) as well as enterprise
API.  Python is a dynamically-typed, object-oriented scripting language with a
vast API but fewer enterprise features.  Jython brings the agility of Python
to the elephantine vastness of Java by implementing the Python runtime in Java
and providing access to Java’s APIs.Buildout is a civilized, coarse-grained environment for managing repeatable
software deployments.  Buildout is driven by recipes, each of which accomplish
a specific goal, often in a cross-platform method.  This recipe,sk.recipe.jython, enables the user to automatically download, configure,
and deploy Jython in a Buildout environment.Developer’s InformationProject home pagehttp://code.google.com/p/buildout-recipes/Source repositoryhttp://buildout-recipes.googlecode.com/svn/recipes/sk.recipe.jythonIssue trackerhttp://code.google.com/p/buildout-recipes/issues/listInstallationSince this is a Buildout recipe, there’s nothing really to install.  Just
mention the recipe name in a buildout and enjoy!  For example, yourbuildout.cfgmight be something like this:[buildout]
develop = src/myegg
parts =
    jython
    myegg
[jython]
recipe = sk.recipe.jython
[myegg]
recipe = zc.recipe.egg
python = jython
interpreter = mypy
eggs = myeggThe above buildout accomplishes the following:Specifies a Python egg in-development insrc/myegg.Downloads and installs Jython.Creates a new interpreterbin/mypypre-baked withmyeggand powered
by Jython.Easy!Supported OptionsThesk.recipe.jythonrecipe supports the following options:url(Optional.) URL to a release of Jython.  If not given, defaults to the URL to the
2.5.1releaseof Jython.  This URL must point to a Jython installer jar
file.md5sum(Optional.) MD5 hash of the Jython installer mentioned byurl.  If
specified, the downloaded Jython release will be checked against this hash
and installation willnotproceed if there’s a mismatch.  If bothmd5sumandurlare missing, then the recipe will check the 2.5.1
release for its proper MD5 hash, 2ee978eff4306b23753b3fe9d7af5b37.java(Optional.) Full path to a Java virtual machine executable.  If not
specified, the recipe will find one by shell path.  Thisjavaexecutable will be invoked toinstallJython only, not for Jython’s
runtime. Example:/usr/java/j2sdk/bin/java.jre(Optional.) Home directory of a Java runtime or development kit used torunJython.  Specify this if you wish to have Jython use a separate
runtime from that of the installer.  Unlike thejavaoption above, thejreoption expects the home directory of a Java runtime; i.e., there
will bebin,lib, etc., directories in the directory named by this
option.  Exampe:/System/Library/Frameworks/JavaVM.framework/Home.include-parts(Optional.) List of parts to install.  See “Installable Parts” below.  If
not specified, you’ll get a minimal Jython installation, which is more
than likely what you’ll want if you’re developing Jython-based
applications.All options are optional.  Really.  By default the recipe makes a complete
Jython installation in the Buildout’sparts/jythondirectory (you can
override the parts directory in the[buildout]itself).  That means your
recipe can be as simple as:[jython]
recipe = sk.recipe.jythonThis recipe exports two values that are handy in other recipes:locationThis exported option identifies where the recipe installed Jython.  You
can use its value as the JYTHON_HOME environment variable.executableThis exported option names the path of thejythonexecutable.  You can
use this as a Python interpreter, for example with thezc.recipe.eggcollection of recipes.Installable PartsJython consists of a number of parts that comprises an installation.  Theinclude-partsoption specifies which extra parts to include in an
installation (by default,noadditional parts are installed).  The
additional parts are:mod: Library modules.demo: Demonstrations and example code.doc: Documentation.src: Source code to Jython.Example UsageFor this demonstration, we’ll use a fanciful Jython installer jar (actually an
empty file) and Java virtual machine (written in Python) to mimic what the
actual an Jython installer does.  In actuality, it merely echoes the options
given to it.  These files are in thetestdatadirectory:>>> import os.path
>>> testdata = join(os.path.dirname(__file__), 'testdata')The filejavais actually an executable Python script, whilejython-fake.jaris an empty file.Let’s create a buildout to build and install Jython:>>> write(sample_buildout, 'buildout.cfg', '''
... [buildout]
... parts = jython
...
... [jython]
... recipe = sk.recipe.jython
... java = %(testdata)s/java
... url = file://%(testdata)s/jython-fake.jar
... ''' % dict(testdata=testdata))This will “download” the fake Jython installer and install it with all parts.
Running the buildout:>>> print system(buildout)
Installing jython.
"JVM": Jython installer in file ".../jython-fake.jar"
"JVM": Installer options: ['--silent', '--directory', '/sample-buildout/parts/jython']And the parts directory should now have Jython installed:>>> ls(sample_buildout, 'parts')
d jythonUsing Additional OptionsLet’s exercise thejreandinclude-partsoptions, specifying a
mythical JRE at/usr/mythical/java/j3sdkand asking for the documentation
(doc) and source code (src) to be installed:>>> write(sample_buildout, 'buildout.cfg', '''
... [buildout]
... parts = jython
...
... [jython]
... recipe = sk.recipe.jython
... java = %(testdata)s/java
... jre = /usr/mythical/java/j3sdk
... include-parts =
...     doc
...     src
... url = file://%(testdata)s/jython-fake.jar
... ''' % dict(testdata=testdata))Re-running the buildout now gives us:>>> print system(buildout)
Uninstalling jython.
Installing jython.
"JVM": Jython installer in file ".../jython-fake.jar"
"JVM": Installer options: ['--silent', '--directory', '/sample-buildout/parts/jython', '--jre', '/usr/mythical/java/j3sdk', '--include', 'doc', 'src']Perfect.MD5 HashesLet’s re-write the buildout but inject an error: an incorrect MD5 hash:>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... parts = jython
...
... [jython]
... recipe = sk.recipe.jython
... java = %(testdata)s/java
... md5sum = c120503f1e327388bd0b6bbdee530733
... url = file://%(testdata)s/jython-fake.jar
... ''' % dict(testdata=testdata))The hash shown above isnotthe correct MD5 for an empty file (which is whatjython-fake.jaris).  Running the buildout should bail:>>> print system(buildout)
Uninstalling jython.
Installing jython.
While:
  Installing jython.
Error: MD5 checksum mismatch...Specifying the correct MD5:>>> write(sample_buildout, 'buildout.cfg',
... '''
... [buildout]
... parts = jython
...
... [jython]
... recipe = sk.recipe.jython
... java = %(testdata)s/java
... md5sum = d41d8cd98f00b204e9800998ecf8427e
... url = file://%(testdata)s/jython-fake.jar
... ''' % dict(testdata=testdata))Makes the problem go away:>>> print system(buildout)
Installing jython.
"JVM": Jython installer in file ".../jython-fake.jar"
"JVM": Installer options: ['--silent', '--directory', '/sample-buildout/parts/jython']That’s pretty much it.Changelog0.0.0This release is destined to become the eventualGArelease.