Archive for the ‘plugin’ tag
Using Pydev for Google App Engine development on a Mac
I’ve been experimenting with Google App Engine a bit recently and although it’s not without its problems, it fits really well with a couple of small projects I’m working on at the moment. Up until now, I’ve been mainly working with TextMate and the Google App Engine launcher, which is fine, but hardly an ideal development environment. That’s where Aptana Pydev comes in.
Pydev is an Eclipse/Aptana plugin for developing Python applications. It has great support for Django and other Python frameworks, and is a great all-round Python development tool. The feature that caught my eye the most was built-in support for Google App Engine development, but I ran into a few problems when I tried to get up and running with it on my Mac. In this post, I will walk through how I got it all working in the end.
There are several options for downloading Pydev. Eclipse developers can download it as a plugin, or if you don’t use Eclipse, Pydev comes bundled in Aptana Studio (an Eclipse-based IDE that is geared towards Web development). In this post I will cover the Aptana method, but it should be simple to extract the relevant parts if you are going down the plugin path.
Head to the Aptana Studio 3 download page (product in beta at time of writing) and download the disk image to your Mac. When you mount this image and open it, you should see a Finder window like the one in Figure 1.

Figure 1. Aptana Studio disk image
Follow the simple instructions and drag the Aptana Studio 3 folder into the Applications directory shortcut. This will install Aptana in your Applications directory. You will see the files being copied from the image as shown in Figure 2.

Figure 2. Copying files
When this is completed, you can open the Aptana Studio 3 folder in your Applications directory and launch Aptana by opening the AptanaStudio3.app file, as seen in Figure 3.

Figure 3. Finding AptanaStudio3.app
When you first launch Aptana Studio, you will see a blank workspace, as shown in Figure 4.

Figure 4. Blank Aptana Studio Workspace
Now it’s time for the fun stuff. First, you need to create a new project. Press [Cmd] + N to open the New Project wizard. In the list of Wizards, you should see a folder named “Pydev”. Expand this folder and you will find an option “Pydev Google App Engine Project”, as shown in Figure 5.

Figure 5. New Project Wizard
Make sure you’ve selected the correct option, and hit the Next > button to continue. On the next screen, you will need to enter details about the project, including the name of the project, the type of project (Python, Jython or Iron Python), the grammar version to use and the interpreter. Before you fill out this form, you’ll notice that there’s a link “Please configure an interpreter” in the related preferences before proceeding. This is shown in Figure 6.

Figure 6. PyDev Project Wizard
Click on this link and the main Aptana Preferences window will open, and you will be brought straight to the “Interpreter – Python” page of the Pydev preferences section. On the right-hand-side, there’s a list (currently empty) of Python interpreters, with two enabled buttons to the right of the list, New and Auto Config, as can be seen in Figure 7.
Warning: Don’t use Auto Config, on my system it found Python 2.6, and for Google App Engine development you’ll want to use Python 2.5.

Figure 7. PyDev Python Interpreter Preferences
Click the “New” button and Aptana will open the Select interpreter dialog. Enter the following values into the relevant fields:
- Interpreter Name: Python 2.5
- Interpreter Executable: /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
If you prefer, browse to the location of the executable and select it. The dialog should look like Figure 8.

Figure 8. Select interpretor
Press the OK button to add this interpreter. Aptana will do some preparation, and before long you’ll be presented with another dialog that needs your attention. This one looks like the screen grab in Figure 9.

Figure 9. Adding folders to the SYSTEM pythonpath
In my case I simply accepted the default selections and pressed OK, but if you need to, you can select the other options. When you press OK, you should be back in the Aptana Preferences window, which should now look more like Figure 10.

Figure 10. Updated PyDev Preferences
You can now close this screen by pressing OK in the bottom right of the window. After you do this, Aptana will go off and do some work, and you’ll see a window like the one shown in Figure 11. This might take a minute or two to complete so be patient.

Figure 12. Aptana background work
When this progress window closes, you’ll be back at the Pydev Project setup screen. Enter whatever project name you like, I’ve called mine “game-planner” which is the same as the application ID for my Google App Engine application. Make sure “Python” is selected as the Project Type, and change the Grammar Version to 2.5. If you only set up the Python 2.5 interpreter, you can leave the Intepreter set to “Default”, or alternatively you can change this to “Python 2.5″ if you are unsure. The completed project screen should look something like Figure 13.

