Showing posts with label PyDev. Show all posts
Showing posts with label PyDev. Show all posts

Friday, December 3, 2010

Python Code Style

Code conventions are important in software development. In Python, where whitespace (specifically indentation) can have a functional impact on your software, coding conventions are critical, especially when code needs to be shared and reused.

Python does have a widely accepted (and widely tweaked) Style Guide called PEP 8. I saw it a while ago but didn't have the time to digest and then laboriously apply it to my active codebases.

When I recently rebooted my development environment on Ubuntu and Mac OSX I noticed the PyDev IDE (now shipping with Aptana Studio)  had support for PyLint. PyLint - like other 'linting' programs - can examine your code and find non-compliances to a specific standard of code formatting. PyLint, when used as commandline tool, can provide a detailed report on your code style.

The great thing about the integration with PyDev, however, is that PyLint shows non-compliances in your currently open files and flags them as warnings and problems in your problems view. This makes deciding to implement and meet a code standard a lot less cognitively burdensome.

PyLint also highlights bad code smells - components and practices which don't smell right that might need refactoring. PyLint can be given global instructions to ignore certain issues, or specific source files can include comments to change how PyLint analyses the file. This gives some ability to customise the behaviour and ignore PyLint where pragmatic.

To enable PyLint in PyDev, first make sure PyLint is installed. Installing PyLint is as easy as installing any python program:

$sudo easy_install pylint

If you have different python versions in your environment, use the correct invocation of SetupTools for that version. I need to target Python2.5 for Google App Engine, so I use:

$sudo easy_install-2.5 pylint

Once pyLint is installed, within Eclipse (or Aptana etcetera) visit the Preferences page and specifically the PyDev > PyLint section in the hierarchy. Locate the actual PyLint script (lint.py) and enable PyLint.

PyLint is really helping me clean up my code (I admit it - I am a recovering tab-fiend).

Monday, November 8, 2010

Quick Note: Eclipse and Subclipse on Ubuntu (for Appengine)

I have previously written about configuring PyDev on top of an Eclipse/Aptana installation for Google App Engine development. Now on the Ubuntu platform instead of the windows, the process is easier these days since Pydev ships with the new Aptana Studio 3 Beta.

I thought I would write a quick note to future Ben (i.e. me) about configuring Eclipse and Subclipse on Ubuntu. Subclipse is a Subversion plugin for Eclipse (the alternative is Subversive, which I haven't tried).

Briefly my Eclipse install (for reference):

  • sudo apt-get install eclipse (if using eclipse base install)
  • Install Aptana Studio 3 beta, either standalone or as Eclipse plugin
  • Install Google plugin for Eclipse from within Eclipse (page with download sites)
  • Configure Python 2.5 interpreter within Eclipse (assuming you have already installed Python 2.5)
  • Create new Google App Engine project (under PyDev grouping)
  • Configure Python Library Paths for Eclipse
To add Subclipse:
  • sudo apt-get install subversion
  • sudo apt-get install libsvn-java
  • install subclipse within Eclipse (download sites)
Since I eventually managed to install Python 2.5 I've had a great experience installing software on Ubuntu. I've experienced some detours but none of them have been too long. Let me know if I have missed anything, or could have done something better.

Tuesday, July 14, 2009

Running App_DevServer.py from Pydev

In my earlier post about setting up a Python Development environment for Google App Engine I mentioned I was going to explore using Aptana Studio for my Python for Google App Engine editing. So far this is going well and has been very easy to set up. Even better, for the moment PyDev seems to be bundled more or less exactly as it used to be when PyDev was independent. This is good news from the perspective that PyDev documentation and tips you can find online are still very valid.

Setup instructions for virgin eclipse installs:

  1. Go to the Aptana website and download the Aptana Studio standalone (if you have an existing Eclipse installation you can add it as a plugin as well).
  2. Install Aptana Studio
  3. From the 'My Aptana' homepage within Aptana, click on the Plugins section and click on the 'Get It' link for Aptana PyDev to install python support.
  4. From there, follow Joscha Feth's setup instructions from step 3 of Installing PyDev on Eclipse. These useful instructions explain how to set the Python interpreter correctly and what step you need for each project to bring in the Google App Engine python libraries and setup a Run configuration.
When I setup my Run configuration I ran into an issue where it seemed Eclipse was ignoring my specified arguments. When I ran the project, the dev_appserver.py script rightly complained it did not have the correct arguments.

After scouting out a couple of other websites (like this one) I cottoned on to the fact that if your project location path contains spaces, you need to place the argument in quotes, like so:

"${project_loc}/src"

This all makes perfect sense (and obvious), but in my case I was worrying the problem was something more serious. The fact that Eclipse/PyDev's own command-line inspection function was freaked out by the space (and therefore ended prematurely) meant I could not see the commandline which I hope would have clued me into the problem sooner.

The problem only took a few minutes to figure out, but maybe this post will assist someone else is spending 1 or 2 minutes less. Happy learning!