Geertjan is a DZone Zone Leader and has posted 457 posts at DZone. You can read more from them at their website. View Full User Profile

Interview: Allan Davis, nbPython Developer

06.20.2008
| 11308 views |
  • submit to reddit

Allan Davis recently posted a screencast of something called "nbPython", here, over on NetBeans.tv. Later, the screencast was reposted here on NetBeans Zone. Python is one of the handful of hot languages that is still missing support in NetBeans IDE and, now that the NetBeans language APIs are growing in versatility, the time is right for support being created for Scala and Groovy, for example, as well as, now, Python.

So let's meet Allan and find out what nbPython is all about and look under the hood at some of the API magic...

Can you tell us a bit about yourself, who you are and where and what you do?

Sure, my name is Allan Davis. I have been working in Software development for about 15 years. I started learning and using Java in 1998, gaining my SCJP in 2003. I began working with NetBeans in 2002, utilizing version 3.3. I have jumped around to different IDE's (JDeveloper, Eclipse, JBuilder, to name a few), always coming back to NetBeans, every time. Recently, I have built 3 different RCP applications.

Currently, I am working as a GIS/Java developer for General Dynamics. We are developing a web-based JSF map editor.

What's nbPython?

NbPython is an extension of the NetBeans IDE to provide support for the Python programming language.

How did it get started and why?

After having to do some GIS scripting with Python and pydev, I thought it would to be cool if I could use NetBeans. About the same time, NetBeans 6.0 was released with Ruby support. I realized that a Python extension would be a perfect fit. Recently, our office has started a switch from Eclipse to NetBeans as well, so, the needs keep growing for this development.

What does it aim to provide?

NbPython aims to provide first-class support for the Python language in NetBeans. This includes a full editor, interactive console, a Python platform manager, and Django support. The full editor includes syntax highlighting, code completion, editor hints, and numerous other features.

What does it provide right now?

Right now nbPython provides syntax highlighting, a basic Python project template, and basic execution of any Python script

You must have been using quite a few NetBeans APIs. Which ones and how has the experience been?

There have been a lot of changes to the API since I started working with NetBeans. For this project, one of my favorites has been GSF. GSF, or Generic Scripting Framework, is used to provide support for scripting languages such as Ruby, Python, and PHP. It has eased some of the load of coding requirements, allowing for easier coding milestones. The prime example of this is the Editor window itself:

The only items I have to define are the Lexer and a language file that extends DefaultLanguageConfig. I then create a link to GSF in the layer.xml, as per the examples below:

public class PythonLanguage extends DefaultLanguageConfig {

@Override
public String getLineCommentPrefix() {
return "#"; //NOI18N

}

public Language getLexerLanguage() {
return PythonTokenId.language();
}

public String getDisplayName() {
return "Python";
}

@Override
public String getPreferredExtension() {
return "py";
}

@Override
public Parser getParser() {
return new PythonParser();
}

@Override
@SuppressWarnings("deprecation")
public boolean hasStructureScanner() {
return true;
}

@Override
public StructureScanner getStructureScanner() {
return new PythonStructureScanner();
}

}
<folder name="GsfPlugins">
<folder name="text">
<folder name="x-python">
<file name="language.instance">
<attr name="instanceOf"
stringvalue="org.netbeans.modules.gsf.api.GsfLanguage"/>
<attr name="instanceClass"
stringvalue="net.java.dev.nbpython.editor.PythonLanguage"/>
</file>
<file name="structure.instance">
<attr name="instanceClass"
stringvalue="net.java.dev.nbpython.editor.PythonStructureScanner"/>
</file>
</folder>
</folder>
</folder>

Another great API for NetBeans is extExecution. This API allows for easing the creation of external execution processes in NetBeans. We use it for execution to both Jython and Cpython.

