Friday, June 17, 2011

Getting started with Google app engine (python) + portable python

I fell in love with python a long long time ago. But somehow didn't get the time to work with google app engine. Now that a project came up that requires some of the cool features of google app engine (like mail receiving) I am working on it.

Getting the development launcher to work with portable python (for version 2.5.4) was slightly tricky in that you need to point to the python executable rather than the folder in which the executable is found. i.e in my case in "Google App Engine Launcher" go to Edit -- Preferences and notice the "Python Path". I needed to set it to "C:\PYTHON\App\pythonw.exe" OR "C:\PYTHON\App\python.exe"

Also I set the editor to pyscripter "C:\PYTHON\App\Pyscripter.exe" as shown.
Next when I click on edit in launcher now I can get a cool editor as shown.:
You can also view the files by using the file explorer in pyscripter using the active script option as shown:


Notice that not only can I view all the files in the same directory but also see my commit options since I have tortoise Hg installed:




NOTE : I have not yet managed to get debugging working with pyscripter .... stop reading here. For debugging with PyDev check this out :)
If you want to simply debug your application with pyscripter you can add the following folder to your PYTHONPATH environment variable "C:\Program Files\Google\google_appengine". The contents of this folder are shown:

You also need to add a pythonpath entry for select folders in"C:\Program Files\Google\google_appengine\lib"
The contents of this folder in my case are shown:


so the complete PYTHONPATH setting is : "C:\Program Files\Google\google_appengine;C:\Program Files\Google\google_appengine\lib\antlr3;C:\Program Files\Google\google_appengine\lib\django_0_96;C:\Program Files\Google\google_appengine\lib\fancy_urllib;C:\Program Files\Google\google_appengine\lib\graphy;C:\Program Files\Google\google_appengine\lib\ipaddr;C:\Program Files\Google\google_appengine\lib\simplejson;C:\Program Files\Google\google_appengine\lib\webob;C:\Program Files\Google\google_appengine\lib\yaml\lib"

Note my python path settings:
After you have set the pythonpath you MUST RESTART GAE Launcher. Now click edit and run main.py
You can see a successful break point below:
But this is just a script running outside a web server. You can launch the Google App Engine web server INSIDE of pyscripter to get the debugging goodness of a running web application as follows.

Notice the commandline for the python started by launcher using process explorer :
In my case it was : "C:\PYTHON\App\pythonw.exe "C:\Program Files\Google\google_appengine\dev_appserver.py" --admin_console_server= --port=8080 D:\CODETEST\npitracker\npitracker"

Now you are going to configure pyscripter to run the file "C:\Program Files\Google\google_appengine\dev_appserver.py" for us. 
Open this file in pyscripter and select run -- Command Line parameters.
Set the command parameters to your project as shown:

In my case I kept the command line parameters as : "--admin_console_server= --port=8080 D:\CODETEST\npitracker\npitracker"

Now setup a breakpoint anywhere cool in the project as shown:

Switch back to "dev_appserver.py" and run. Browse to your website (http://localhost:8080) in my case and enjoy the debugging goodness.

Note: (GAE version 1.5.0)

PS: for python path option in launcher "C:\PYTHON\App\" did not work. If I left it at that and run a project the browse button does not become enabled in the launcher and a busy indicator is shown next to the project.

Enjoy!