Skip to content
This repository
Newer
Older
100644 231 lines (161 sloc) 7.265 kb
4ad6d42d » Chris McDonough
2009-05-14 General cleanup.
1 .. _appengine_tutorial:
2
fd5ae92b » mcdonc
2010-11-09 - All references to Pyramid-the-application were changed from :mod:`p…
3 Running :app:`Pyramid` on Google's App Engine
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
4 ================================================
5
fd5ae92b » mcdonc
2010-11-09 - All references to Pyramid-the-application were changed from :mod:`p…
6 It is possible to run a :app:`Pyramid` application on Google's `App
eaaa8855 » mcdonc
2010-10-25 convert more docs from bfg to pyramid
7 Engine <http://code.google.com/appengine/>`_. Content from this
8 tutorial was contributed by YoungKing, based on the
9 `"appengine-monkey" tutorial for Pylons
10 <http://code.google.com/p/appengine-monkey/wiki/Pylons>`_. This
11 tutorial is written in terms of using the command line on a UNIX
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
12 system; it should be possible to perform similar actions on a Windows
13 system.
14
15 #. Download Google's `App Engine SDK
16 <http://code.google.com/appengine/downloads.html>`_ and install it
17 on your system.
18
19 #. Use Subversion to check out the source code for
20 ``appengine-monkey``.
21
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
22 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
23
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
24 $ svn co http://appengine-monkey.googlecode.com/svn/trunk/ \
25 appengine-monkey
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
26
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
27 #. Use ``appengine_homedir.py`` script in ``appengine-monkey`` to
28 create a :term:`virtualenv` for your application.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
29
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
30 .. code-block:: text
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
31
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
32 $ export GAE_PATH=/usr/local/google_appengine
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
33 $ python2.5 /path/to/appengine-monkey/appengine-homedir.py --gae \
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
34 $GAE_PATH pyramidapp
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
35
36 Note that ``$GAE_PATH`` should be the path where you have unpacked
37 the App Engine SDK. (On Mac OS X at least,
38 ``/usr/local/google_appengine`` is indeed where the installer puts
39 it).
40
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
41 This will set up an environment in ``pyramidapp/``, with some tools
42 installed in ``pyramidapp/bin``. There will also be a directory
43 ``pyramidapp/app/`` which is the directory you will upload to
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
44 appengine.
45
fd5ae92b » mcdonc
2010-11-09 - All references to Pyramid-the-application were changed from :mod:`p…
46 #. Install :app:`Pyramid` into the virtualenv
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
47
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
48 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
49
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
50 $ cd pyramidapp/
eaaa8855 » mcdonc
2010-10-25 convert more docs from bfg to pyramid
51 $ bin/easy_install pyramid
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
52
fd5ae92b » mcdonc
2010-11-09 - All references to Pyramid-the-application were changed from :mod:`p…
53 This will install :app:`Pyramid` in the environment.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
54
55 #. Create your application
56
fd5ae92b » mcdonc
2010-11-09 - All references to Pyramid-the-application were changed from :mod:`p…
57 We'll use the standard way to create a :app:`Pyramid`
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
58 application, but we'll have to move some files around when we are
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
59 done. The below commands assume your current working directory is
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
60 the ``pyramidapp`` virtualenv directory you created in the third step
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
61 above:
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
62
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
63 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
64
7cbc2057 » Chris McDonough
2009-06-24 Logic error in GAE tutorial (Michael B).
65 $ cd app
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
66 $ rm -rf pyramidapp
67 $ bin/paster create -t pyramid_starter pyramidapp
68 $ mv pyramidapp aside
69 $ mv aside/pyramidapp .
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
70 $ rm -rf aside
71
72 #. Edit ``config.py``
73
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
74 Edit the ``APP_NAME`` and ``APP_ARGS`` settings within
4f8c69f2 » d2m
2010-11-17 paster templates now use the name "main" to represent the function th…
75 ``config.py``. The ``APP_NAME`` must be ``pyramidapp:main``, and
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
76 the APP_ARGS must be ``({},)``. Any other settings in
77 ``config.py`` should remain the same.
78
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
79 .. code-block:: python
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
80
4f8c69f2 » d2m
2010-11-17 paster templates now use the name "main" to represent the function th…
81 APP_NAME = 'pyramidapp:main'
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
82 APP_ARGS = ({},)
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
83
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
84 #. Edit ``runner.py``
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
85
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
86 To prevent errors for ``import site``, add this code stanza before
87 ``import site`` in app/runner.py:
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
88
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
89 .. code-block:: python
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
90
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
91 import sys
92 sys.path = [path for path in sys.path if 'site-packages' not in path]
93 import site
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
94
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
95 You will also need to comment out the line that starts with
96 ``assert sys.path`` in the file.
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
97
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
98 .. code-block:: python
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
99
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
100 # comment the sys.path assertion out
101 # assert sys.path[:len(cur_sys_path)] == cur_sys_path, (
102 # "addsitedir() caused entries to be prepended to sys.path")
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
103
8ab4d082 » Chris McDonough
2009-12-30 Workaround for new GAE version compatibility with appengine-monkey.
104 For GAE development environment 1.3.0 or better, you will also need
105 the following somewhere near the top of the ``runner.py`` file to
106 fix a compatibility issue with ``appengine-monkey``:
107
108 .. code-block:: python
109
110 import os
111 os.mkdir = None
112
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
113 #. Run the application. ``dev_appserver.py`` is typically installed
114 by the SDK in the global path but you need to be sure to run it
115 with Python 2.5 (or whatever version of Python your GAE SDK
116 expects).
117
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
118 .. code-block:: text
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
119 :linenos:
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
120
121 $ cd ../..
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
122 $ python2.5 /usr/local/bin/dev_appserver.py pyramidapp/app/
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
123
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
124 Startup success looks something like this:
125
126 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
127
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
128 [chrism@vitaminf pyramid_gae]$ python2.5 \
129 /usr/local/bin/dev_appserver.py \
130 pyramidapp/app/
44f1df7b » Chris McDonough
2009-12-28 Fix overlong lines.
131 INFO 2009-05-03 22:23:13,887 appengine_rpc.py:157] # ... more...
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
132 Running application pyramidapp on port 8080: http://localhost:8080
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
133
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
134 You may need to run "Make Symlinks" from the Google App Engine
135 Launcher GUI application if your system doesn't already have the
136 ``dev_appserver.py`` script sitting around somewhere.
137
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
138 #. Hack on your pyramid application, using a normal run, debug, restart
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
139 process. For tips on how to use the ``pdb`` module within Google
140 App Engine, `see this blog post
141 <http://jjinux.blogspot.com/2008/05/python-debugging-google-app-engine-apps.html>`_.
142 In particular, you can create a function like so and call it to
143 drop your console into a pdb trace:
144
145 .. code-block:: python
146 :linenos:
147
148 def set_trace():
149 import pdb, sys
150 debugger = pdb.Pdb(stdin=sys.__stdin__,
151 stdout=sys.__stdout__)
152 debugger.set_trace(sys._getframe().f_back)
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
153
154 #. `Sign up for a GAE account <http://code.google.com/appengine/>`_
155 and create an application. You'll need a mobile phone to accept an
156 SMS in order to receive authorization.
157
158 #. Edit the application's ID in ``app.yaml`` to match the application
159 name you created during GAE account setup.
160
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
161 .. code-block:: yaml
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
162
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
163 application: mycoolpyramidapp
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
164
165 #. Upload the application
166
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
167 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
168
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
169 $ python2.5 /usr/local/bin/appcfg.py update pyramidapp/app
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
170
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
171 You almost certainly won't hit the 3000-file GAE file number limit
172 when invoking this command. If you do, however, it will look like
173 so:
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
174
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
175 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
176
177 HTTPError: HTTP Error 400: Bad Request
178 Rolling back the update.
179 Error 400: --- begin server output ---
0ac7b075 » Chris McDonough
2009-12-25 Fix syntax errors found via manuel, and add manuel-style markers to p…
180 Max number of files and blobs is 3000.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
181 --- end server output ---
182
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
183 If you do experience this error, you will be able to get around
184 this by zipping libraries. You can use ``pip`` to create zipfiles
185 from packages. See :ref:`pip_zip` for more information about this.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
186
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
187 A successful upload looks like so:
188
189 .. code-block:: text
190
48fae0a0 » mcdonc
2010-11-04 bfg->pyramid, account for paster template changes
191 [chrism@vitaminf pyramidapp]$ python2.5 /usr/local/bin/appcfg.py \
192 update ../pyramidapp/app/
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
193 Scanning files on local disk.
194 Scanned 500 files.
44f1df7b » Chris McDonough
2009-12-28 Fix overlong lines.
195 # ... more output ...
028ba403 » Chris McDonough
2009-12-25 Normalize code blocks.
196 Will check again in 16 seconds.
197 Checking if new version is ready to serve.
198 Closing update: new version is ready to start serving.
199 Uploading index definitions.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
200
44f1df7b » Chris McDonough
2009-12-28 Fix overlong lines.
201 #. Visit ``http://<yourapp>.appspot.com`` in a browser.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
202
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
203 .. _pip_zip:
204
205 Zipping Files Via Pip
206 ---------------------
207
208 If you hit the Google App Engine 3000-file limit, you may need to
209 create zipfile archives out of some distributions installed in your
210 application's virtualenv.
211
212 First, see which packages are available for zipping:
213
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
214 .. code-block:: text
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
215
0ac7b075 » Chris McDonough
2009-12-25 Fix syntax errors found via manuel, and add manuel-style markers to p…
216 $ bin/pip zip -l
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
217
218 This shows your zipped packages (by default, none) and your unzipped
219 packages. You can zip a package like so:
220
125e9746 » Chris McDonough
2009-12-28 Adjust for 7.5x9.25in output.
221 .. code-block:: text
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
222
0ac7b075 » Chris McDonough
2009-12-25 Fix syntax errors found via manuel, and add manuel-style markers to p…
223 $ bin/pip zip pytz-2009g-py2.5.egg
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
224
fd5ae92b » mcdonc
2010-11-09 - All references to Pyramid-the-application were changed from :mod:`p…
225 Note that it requires the whole egg file name. For a :app:`Pyramid` app, the
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
226 following packages are good candidates to be zipped.
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
227
604ad175 » Chris McDonough
2010-02-05 Modernize.
228 - Chameleon
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
229 - zope.i18n
5810ad11 » Chris McDonough
2009-05-03 Add GAE tutorial plus make CHANGES.txt renderings work.
230
29e1dcb1 » Chris McDonough
2009-07-03 Make sure tutorial still works.
231 Once the zipping procedure is finished you can try uploading again.
Something went wrong with that request. Please try again.