Skip to main content

A recipe for Buildout (zc.buildout) to install Jython

Project description

This is a Buildout recipe that automates the download, configuration, and deployment of Jython, the Python environment implemented in Java.

Introduction

Java 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 Information

Project home page

http://code.google.com/p/buildout-recipes/

Source repository

http://buildout-recipes.googlecode.com/svn/recipes/sk.recipe.jython

Issue tracker

http://code.google.com/p/buildout-recipes/issues/list

Installation

Since this is a Buildout recipe, there’s nothing really to install. Just mention the recipe name in a buildout and enjoy! For example, your buildout.cfg might 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 = myegg

The above buildout accomplishes the following:

  • Specifies a Python egg in-development in src/myegg.

  • Downloads and installs Jython.

  • Creates a new interpreter bin/mypy pre-baked with myegg and powered by Jython.

Easy!

Supported Options

The sk.recipe.jython recipe supports the following options:

url

(Optional.) URL to a release of Jython. If not given, defaults to the URL to the 2.5.1 release of Jython. This URL must point to a Jython installer jar file.

md5sum

(Optional.) MD5 hash of the Jython installer mentioned by url. If specified, the downloaded Jython release will be checked against this hash and installation will not proceed if there’s a mismatch. If both md5sum and url are 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. This java executable will be invoked to install Jython only, not for Jython’s runtime. Example: /usr/java/j2sdk/bin/java.

jre

(Optional.) Home directory of a Java runtime or development kit used to run Jython. Specify this if you wish to have Jython use a separate runtime from that of the installer. Unlike the java option above, the jre option expects the home directory of a Java runtime; i.e., there will be bin, 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’s parts/jython directory (you can override the parts directory in the [buildout] itself). That means your recipe can be as simple as:

[jython]
recipe = sk.recipe.jython

This recipe exports two values that are handy in other recipes:

location

This exported option identifies where the recipe installed Jython. You can use its value as the JYTHON_HOME environment variable.

executable

This exported option names the path of the jython executable. You can use this as a Python interpreter, for example with the zc.recipe.egg collection of recipes.

Installable Parts

Jython consists of a number of parts that comprises an installation. The include-parts option specifies which extra parts to include in an installation (by default, no additional parts are installed). The additional parts are:

  • mod: Library modules.

  • demo: Demonstrations and example code.

  • doc: Documentation.

  • src: Source code to Jython.

Example Usage

For 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 the testdata directory:

>>> import os.path
>>> testdata = join(os.path.dirname(__file__), 'testdata')

The file java is actually an executable Python script, while jython-fake.jar is 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 jython

Using Additional Options

Let’s exercise the jre and include-parts options, specifying a mythical JRE at /usr/mythical/java/j3sdk and 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 Hashes

Let’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 is not the correct MD5 for an empty file (which is what jython-fake.jar is). 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.

Changelog

0.0.0

This release is destined to become the eventual GA release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sk.recipe.jython-0.0.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distributions

sk.recipe.jython-0.0.0-py2.6.egg (14.9 kB view details)

Uploaded Source

sk.recipe.jython-0.0.0-py2.5.egg (14.9 kB view details)

Uploaded Source

sk.recipe.jython-0.0.0-py2.4.egg (14.9 kB view details)

Uploaded Source

File details

Details for the file sk.recipe.jython-0.0.0.tar.gz.

File metadata

File hashes

Hashes for sk.recipe.jython-0.0.0.tar.gz
Algorithm Hash digest
SHA256 ae88d1ff18812cb9049f7e2b02a891c53154e87ee523b7b1244d72865f73082c
MD5 af0294051de3c4c15935d557c268337b
BLAKE2b-256 9c47e4206f3a4e1ffcf959356cd9e6dc173a13807be05ef3cfedda597d6c3a23

See more details on using hashes here.

File details

Details for the file sk.recipe.jython-0.0.0-py2.6.egg.

File metadata

File hashes

Hashes for sk.recipe.jython-0.0.0-py2.6.egg
Algorithm Hash digest
SHA256 52c223b122bab1f4235a4183c40a02a2e4c9e46a13287116eead24c3e76c6d2c
MD5 355cc87b2ad8c20caf028937dc7476a0
BLAKE2b-256 8170a0e6a5a49459adb1afed52f289ec031ec587c1369d04054ef8faa230dcc4

See more details on using hashes here.

File details

Details for the file sk.recipe.jython-0.0.0-py2.5.egg.

File metadata

File hashes

Hashes for sk.recipe.jython-0.0.0-py2.5.egg
Algorithm Hash digest
SHA256 3c6d35ce615aa93481f28f60470ae0078592aeb55904061477b4a64cb67d0bd1
MD5 95c9c172b343d9895808dda871149b83
BLAKE2b-256 e0f9a5438616c3050f06ca94bedd7b4f1d1fff6031d8434d53607c425356ecea

See more details on using hashes here.

File details

Details for the file sk.recipe.jython-0.0.0-py2.4.egg.

File metadata

File hashes

Hashes for sk.recipe.jython-0.0.0-py2.4.egg
Algorithm Hash digest
SHA256 1c8f3c1ef2e1c7d47c453c3bcf661ac23cd458ae506c78025acf71ff72398c87
MD5 433c01780b5ecbb987a75440e9f6660f
BLAKE2b-256 b950616e0dba715a20496427fdc83e4d0b5d0df537a19aebcd5d16bdef4874ea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page