'Don''t repeat yourself: distribute jython package with jip.dist'

Thu 14 April 2011
  • ANN tags:
  • jip
  • jython
  • python published: true comments: true

As a new feature in jip 0.4, we can use some helpers from jip.dist to simplify package distribution. With jip.dist, you can define Java dependencies for your jython package. In an environment with jip, dependencies will be automatically installed when user uses pip to get you package.

We have two different approaches allow you to choose.

Approach 1, Define dependencies in POM

This is the standard maven way. To describe your jython package and its dependencies, create a pom.xml in your project. The directory hierarchy looks like:
├── app
│   ├── module1
│   │   ├── __init__.py
│   ├── core.py
│   ├── __init__.py
├── LICENSE
├── MANIFEST.in
├── pom.xml
├── README
└── setup.py

In pom.xml, just add dependencies as you do with Maven.
[cc lang="xml"] xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

...

org.slf4j slf4j-api 1.6.1

org.slf4j slf4j-log4j12 1.6.1

...

sonatype-oss-sonatype http://oss.sonatype.org/content/repositories/snapshots/ [/cc]
You can also define repositories in pom.xml if you use custom repository. (for example, jboss, java.net)

Remember to add pom.xml in your MANIFEST.in, to ensure the file will be packaged into source package:
[cc lang="text"]
include pom.xml
[/cc]

Approach 2, Define dependencies with Python

You may be tired with endless XML configuration. jip allows you to define dependencies with python, just like gradle with groovy.

In your setup.py, add something like:
[cc lang="python"]
requires_java = {
'dependencies':[
## (groupdId, artifactId, version)
('org.slf4j', 'slf4j-api', '1.6.1'),
('org.slf4j', 'slf4j-log4j12', '1.6.1'),
('info.sunng.soldat', 'soldat', '1.0-SNAPSHOT'),
('org.apache.mina', 'mina-core', '2.0.2')
],
'repositories':[
('sonatype-oss-snapshot', 'http://oss.sonatype.org/content/repositories/snapshots/')
]
} [/cc]

Then pass it to setup(). The keyword argument require_java is jip specific.
[cc lang="python"]
setup(
...
requires_java=requires_java,
...)
[/cc]

Use jip's setup wrapper

To use jip's power, the only difference is to use setup() from jip.dist instead of setuptools or distutils.
[cc lang="python"]
from jip.dist import setup
[/cc]

Then publish your jython package to Python Cheese Shop: $ jython setup.py sdist upload

Internally, jip uses setuptools. So you can still do jython setup.py develop .

And jip 0.4 is available under MIT License. You are free to use jip.dist in your code.

For your user

You should write a guide forcing users to use your jython application within virtualenv. And install jip as a prerequisite: $ pip install jip

Then simply install your package with pip: $ pip install <your-package-name>

No additional step required!

So please just release your jython package with jip !

For more information: