Back to photostream

2008APR181138

Webpy Howto

 

For the moment I'm going to try using Webpy. Why?

 

Well I like the fact that Aaron could get an app up quickly without having to make lots of adjustments to existing code. I'm not so sure this is the case with django. Which bits can you use? What bits are being left out?

 

I suppose the biggest problem I have with django is the size of the codebase you have to upload. More code, more moving parts and the greater chance for something to go wrong. Plus the fact you have to use a hack to even start (django_bootstrap.py). I don't think this is the real problem though. The real problem starts when you have to set up your local application and try to get it to run on appengine. There is a couple of little tricks & problems I've found. The approach is far from seamless and prone to error that will compound adding large frameworks. Not a show stopper but annoying enough to slow you down. The google developers are really pulling the stops out for django support so don't assume not choosing django now will stop me using it in the future.

 

Problems

 

The following solutions below should give you enough information to get webpy up and running. If you have an questions thow a question to this google app-engine thread, twitter.com/bootload or email me. Below is a list of the problems you will encounter.

 

1) Cannot run webpy locally:

 

I've encountered a few problems. The first is "how do you run webpy locally?" The problem is you may have webpy installed, the webpy code (web tree) in your current directory. But how does your local code find it? [1] Hidden in the documentation is a hint to make a symbolic link to the code you wish to use. Here is how:

 

* We wish to use Webpy and "import web"

 

* make sure you have a copy of "bzr" (debian/ubuntu): "apt-get install bzr"

 

* download the latest (0.3) webpy install version (0.3): "bzr get webpy.org/bzr/webpy.dev/;

 

* install the latest webpy, cd into webpy.dev & install: "python setup.py install"

 

* in the directory you have installed your app-engine client, create a symbolic link to a newly created directory called "web" to your webpy installation.

 

* ln -s /usr/lib/python2.5/site-packages/web web

 

The result is something like this with the app-engine code, your code (helloworld & hellowebpy).

drwxr-xr-x 12 fb fb 4096 2008-04-18 20:09 .

drwxr-xr-x 18 fb fb 4096 2008-04-14 21:23 ..

-r-xr-xr-x 1 fb fb 1595 2008-04-03 11:05 appcfg.py

-r--r--r-- 1 fb fb 154 2008-04-03 11:05 BUGS

drwxr-xr-x 4 fb fb 4096 2008-04-16 22:16 demos

-r-xr-xr-x 1 fb fb 1713 2008-04-16 16:59 dev_appserver.py

drwxr-xr-x 5 fb fb 4096 2008-04-14 22:05 google

drwxr-xr-x 8 fb fb 4096 2008-04-03 11:05 google_appengine

drwxr-xr-x 6 fb fb 4096 2008-04-18 11:47 hellowebpy

drwxr-xr-x 6 fb fb 4096 2008-04-16 15:57 helloworld

drwxr-xr-x 5 fb fb 4096 2008-04-03 11:05 lib

-r--r--r-- 1 fb fb 4348 2008-04-03 11:05 LICENSE

drwxr-xr-x 2 fb fb 4096 2008-04-09 13:55 new_project_template

-r--r--r-- 1 fb fb 3476 2008-04-03 11:05 README

drwxr-xr-x 2 fb fb 4096 2008-04-09 13:55 templates

drwxr-xr-x 2 fb fb 4096 2008-04-09 13:55 tools

-r--r--r-- 1 fb fb 57 2008-04-03 11:05 VERSION

lrwxrwxrwx 1 fb fb 36 2008-04-16 23:11 web -> /usr/lib/python2.5/site-packages/web

 

This now allows you to run your webpy code on the development machine.

 

2) Run webpy remotely :

 

In your source code directory (in my case, hellowebpy) take a copy of the webpy.dev/web directory and paste it into hellowebpy/. The result is something like this:

drwxr-xr-x 6 fb fb 4096 2008-04-18 20:24 .

drwxr-xr-x 12 fb fb 4096 2008-04-18 20:09 ..

-rw-r--r-- 1 fb fb 223 2008-04-18 11:05 app.yaml

-rwxr--r-- 1 fb fb 844 2008-04-13 23:23 favicon.ico

-rw-r--r-- 1 fb fb 448 2008-04-18 11:47 hello.py

drwxr-xr-x 2 fb fb 4096 2008-04-18 11:07 images

-rw-r--r-- 1 fb fb 471 2008-04-18 11:47 index.yaml

drwxr-xr-x 2 fb fb 4096 2008-04-18 11:07 styles

drwxr-xr-x 2 fb fb 4096 2008-04-18 10:57 templates

drwxr-xr-x 4 fb fb 4096 2008-04-18 11:08 web

 

* cd up to the root directory with appcfg.py

* upload your code + the webpy "web" code using appcfg.py: "./appcfg --noisy -e foo@bar.com update hellowebpy/" (remember to use your email address)

 

3) Problems with errors and c-based code :

 

If you have installed code like Cheetah you will get an error saying you cannot run c-based code. The reason is the dev_appserver.py code assumes the Cheetah code you have is trying to make a call to some cPython code, strop (a C based, string library optomised for speed). [3] The solution is to un-install Cheetah from your system. The google app-engine code base has a modified version of Cheetah removing all C code based routines. Be warned.

 

4) Problems uploading new code? :

 

I've had problems updating code sometimes. I suspect caching is the problem. So go to your root directory in your account and search for ".app*". You should see the following files, .appcfg_cookies and .appcfg_nag. Delete them both. Create a new directory, delete the index.yaml and copy your old code into the new directory. Then re-run the upload sequence ... "./appcfg --noisy -e foo@bar.com update new_directory_with_your_code/"

 

Following these steps should allow you to run webpy. Remember the example Aaron shows is for version 0.3. It was mentioned in the google-appengine webpy post others managed to get 0.23 to work. Try what they suggest. The example code works as shown for 0.3.

 

Have fun.

 

Reference

 

[1] Google App Engine, Pure Python, "... You can include other pure Python libraries with your application by putting the code in your application directory. If you make a symbolic link to a module's directory in your application directory, appcfg.py will follow the link and include the module in your app ..."

 

code.google.com/appengine/docs/python/purepython.html

 

[2] Python docs, "common string manipulations, optimized for speed called by "import string" /usr/local/lib/python2.4/lib-dynload/strop.so"

 

pydoc.org/2.4.1/strop.html

 

<<< start

2,309 views
0 faves
0 comments
Uploaded on April 18, 2008
Taken on April 18, 2008