Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 232 lines (161 sloc) 7.265 kb
4ad6d42 General cleanup.
Chris McDonough authored
1 .. _appengine_tutorial:
2
fd5ae92 Chris McDonough - All references to Pyramid-the-application were changed from :mod:`pyra...
mcdonc authored
3 Running :app:`Pyramid` on Google's App Engine
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
4 ================================================
5
fd5ae92 Chris McDonough - All references to Pyramid-the-application were changed from :mod:`pyra...
mcdonc authored
6 It is possible to run a :app:`Pyramid` application on Google's `App
eaaa885 Chris McDonough convert more docs from bfg to pyramid
mcdonc authored
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
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
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
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
22 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
23
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
24 $ svn co http://appengine-monkey.googlecode.com/svn/trunk/ \
25 appengine-monkey
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
26
29e1dcb Make sure tutorial still works.
Chris McDonough authored
27 #. Use ``appengine_homedir.py`` script in ``appengine-monkey`` to
28 create a :term:`virtualenv` for your application.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
29
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
30 .. code-block:: text
29e1dcb Make sure tutorial still works.
Chris McDonough authored
31
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
32 $ export GAE_PATH=/usr/local/google_appengine
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
33 $ python2.5 /path/to/appengine-monkey/appengine-homedir.py --gae \
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
34 $GAE_PATH pyramidapp
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
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
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
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
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
44 appengine.
45
fd5ae92 Chris McDonough - All references to Pyramid-the-application were changed from :mod:`pyra...
mcdonc authored
46 #. Install :app:`Pyramid` into the virtualenv
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
47
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
48 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
49
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
50 $ cd pyramidapp/
eaaa885 Chris McDonough convert more docs from bfg to pyramid
mcdonc authored
51 $ bin/easy_install pyramid
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
52
fd5ae92 Chris McDonough - All references to Pyramid-the-application were changed from :mod:`pyra...
mcdonc authored
53 This will install :app:`Pyramid` in the environment.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
54
55 #. Create your application
56
fd5ae92 Chris McDonough - All references to Pyramid-the-application were changed from :mod:`pyra...
mcdonc authored
57 We'll use the standard way to create a :app:`Pyramid`
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
58 application, but we'll have to move some files around when we are
29e1dcb Make sure tutorial still works.
Chris McDonough authored
59 done. The below commands assume your current working directory is
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
60 the ``pyramidapp`` virtualenv directory you created in the third step
29e1dcb Make sure tutorial still works.
Chris McDonough authored
61 above:
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
62
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
63 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
64
7cbc205 Logic error in GAE tutorial (Michael B).
Chris McDonough authored
65 $ cd app
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
66 $ rm -rf pyramidapp
67 $ bin/paster create -t pyramid_starter pyramidapp
68 $ mv pyramidapp aside
69 $ mv aside/pyramidapp .
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
70 $ rm -rf aside
71
72 #. Edit ``config.py``
73
29e1dcb Make sure tutorial still works.
Chris McDonough authored
74 Edit the ``APP_NAME`` and ``APP_ARGS`` settings within
4f8c69f paster templates now use the name "main" to represent the function that ...
d2m authored
75 ``config.py``. The ``APP_NAME`` must be ``pyramidapp:main``, and
29e1dcb Make sure tutorial still works.
Chris McDonough authored
76 the APP_ARGS must be ``({},)``. Any other settings in
77 ``config.py`` should remain the same.
78
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
79 .. code-block:: python
29e1dcb Make sure tutorial still works.
Chris McDonough authored
80
4f8c69f paster templates now use the name "main" to represent the function that ...
d2m authored
81 APP_NAME = 'pyramidapp:main'
29e1dcb Make sure tutorial still works.
Chris McDonough authored
82 APP_ARGS = ({},)
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
83
028ba40 Normalize code blocks.
Chris McDonough authored
84 #. Edit ``runner.py``
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
85
028ba40 Normalize code blocks.
Chris McDonough authored
86 To prevent errors for ``import site``, add this code stanza before
87 ``import site`` in app/runner.py:
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
88
028ba40 Normalize code blocks.
Chris McDonough authored
89 .. code-block:: python
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
90
028ba40 Normalize code blocks.
Chris McDonough authored
91 import sys
92 sys.path = [path for path in sys.path if 'site-packages' not in path]
93 import site
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
94
028ba40 Normalize code blocks.
Chris McDonough authored
95 You will also need to comment out the line that starts with
96 ``assert sys.path`` in the file.
29e1dcb Make sure tutorial still works.
Chris McDonough authored
97
028ba40 Normalize code blocks.
Chris McDonough authored
98 .. code-block:: python
29e1dcb Make sure tutorial still works.
Chris McDonough authored
99
028ba40 Normalize code blocks.
Chris McDonough authored
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")
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
103
8ab4d08 Workaround for new GAE version compatibility with appengine-monkey.
Chris McDonough authored
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
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
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
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
118 .. code-block:: text
028ba40 Normalize code blocks.
Chris McDonough authored
119 :linenos:
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
120
121 $ cd ../..
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
122 $ python2.5 /usr/local/bin/dev_appserver.py pyramidapp/app/
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
123
028ba40 Normalize code blocks.
Chris McDonough authored
124 Startup success looks something like this:
125
126 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
127
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
128 [chrism@vitaminf pyramid_gae]$ python2.5 \
129 /usr/local/bin/dev_appserver.py \
130 pyramidapp/app/
44f1df7 Fix overlong lines.
Chris McDonough authored
131 INFO 2009-05-03 22:23:13,887 appengine_rpc.py:157] # ... more...
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
132 Running application pyramidapp on port 8080: http://localhost:8080
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
133
29e1dcb Make sure tutorial still works.
Chris McDonough authored
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
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
138 #. Hack on your pyramid application, using a normal run, debug, restart
29e1dcb Make sure tutorial still works.
Chris McDonough authored
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)
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
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
028ba40 Normalize code blocks.
Chris McDonough authored
161 .. code-block:: yaml
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
162
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
163 application: mycoolpyramidapp
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
164
165 #. Upload the application
166
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
167 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
168
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
169 $ python2.5 /usr/local/bin/appcfg.py update pyramidapp/app
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
170
29e1dcb Make sure tutorial still works.
Chris McDonough authored
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:
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
174
028ba40 Normalize code blocks.
Chris McDonough authored
175 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
176
177 HTTPError: HTTP Error 400: Bad Request
178 Rolling back the update.
179 Error 400: --- begin server output ---
0ac7b07 Fix syntax errors found via manuel, and add manuel-style markers to prev...
Chris McDonough authored
180 Max number of files and blobs is 3000.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
181 --- end server output ---
182
29e1dcb Make sure tutorial still works.
Chris McDonough authored
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.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
186
028ba40 Normalize code blocks.
Chris McDonough authored
187 A successful upload looks like so:
188
189 .. code-block:: text
190
48fae0a Chris McDonough bfg->pyramid, account for paster template changes
mcdonc authored
191 [chrism@vitaminf pyramidapp]$ python2.5 /usr/local/bin/appcfg.py \
192 update ../pyramidapp/app/
028ba40 Normalize code blocks.
Chris McDonough authored
193 Scanning files on local disk.
194 Scanned 500 files.
44f1df7 Fix overlong lines.
Chris McDonough authored
195 # ... more output ...
028ba40 Normalize code blocks.
Chris McDonough authored
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.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
200
44f1df7 Fix overlong lines.
Chris McDonough authored
201 #. Visit ``http://<yourapp>.appspot.com`` in a browser.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
202
29e1dcb Make sure tutorial still works.
Chris McDonough authored
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
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
214 .. code-block:: text
29e1dcb Make sure tutorial still works.
Chris McDonough authored
215
0ac7b07 Fix syntax errors found via manuel, and add manuel-style markers to prev...
Chris McDonough authored
216 $ bin/pip zip -l
29e1dcb Make sure tutorial still works.
Chris McDonough authored
217
218 This shows your zipped packages (by default, none) and your unzipped
219 packages. You can zip a package like so:
220
125e974 Adjust for 7.5x9.25in output.
Chris McDonough authored
221 .. code-block:: text
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
222
0ac7b07 Fix syntax errors found via manuel, and add manuel-style markers to prev...
Chris McDonough authored
223 $ bin/pip zip pytz-2009g-py2.5.egg
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
224
fd5ae92 Chris McDonough - All references to Pyramid-the-application were changed from :mod:`pyra...
mcdonc authored
225 Note that it requires the whole egg file name. For a :app:`Pyramid` app, the
29e1dcb Make sure tutorial still works.
Chris McDonough authored
226 following packages are good candidates to be zipped.
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
227
604ad17 Modernize.
Chris McDonough authored
228 - Chameleon
29e1dcb Make sure tutorial still works.
Chris McDonough authored
229 - zope.i18n
5810ad1 Add GAE tutorial plus make CHANGES.txt renderings work.
Chris McDonough authored
230
29e1dcb Make sure tutorial still works.
Chris McDonough authored
231 Once the zipping procedure is finished you can try uploading again.
Something went wrong with that request. Please try again.