Michael Merickel
2017-06-18 75c30dfe18b26ca04efae2acbe35052fa0d93ed6
commit | author | age
558f3e 1 .. _qtut_cookiecutters:
SP 2
3 =================================================
4 Prelude: Quick Project Startup with Cookiecutters
5 =================================================
6
7 To ease the process of getting started on a project, the Pylons Project provides :term:`cookiecutter`\ s that generate sample :app:`Pyramid` projects from project templates. These cookiecutters will install :app:`Pyramid` and its dependencies as well. We will still cover many topics of web application development using :app:`Pyramid`, but it's good to know of this facility. This prelude will demonstrate how to get a working :app:`Pyramid` web application running via ``cookiecutter``.
8
9
10 Objectives
11 ==========
12
13 - Use a cookiecutter to make a new project.
14
15 - Start up a :app:`Pyramid` application and visit it in a web browser.
16
17
18 Steps
19 =====
20
21 #.  Install cookiecutter into your virtual environment.
22
23     .. code-block:: bash
24
25         $VENV/bin/pip install cookiecutter
26
27 #.  Let's use the cookiecutter ``pyramid-cookiecutter-starter`` to create a starter :app:`Pyramid` project in the current directory, entering values at the prompts as shown below for the following command.
28
29     .. code-block:: bash
30
1aa283 31         $ $VENV/bin/cookiecutter gh:Pylons/pyramid-cookiecutter-starter --checkout 1.9-branch
558f3e 32
SP 33     If prompted for the first item, accept the default ``yes`` by hitting return.
34
2cd381 35     .. code-block:: text
SP 36
37         You've cloned ~/.cookiecutters/pyramid-cookiecutter-starter before.
38         Is it okay to delete and re-clone it? [yes]: yes
39         project_name [Pyramid Scaffold]: cc_starter
6ff6fa 40         repo_name [cc_starter]: cc_starter
2cd381 41         Select template_language:
SP 42         1 - jinja2
43         2 - chameleon
6204d8 44         3 - mako
SP 45         Choose from 1, 2, 3 [1]: 1
558f3e 46
SP 47 #.  We then run through the following commands.
48
49     .. code-block:: bash
50
51         # Change directory into your newly created project.
52         $ cd cc_starter
53         # Create a new virtual environment...
54         $ python3 -m venv env
55         # ...where we upgrade packaging tools...
56         $ env/bin/pip install --upgrade pip setuptools
57         # ...and into which we install our project.
58         $ env/bin/pip install -e .
59
60 #.  Start up the application by pointing :app:`Pyramid`'s ``pserve`` command at the
61     project's (generated) configuration file:
62
63     .. code-block:: bash
64
65         $ env/bin/pserve development.ini --reload
66
67     On start up, ``pserve`` logs some output:
68
69     .. code-block:: text
70
71         Starting subprocess with file monitor
72         Starting server in PID 73732.
73         Serving on http://localhost:6543
74         Serving on http://localhost:6543
75
76 #. Open http://localhost:6543/ in your browser.
77
78 Analysis
79 ========
80
81 Rather than starting from scratch, a cookiecutter can make it easy to get a Python
82 project containing a working :app:`Pyramid` application. The Pylons Project provides `several cookiecutters <https://github.com/Pylons?q=pyramid-cookiecutter>`_.
83
84 ``pserve`` is :app:`Pyramid`'s application runner, separating operational details from
85 your code. When you install :app:`Pyramid`, a small command program called ``pserve``
86 is written to your ``bin`` directory. This program is an executable Python
87 module. It is passed a configuration file (in this case, ``development.ini``).