IntroductionThis is a tutorial on getting the basic tutorial code for Pyramid running on appengine. Its based on predefined project. A paster based template to build the project will come later. DetailsThis setup assumes your using linux. Code and buildout config for the tutorial is found at http://bfg-pages.googlecode.com/svn/pyramid-gae-tutorial/trunk SetupTo do the setup I am going to use a buildout recipe developed by Rodrigo Moraes <rodrigo moraes at gmail com>. Recipe at http://pypi.python.org/pypi/appfy.recipe.gae/0.9.1. Make a directory for your tutorial. timh@chrome:~$ mkdir tut1 timh@chrome:~$ cd tut1 Then setup virtualenv so you can install the buildout recipe. timh@chrome:~/tut1$ virtualenv --no-site-packages --python=/usr/bin/python2.5 . Running virtualenv with interpreter /usr/bin/python2.5 New python executable in ./bin/python2.5 Also creating executable in ./bin/python Installing setuptools............done. Don't activate the virtualenv. Use explicit paths when referencing scripts set up by virtualenv. Now use easy_install to install the appfy.recipe.gae timh@chrome:~/tut1$ ./bin/easy_install appfy.recipe.gae Next check out the sample app which has the bootstrap and buildout configs to be used for the rest of the tutorial. timh@chrome:~/tut1$ timh@chrome:~/tut1$ svn checkout http://bfg-pages.googlecode.com/svn/pyramid-gae-tutorial/trunk app A app/default_error.html A app/settings.yaml A app/app.yaml A app/pkg_resources.py A app/views.py A app/bootstrap.py A app/buildout.cfg A app/lib A app/lib/dist A app/utils.py A app/static A app/static/logo.png A app/static/pylons.css A app/static/favicon.ico A app/tests.py A app/models.py A app/main.py A app/templates A app/templates/mytemplate.pt Checked out revision 159. Next we need to create some symlinks to varios .cfg files required for buildout. timh@chrome:~/tut1$ ln -s app/buildout.cfg timh@chrome:~/tut1$ ln -s app/bootstrap.py timh@chrome:~/tut1$ ln -s app/gaetools.cfg timh@chrome:~/tut1$ ln -s app/versions.cfg make a var/downloads so that buildout can cache its downloads. timh@chrome:~/tut1$ mkdir -p var/downloads Then run bootstrap.py which sets up the environment (this will use distribute) timh@chrome:~/tut1$ ./bin/python bootstrap.py ... stuff happens ... Now run buildout, which will download and install pyramid and all of it's dependancies in app/lib/dist. This recipe unpicks the eggs and only deploys the required files. timh@chrome:~/tut1$ ./bin/buildout ... stuff happens ... timh@chrome:~/tut1$ Now start the dev server. timh@chrome:~/tut1$ bin/dev_appserver app INFO 2010-12-03 15:24:27,784 appengine_rpc.py:153] Server: appengine.google.com WARNING 2010-12-03 15:24:27,788 datastore_file_stub.py:573] Could not read datastore data from /home/timh/tut1/var/data.store INFO 2010-12-03 15:24:27,816 dev_appserver_main.py:485] Running application pyramid-gae-tutorial on port 8080: http://localhost:8080 WARNING 2010-12-03 15:24:33,924 main.py:20] Starting main Point your web browser at http://localhost:8080/ and something similar to below will appear in the terminal INFO 2010-12-03 15:24:34,171 dev_appserver.py:3317] "GET / HTTP/1.1" 200 - This sample app has been deployed on appspot. You can see it at http://pyramid-gae-tutorial.appspot.com/ Details of the sample appNow lets look at the difference between this sample app and the one in the original tutorial. things to discuss. whats in the app + app
+ lib
+ dist
#unpicked pyramid and it's dependancies
+ chameleon
+ mako
+ markupsafe
+ paste
+ pyramid
+ README.txt
+ repoze
+ simplejson
+ tests
+ translationstring
+ venusian
+ webob
+ zope
app.yaml
default_error.html
main.py
pkg_resources.py
+ static
favicon.ico
logo.png
pylons.css
+ templates
mytemplate.pt
tests.py
views.py
You will also note there are the .cfg files that you created the symlink to eariler. These are not part of the appengine application. (I need to stick them somewhere else ;-) The contents of lib are as a result of running buildout, which installs pyramid from PyPI eggs and all of its dependancies and then proceeds to copy the actual code from the eggs to lib/dist (I need to move everything up to dist, thats a hold over from the original recipe for tipfy, which I am leveraging off) main.pyimport logging
logging.getLogger().setLevel(logging.INFO)
import sys,os
sys.path.insert(0,'lib/dist')
from pyramid.configuration import Configurator
from models import get_root
from google.appengine.ext.webapp.util import run_wsgi_app
settings = {
'reload_templates': 'false',
'debug_authorization': 'false',
'debug_notfound': 'false',
'debug_templates': 'false',
'default_locale_name': 'en',
}
def main():
""" This function runs a Pyramid WSGI application.
"""
config = Configurator(root_factory=get_root,settings=settings)
config.add_view('views.my_view',
context='models.MyModel',
renderer='templates/mytemplate.pt')
app = config.make_wsgi_app()
run_wsgi_app(app)
if __name__ == '__main__':
main()
Deploying the app
Running testsput stuff here ... Some important info/links for appengineImport things to notehere are some random things a pyramid developer new to appengine needs to know.
Important links to documents and/or resources
|
No need to use activate and bin/easy_install. Better not to use activate and use local paths instead (consistently), i.e. also when running buildout.
Note that when starting the development server, bin/dev_appserver should be bin/dev_appserver app.
Hi Rich.
At least in my install the "app" bit is optional. Though I would say makes things a little clearer.
Hi Charlie. I have made you suggested changes. It's probably a good idea for people to not get in the habit activating ;-)
Rich, I have changed the bin/dev_appserver to bin/dev_appserver app
Tim, you've been to judicious with the scalpel! It still says "Activate the virtualenv".
Oops, yep missed that one, thanks
i got an error upon ./bin/buildout:
$ ./bin/buildout Updating gae_sdk. Installing gae_tools. While:
An internal error occurred due to a bug in either zc.buildout or in a recipe being used: Traceback (most recent call last):
File "/home/bshanks/prog/myapp/lib/python2.5/site-packages/zc.buildout-1.5.2-py2.5.egg/zc/buildout/easy_install.py", line 1460, in write_script IOError: 26? Text file busy: '/home/bshanks/prog/myapp/bin/python'doing this instead works (putting the virtualenv in ./python instead of . ):
mkdir pyramid2
cd pyramid2
virtualenv --no-site-packages --python=/usr/bin/python2.5 python
python/bin/easy_install appfy.recipe.gae
svn checkout http://bfg-pages.googlecode.com/svn/pyramid-gae-tutorial/trunk app
ln -s app/versions.cfg
ln -s app/gaetools.cfg
ln -s app/buildout.cfg
ln -s app/bootstrap.py
mkdir -p var/downloads
python/bin/python bootstrap.py
python/bin/buildout
#to run:
bin/dev_appserver app
#to deploy:
bin/appcfg update app
however, how is one supposed to do this on Windows? does one just use "mlink" instead of "ln"?
Sorry I don't do any development in windows. I would just copy those files rather than linking them
bshanks3: I've never gotten Pyramid and GAE to work under Windows. Let me know if you have a reliable method! I use VirtualBox? to run Ubuntu under Windows where necessary.
Tim: you might be interested to know you inspired me to write a very basic tutorial based in part on your work here, after you mentioned that it was possible to deploy to App Engine without using Paster in an IRC conversation a few months back. It's up at http://www.eloquentgeek.com. I'm hoping to develop the blog it uses as a test case into something a bit more functional. I'd welcome your suggestions and corrections. It doesn't have a comment facility yet though!
rich: cool. Glad to see some other people starting to look at making appengine/pyramid an easier route to take.
Now I get this error:
Getting distribution for 'Chameleon>=1.2.3'. The required version of distribute (>=0.6.14) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U distribute'.
(Currently using distribute 0.6.10 (/home/bshanks/prog/pietrust/pie-share-pyramid/python/lib/python2.5/site-packages/distribute-0.6.10-py2.5.egg)) error: Setup script exited with 2 An error occurred when trying to install Chameleon 2.0-rc6. Look above this message for any errors that were output by easy_install. While:
Error: Couldn't install: Chameleon 2.0-rc6None of the buildout approaches have worked for me out of the box, but I finally just took the time to hack this one into submission. A more refined explanation will follow but one thing that absorbed far too much time was a pkg_resources loader error which was ultimately solved by the following block stolen from appengine_monkey (add it to main.py):
try: import pkg_resources except ImportError: pass else: if hasattr(os, '__loader__'): # This only seems to apply to the SDK pkg_resources.register_loader_type(type(os.__loader__), pkg_resources.DefaultProvider)The modifications that I've had to make to this are outlined here:
http://whippleit.blogspot.com/2011/04/pyramid-on-google-app-engine-take-1-for.html
I'm getting this error when running buildout.
RuntimeError?: On Python 2, Pyramid requires Python 2.6 or better An error occurred when trying to install pyramid 1.3.2. Look above this message for any errors that were output by easy_install. While:
Error: Couldn't install: pyramid 1.3.2