Figure 13. Project dialog, filled out
Press the Next > button to move on to the next step of the Project Wizard. This step asks you to select the Google App Engine Directory. It is shown in Figure 14.

Figure 14. Google App Engine Directory
You can use the Browse button, but unless you downloaded the zip archive of the App Engine Python SDK, you will not be able to find the directory in Finder. This is because the SDK package that comes in the form of the “Google App Engine Launcher” is wrapped up in a .app archive, which can’t be explored in Finder. See Figure 15 for an example of this.

Figure 15. Cannot browse GoogleAppEngineLauncher.app
The location it is looking for is the location where the Google App Engine files dev_appserver.py, appcfg.py, the lib directory and so on are located. If you are using the launcher version of the SDK, this is usually in the following location:
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine
If you paste this into the Google App Engine Directory field, however, you’ll notice that it results in an error. This error is shown in Figure 16.

Figure 16. Error finding django lib directory
The reason for this error is relatively straightforward – Google App Engine doesn’t have a directory named django at that path. Apparently this issue will be fixed in the next release of Pydev. However, as seen in Figure 17, there are two other directories that are very similar, django_0_96 and django_1_2.

Figure 17. django directories that are available
To solve the problem, we can simply create a symbolic link named django, which will point to the django_0_96 directory. To do this, open Terminal (Applications > Utilities > Terminal) and issue the following commands:
$ cd /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/ $ ln -s django_0_96 django
If you issue the ls command after doing this, you should see that there is now what looks like a django directory. This is a soft link to the django_0_96 directory, and if any changes are made in django_0_96, they will automatically be reflected in the django directory. Sample Terminal output is shown in Figure 18.

Figure 18. Mac OS X Terminal Output
Next, go back to Aptana and enter the directory path again (cut it and re-paste it back) to refresh the wizard. This time, you should see a much friendlier result, like the one shown in Figure 19.

Figure 19. No errors this time around
Click Finish and the project will be created. You might be asked to switch to the Pydev perspective, as shown in Figure 20. It’s up to you whether you do this, I personally checked the Remember my decision field and pressed the Yes button.

Figure 20. Pydev Perspective
You should now be in your Pydev Google App Engine project. From here you can create, run and debug your Google App Engine applications. The default Pydev workspace is shown in Figure 21.

Figure 21. Pydev Eclipse Perspective
If you have any questions about this post, or have comments, suggestions or improvements, please leave a comment. Thanks for reading!
Twitter for WordPress on 2.7
Today, I upgraded my blog to WordPress 2.7, and while most of the upgrade went smoothly, I did notice that my Twitter plugin wasn’t showing new tweets anymore. I initially thought maybe it was a caching issue, or I had run out of API calls or something, but I returned hours later to find it in the same state. I tweaked with the function call to see if changing it would refresh the cache but nothing I tried made it work. I looked for a solution on the official plugin website and on WordPress.org, but none was available, so I decided to try and fix it myself. The following will fix the bug, but it involves turning off the MagPie cache used by the fetch_rss function. I don’t really know what this means, but the cache is likely there for a reason and turning it off is probably not ideal, or recommended. However, this did get my new tweets appearing again, so it will have to do until an official fix is released. If you want to do the same, here is how I did it:
- Log in to your WordPress Administration Interface (usually http://www.yoursite.com/wp-admin)
- On the navigation bar on the left hand side of the page, click on the Arrow next to Plugins. You should see an expanded submenu.
- From this submenu, click on “Editor” to bring up the Plugin Editor
- You should now see a large text editor with the code for the first of your plugins showing in it (Akismet in my case). On the right hand side should be a list of plugins. Find “Twitter for WordPress” in this list and click on the link.
- You should now be able to edit “twitter.php” in the text editor. Scroll down just below the copyright notice until you find the line: Â
define('MAGPIE_CACHE_AGE', 120); - Add a new line under this and paste the following:
define('MAGPIE_CACHE_ON', false); - Click the “Update” button at the bottom of the page to update the plugin file. That’s it, your twitter plugin should now be showing new tweets once again.
Note: your plugin file will need to be writable in order to perform the above procedure. If it’s not, either make it writable using an FTP client or SSH, or else simply edit the file manually by downloading it with FTP or via SSH. As I said above, this is almost definitely not the best solution to this problem, but one that should make do until an official fix is released by the plugin author.