Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 314 lines (203 sloc) 8.738 kB
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
1 ============
2 Installation
3 ============
4
0aed1cd Restructured the routes wiki tutorial to make it easier to follow alo…
Carlos de la Guardia authored
5 This tutorial assumes that Python and virtualenv are already installed
6 and working in your system. If you need help setting this up, you should
7 refer to the chapters on :ref:`installing_chapter`.
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
8
9 Preparation
10 ===========
11
12 Please take the following steps to prepare for the tutorial. The
13 steps are slightly different depending on whether you're using UNIX or
14 Windows.
15
16 Preparation, UNIX
17 -----------------
18
19 #. Install SQLite3 and its development packages if you don't already
20 have them installed. Usually this is via your system's package
21 manager. For example, on a Debian Linux system, do ``sudo apt-get
22 install libsqlite3-dev``.
23
0aed1cd Restructured the routes wiki tutorial to make it easier to follow alo…
Carlos de la Guardia authored
24 #. Use your Python's virtualenv to make a workspace:
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
25
26 .. code-block:: text
27
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
28 $ path/to/my/Python-2.6/bin/virtualenv --no-site-packages pyramidtut
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
29
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
30 #. Switch to the ``pyramidtut`` directory:
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
31
32 .. code-block:: text
33
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
34 $ cd pyramidtut
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
35
fd5ae92 @mcdonc - All references to Pyramid-the-application were changed from :mod:`p…
mcdonc authored
36 #. Use ``easy_install`` to get :app:`Pyramid` and its direct
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
37 dependencies installed:
38
39 .. code-block:: text
40
41 $ bin/easy_install pyramid
42
43 Preparation, Windows
44 --------------------
45
0aed1cd Restructured the routes wiki tutorial to make it easier to follow alo…
Carlos de la Guardia authored
46 #. Use your Python's virtualenv to make a workspace:
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
47
48 .. code-block:: text
49
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
50 c:\> c:\Python26\Scripts\virtualenv --no-site-packages pyramidtut
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
51
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
52 #. Switch to the ``pyramidtut`` directory:
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
53
54 .. code-block:: text
55
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
56 c:\> cd pyramidtut
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
57
fd5ae92 @mcdonc - All references to Pyramid-the-application were changed from :mod:`p…
mcdonc authored
58 #. Use ``easy_install`` to get :app:`Pyramid` and its direct
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
59 dependencies installed:
60
61 .. code-block:: text
62
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
63 c:\pyramidtut> Scripts\easy_install pyramid
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
64
65 .. _sql_making_a_project:
66
67 Making a Project
68 ================
69
fd5ae92 @mcdonc - All references to Pyramid-the-application were changed from :mod:`p…
mcdonc authored
70 Your next step is to create a project. :app:`Pyramid` supplies a
7584643 @jayd3e It was decided that pyramid would undergo a terminology change.
jayd3e authored
71 variety of scaffolds to generate sample projects. We will use the
818f8ca @mcdonc - The ``alchemy`` scaffold has been removed.
mcdonc authored
72 ``alchemy`` scaffold, which generates an application
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
73 that uses :term:`SQLAlchemy` and :term:`URL dispatch`.
74
75 The below instructions assume your current working directory is the
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
76 "virtualenv" named "pyramidtut".
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
77
78 On UNIX:
79
80 .. code-block:: text
81
818f8ca @mcdonc - The ``alchemy`` scaffold has been removed.
mcdonc authored
82 $ bin/pcreate -s alchemy tutorial
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
83
84 On Windows:
85
86 .. code-block:: text
87
818f8ca @mcdonc - The ``alchemy`` scaffold has been removed.
mcdonc authored
88 c:\pyramidtut> Scripts\pcreate -s alchemy tutorial
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
89
818f8ca @mcdonc - The ``alchemy`` scaffold has been removed.
mcdonc authored
90 .. note:: If you are using Windows, the ``alchemy``
7584643 @jayd3e It was decided that pyramid would undergo a terminology change.
jayd3e authored
91 scaffold may not deal gracefully with installation into a
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
92 location that contains spaces in the path. If you experience
93 startup problems, try putting both the virtualenv and the project
94 into directories that do not contain spaces in their paths.
95
96 Installing the Project in "Development Mode"
97 ============================================
98
99 In order to do development on the project easily, you must "register"
100 the project as a development egg in your workspace using the
101 ``setup.py develop`` command. In order to do so, cd to the "tutorial"
102 directory you created in :ref:`sql_making_a_project`, and run the
103 "setup.py develop" command using virtualenv Python interpreter.
104
105 On UNIX:
106
107 .. code-block:: text
108
109 $ cd tutorial
110 $ ../bin/python setup.py develop
111
112 On Windows:
113
114 .. code-block:: text
115
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
116 c:\pyramidtut> cd tutorial
117 c:\pyramidtut\tutorial> ..\Scripts\python setup.py develop
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
118
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
119 Success executing this command will end with a line to the console something
120 like::
121
122 Finished processing dependencies for tutorial==0.0
123
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
124 .. _sql_running_tests:
125
126 Running the Tests
127 =================
128
129 After you've installed the project in development mode, you may run
130 the tests for the project.
131
132 On UNIX:
133
134 .. code-block:: text
135
136 $ ../bin/python setup.py test -q
137
138 On Windows:
139
140 .. code-block:: text
141
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
142 c:\pyramidtut\tutorial> ..\Scripts\python setup.py test -q
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
143
b3e608b @douglatornell Improve text of SQLAlchemy wiki tutorial.
douglatornell authored
144 For a successful test run, you should see output that ends like this::
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
145
146 .
147 ----------------------------------------------------------------------
148 Ran 1 test in 0.094s
149
150 OK
151
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
152 Exposing Test Coverage Information
153 ==================================
154
155 You can run the ``nosetests`` command to see test coverage
156 information. This runs the tests in the same way that ``setup.py
157 test`` does but provides additional "coverage" information, exposing
158 which lines of your project are "covered" (or not covered) by the
159 tests.
160
161 To get this functionality working, we'll need to install a couple of
162 other packages into our ``virtualenv``: ``nose`` and ``coverage``:
163
164 On UNIX:
165
166 .. code-block:: text
167
168 $ ../bin/easy_install nose coverage
169
170 On Windows:
171
172 .. code-block:: text
173
be3d6f9 @blaflamme Updated wiki tutorial docs
blaflamme authored
174 c:\pyramidtut\tutorial> ..\Scripts\easy_install nose coverage
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
175
176 Once ``nose`` and ``coverage`` are installed, we can actually run the
177 coverage tests.
178
179 On UNIX:
180
181 .. code-block:: text
182
183 $ ../bin/nosetests --cover-package=tutorial --cover-erase --with-coverage
184
185 On Windows:
186
187 .. code-block:: text
188
879bb56 @Cito More small fixes made reading the rest of the docs and the tutorials.
Cito authored
189 c:\pyramidtut\tutorial> ..\Scripts\nosetests --cover-package=tutorial ^
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
190 --cover-erase --with-coverage
191
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
192 If successful, you will see output something like this::
193
194 .
195 Name Stmts Miss Cover Missing
196 ------------------------------------------------
197 tutorial 11 7 36% 9-15
198 tutorial.models 17 0 100%
199 tutorial.scripts 0 0 100%
200 tutorial.tests 24 0 100%
201 tutorial.views 6 0 100%
202 ------------------------------------------------
203 TOTAL 58 7 88%
204 ----------------------------------------------------------------------
205 Ran 1 test in 0.459s
206
207 OK
208
209 Looks like our package doesn't quite have 100% test coverage.
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
210
c884eea @ppaez Renamed db populate to initialize in SQL tutorial
ppaez authored
211 Initializing the Database
212 =========================
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
213
b284c63 @ppaez Removed the application restart step
ppaez authored
214 We need to use the ``initialize_tutorial_db`` :term:`console
215 script` to initialize our database.
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
216
b284c63 @ppaez Removed the application restart step
ppaez authored
217 Type the following command, make sure you are still in the ``tutorial``
218 directory (the directory with a ``development.ini`` in it):
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
219
220 On UNIX:
221
222 .. code-block:: text
223
c884eea @ppaez Renamed db populate to initialize in SQL tutorial
ppaez authored
224 $ ../bin/initialize_tutorial_db development.ini
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
225
226 On Windows:
227
228 .. code-block:: text
229
c884eea @ppaez Renamed db populate to initialize in SQL tutorial
ppaez authored
230 c:\pyramidtut\tutorial> ..\Scripts\initialize_tutorial_db development.ini
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
231
232 The output to your console should be something like this::
233
234 2011-11-26 14:42:25,012 INFO [sqlalchemy.engine.base.Engine][MainThread]
235 PRAGMA table_info("models")
236 2011-11-26 14:42:25,013 INFO [sqlalchemy.engine.base.Engine][MainThread] ()
237 2011-11-26 14:42:25,013 INFO [sqlalchemy.engine.base.Engine][MainThread]
238 CREATE TABLE models (
239 id INTEGER NOT NULL,
240 name VARCHAR(255),
241 value INTEGER,
242 PRIMARY KEY (id),
243 UNIQUE (name)
244 )
245 2011-11-26 14:42:25,013 INFO [sqlalchemy.engine.base.Engine][MainThread] ()
246 2011-11-26 14:42:25,135 INFO [sqlalchemy.engine.base.Engine][MainThread]
247 COMMIT
248 2011-11-26 14:42:25,137 INFO [sqlalchemy.engine.base.Engine][MainThread]
249 BEGIN (implicit)
250 2011-11-26 14:42:25,138 INFO [sqlalchemy.engine.base.Engine][MainThread]
251 INSERT INTO models (name, value) VALUES (?, ?)
252 2011-11-26 14:42:25,139 INFO [sqlalchemy.engine.base.Engine][MainThread]
253 (u'one', 1)
254 2011-11-26 14:42:25,140 INFO [sqlalchemy.engine.base.Engine][MainThread]
255 COMMIT
256
257 Success! You should now have a ``tutorial.db`` file in your current working
258 directory. This will be a SQLite database with a single table defined in it
259 (``models``).
260
b284c63 @ppaez Removed the application restart step
ppaez authored
261 .. _wiki2-start-the-application:
262
263 Starting the Application
264 ========================
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
265
b284c63 @ppaez Removed the application restart step
ppaez authored
266 Start the application.
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
267
268 On UNIX:
269
270 .. code-block:: text
271
272 $ ../bin/pserve development.ini --reload
273
274 On Windows:
275
276 .. code-block:: text
277
278 c:\pyramidtut\tutorial> ..\Scripts\pserve development.ini --reload
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
279
b284c63 @ppaez Removed the application restart step
ppaez authored
280 If successful, you will see something like this on your console::
281
282 Starting subprocess with file monitor
283 Starting server in PID 8966.
284 Starting HTTP server on http://0.0.0.0:6543
285
286 This means the server is ready to accept requests.
287
6772a25 @mcdonc output warning to use populate command to console after alchemy scaff…
mcdonc authored
288 At this point, when you visit ``http://localhost:6543/`` in your web browser,
b284c63 @ppaez Removed the application restart step
ppaez authored
289 you will see the generated application's default page.
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
290
2c9f3c7 @mcdonc - Mention debug toolbar in tutorials.
mcdonc authored
291 One thing you'll notice is the "debug toolbar" icon on right hand side of the
292 page. You can read more about the purpose of the icon at
293 :ref:`debug_toolbar`. It allows you to get information about your
294 application while you develop.
295
818f8ca @mcdonc - The ``alchemy`` scaffold has been removed.
mcdonc authored
296 Decisions the ``alchemy`` Scaffold Has Made For You
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
297 =================================================================
298
818f8ca @mcdonc - The ``alchemy`` scaffold has been removed.
mcdonc authored
299 Creating a project using the ``alchemy`` scaffold makes
b2adfe7 @mcdonc - The SQL Wiki tutorial was updated to take into account changes to the
mcdonc authored
300 the following assumptions:
301
302 - you are willing to use :term:`SQLAlchemy` as a database access tool
303
304 - you are willing to use :term:`url dispatch` to map URLs to code.
305
306 .. note::
307
fd5ae92 @mcdonc - All references to Pyramid-the-application were changed from :mod:`p…
mcdonc authored
308 :app:`Pyramid` supports any persistent storage mechanism (e.g. object
b2adfe7 @mcdonc - The SQL Wiki tutorial was updated to take into account changes to the
mcdonc authored
309 database or filesystem files, etc). It also supports an additional
310 mechanism to map URLs to code (:term:`traversal`). However, for the
311 purposes of this tutorial, we'll only be using url dispatch and
312 SQLAlchemy.
e267005 @mcdonc adjust wiki2 tutorial for pyramid
mcdonc authored
313
Something went wrong with that request. Please try again.