Thursday, February 05, 2009

Developing Django-Jython Using Netbeans

If you are interested in using Django on Jython, then you will need to incorporate the Django-Jython project into your Jython installation after Django has been installed. The Django-Jython project facilitates the use of Jython's zxJDBC database infrastructure in order for Django to access database backends. At this time, the only fully supported database is Postgresql, but there are also experimental backends for using SQL Server, sqllite, and Oracle under development. In order to use Django on Jython with another database or to assist in the development of these backends, you will need to download the Django-Jython project source code and write your own backend or update one which already exists.

Working with the Django-Jython project using a text editor is one way to go, but if you are used to the automation and simplicity of using an IDE, text editing can be a painful experience. This blog will walk you through the steps of setting up an environment within Netbeans 6.5 for developing the Django-Jython project.

The process of development with Django-Jython is as follows:

1. Download source for project

2. Add/Modify source code to facilitate your needs

3. Build the source and install it into your Jython home

Number 1 above is easy enough, just visit the Django-Jython project page. However, numbers 2 and 3 are manually performed processes. You can help to automate these processes by using the power of Netbeans. Simply follow the procedure below to set up the environment:

1) Create a Python project with existing sources and name it something like "DjangoJython"




2) Add the root-level directory of the "django-jython" source folder to the "Source Root Folders" window area when creating the project, then click finish.


At this point your project will be created and you can work with the source. However, we need a way to tell the IDE to build and install the project. You can either use the command-line to do so by traversing to the project folder and issuing:

jython setup.py build, followed by, jython setup.py install

Or, you can perform have Netbeans IDE build the project for you when you invoke the "Run" process on the project by performing step 3.

3) Right-click on the project, and choose "Properties". Select the "Run" category and then enter "setup.py" as the main module and enter "install" into the application arguments text field. Now, each time you elect to "run" the project, it will cause netbeans to build and install it.




The only caveat to using this method of building and installing Django-Jython is that you will need to manually delete the "build" directory in your DjangoJython Netbeans project as well as delete the "doj" directory from your Jython installation (Jython-Path/Lib/site-packages/doj) prior to issuing "run" each time. I have found that if you do not, sometimes all of the updated modules are not reinstalled. Deleting these directories prior to running your build/install forces a new build and install to take place each time.

Now, enjoy the great development experience of Netbeans while contributing to a great project...Django-Jython! Have fun!

No comments:

Post a Comment

Please leave a comment...