// Setup process Information 
ExternalProcessBuilder processBuilder =
new ExternalProcessBuilder(command);
processBuilder.pwd(new File(workingDirectory));
processBuilder.addArgument(commandArgs);
processBuilder.addArgument(script);
processBuilder.addArgument(scriptArgs);
processBuilder.addEnvironmentVariable("PYTHONPATH", path);
...
//build Service
ExecutionService service =
ExecutionService.newService(
(Callable<Process>) processBuilder.create(),
execBuilder.create(), displayName);
// Start Service
service.run();

The experience using these APIs has been very good. I can't complain about a thing.

Do you have tips to share with others doing similar things?

One of the biggest tips I can suggest is to utilize the mailing lists. Everyone is willing to share what they have done. Also, examples are posted and check out the "contrib" module, as well as "trunk". When I first began developing the Lexer module and trying to use ANTLR for grammar processing, I searched for an example on how to make this work. The one I found linked to the NetBeans 6.0 Lexer. This page pointed to code from the CVS Server that did not migrate to Mercurial. I posted a question to the development mailing list and was pointed to the javafx.editor module that was doing the same thing I was. After studying their code I was able to create the Lexer with no problem.

Is it just you or are there others working on it? Can others join in?

There is no way I could do this alone. The project is open, so anyone can join. I started out building a team from friends at work. We work on this project in our off-time. Interest in the project has been incredible. Not two days after posting the project pages on java.net, I started receiving feature requests. Stuff like that really fuels me. I have also had a lot of interest from Sun, Tor Norbye (Ruby) and Martin Adamek (Groovy) have been indispensable in helping to getting me going with GSF.

If you want to join, go to the project page (http://nbpython.dev.java.net). Request membership to the project, and while you are there sign up for the development mailing list (https://nbpython.dev.java.net/servlets/ProjectMailingListList).

What's the timeline from here on? How often and what will you be publishing next?

We are targeting to be in sync with the 6.5 release of NetBeans, with milestone releases about every 2 to 3 weeks. We want everyone to be able to see how the project progresses. In the next milestone release, there will be some editor enhancements and the Python platform manager.

How do I get started using it?

To start using the program, you can just download the bits from the project page under "Documents & files". There you will find archived downloads of all milestone files including the source code at that time. Or, if you are so inclined, you can check out the source code from Subversion. Then open up the project within the latest development build of NetBeans IDE and then... simply click "Run"!

AttachmentSize
AllanDavis_photo.jpg2.84 KB
nbpython-1.png16.18 KB
nbpython-2.png16.62 KB
nbPythonLogo.png18.6 KB
Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Bryan Low replied on Fri, 2013/02/01 - 10:32pm

Twin Fountains EC is a short drive away from Woodlands and Admiralty MRT Station. Future residents will be able to walk to the nearby Vista Point or a short drive to Causeway Point for some family fun and gatherings. A truly unique lifestyle awaits you.

http://twin-fountains.org 

Bryan Low replied on Thu, 2013/03/07 - 10:07pm

Hillview Peak has full and unique facilities, which includes a guard house, clubhouse, children's playground, swimming pool, Aerobic/Yoga room, piano room, pool room, indoor gym, hydrotherapy beds, hydrotherapy baths, reading room, function room, onsen, jacuzzi.

Hillview Condo

At Ppty replied on Mon, 2013/04/29 - 1:27am

Great Post. I have not been visiting the site recently. Took a visit again and there were some great comments on the site. Excellent post. Keep up the good work.Corals at Keppel Bay 

At Ppty replied on Wed, 2013/05/08 - 5:29am

Thanks for your insight for your fantastic posting. I’m glad I have taken the time to see this. The Trilinq 

Bryan Skyvue replied on Sun, 2013/09/15 - 1:40am

Several buses are available near Bishan Road and Ang Mo Kio Ave 1 along with shopping centers and restaurants near Sky Vue Condo Sky Vue Project Details

Jurongwestcondo... replied on Tue, 2013/10/08 - 11:05pm

Also, it is right beside Jurong Stadium as well as the Jurong Archery Club. Entertainment for your loved ones and friends are therefore at your fingertips with the full condo facilities as well as the amenities near New Condo in Jurong. location of jurong west condo

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.