From a0ebd777ad773c86f5bd5becfd77c2a0d61906d1 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 24 Dec 2016 02:38:07 -0800 Subject: quick_tour - first cut --- docs/quick_tour.rst | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index 5dc7d8816..f9dbd2438 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -491,40 +491,48 @@ more to offer: :ref:`class_as_view`. -Quick project startup with scaffolds -==================================== +Quick project startup with cookiecutters +======================================== So far we have done all of our *Quick Tour* as a single Python file. No Python packages, no structure. Most Pyramid projects, though, aren't developed this way. -To ease the process of getting started, Pyramid provides *scaffolds* that -generate sample projects from templates in Pyramid and Pyramid add-ons. -Pyramid's ``pcreate`` command can list the available scaffolds: +To ease the process of getting started, the Pylons Project provides :term:`cookiecutter`\ s that generate sample Pyramid projects from project templates. In addition these cookiecutters will install Pyramid and its dependencies. + +First you'll need to install cookiecutter. .. code-block:: bash - $ $VENV/bin/pcreate --list - Available scaffolds: - alchemy: Pyramid project using SQLAlchemy, SQLite, URL dispatch, and Jinja2 - pyramid_jinja2_starter: Pyramid Jinja2 starter project - starter: Pyramid starter project using URL dispatch and Chameleon - zodb: Pyramid project using ZODB, traversal, and Chameleon + $ $VENV/bin/pip install cookiecutter -The ``pyramid_jinja2`` add-on gave us a scaffold that we can use. From the -parent directory of where we want our Python package to be generated, let's use -that scaffold to make our project: +In the directory where we want our sample Pyramid project to be generated, let's use the cookiecutter ``pyramid-cookiecutter-starter``, following the prompts of the command. .. code-block:: bash - $ $VENV/bin/pcreate --scaffold pyramid_jinja2_starter hello_world + $ $VENV/bin/cookiecutter https://github.com/Pylons/pyramid-cookiecutter-starter + +If prompted for the first item, accept the default ``yes`` by hitting return. -We next use the normal Python command to set up our package for development: +#. ``You've cloned ~/.cookiecutters/pyramid-cookiecutter-starter before. Is it + okay to delete and re-clone it? [yes]:`` +#. ``project_name [Pyramid Scaffold]: myproject`` +#. ``repo_name [scaffold]: qtour`` + +We then run through the following commands .. code-block:: bash - $ cd hello_world - $ $VENV/bin/pip install -e . + # Change directory into your newly created project. + $ cd qtour + # Create a new virtual environment... + $ python3 -m venv env + # ...where we upgrade packaging tools... + $ env/bin/pip install --upgrade pip setuptools + # ...and into which we install our project and its testing requirements. + $ env/bin/pip install -e ".[testing]" + # Reset our environment variable to use the new virtual environment. + $ export VENV=~/env/qtour/env We are moving in the direction of a full-featured Pyramid project, with a proper setup for Python standards (packaging) and Pyramid configuration. This @@ -537,7 +545,7 @@ includes a new way of running your application: Let's look at ``pserve`` and configuration in more depth. .. seealso:: See also: - :ref:`Quick Tutorial Scaffolds `, + :ref:`Quick Tutorial Cookiecutters `, :ref:`project_narr`, and :doc:`../narr/scaffolding` -- cgit v1.2.3 From 49cd001b213ca74d0b39914eeed4c1eb4969d84d Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 24 Dec 2016 02:38:54 -0800 Subject: quick_tour - fix reference --- docs/quick_tour.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index f9dbd2438..a0c8a4737 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -545,7 +545,7 @@ includes a new way of running your application: Let's look at ``pserve`` and configuration in more depth. .. seealso:: See also: - :ref:`Quick Tutorial Cookiecutters `, + :ref:`Quick Tutorial Cookiecutters `, :ref:`project_narr`, and :doc:`../narr/scaffolding` -- cgit v1.2.3 From 2cd1eab15a3777cbc81c2d365f21a98c29c9ed86 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 24 Dec 2016 20:41:08 -0800 Subject: use hello_world for project and repo names; grammar fixes --- docs/quick_tour.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index a0c8a4737..4c8dfc143 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -498,7 +498,7 @@ So far we have done all of our *Quick Tour* as a single Python file. No Python packages, no structure. Most Pyramid projects, though, aren't developed this way. -To ease the process of getting started, the Pylons Project provides :term:`cookiecutter`\ s that generate sample Pyramid projects from project templates. In addition these cookiecutters will install Pyramid and its dependencies. +To ease the process of getting started, the Pylons Project provides :term:`cookiecutter`\ s that generate sample Pyramid projects from project templates. These cookiecutters will install Pyramid and its dependencies as well. First you'll need to install cookiecutter. @@ -506,7 +506,7 @@ First you'll need to install cookiecutter. $ $VENV/bin/pip install cookiecutter -In the directory where we want our sample Pyramid project to be generated, let's use the cookiecutter ``pyramid-cookiecutter-starter``, following the prompts of the command. +Let's use the cookiecutter ``pyramid-cookiecutter-starter`` to create a starter Pyramid project in the current directory, entering values at the prompts as shown below for the following command. .. code-block:: bash @@ -516,23 +516,23 @@ If prompted for the first item, accept the default ``yes`` by hitting return. #. ``You've cloned ~/.cookiecutters/pyramid-cookiecutter-starter before. Is it okay to delete and re-clone it? [yes]:`` -#. ``project_name [Pyramid Scaffold]: myproject`` -#. ``repo_name [scaffold]: qtour`` +#. ``project_name [Pyramid Scaffold]: hello_world`` +#. ``repo_name [scaffold]: hello_world`` We then run through the following commands .. code-block:: bash # Change directory into your newly created project. - $ cd qtour + $ cd hello_world # Create a new virtual environment... $ python3 -m venv env # ...where we upgrade packaging tools... $ env/bin/pip install --upgrade pip setuptools # ...and into which we install our project and its testing requirements. $ env/bin/pip install -e ".[testing]" - # Reset our environment variable to use the new virtual environment. - $ export VENV=~/env/qtour/env + # Reset our environment variable for a new virtual environment. + $ export VENV=~/env/hello_world/env We are moving in the direction of a full-featured Pyramid project, with a proper setup for Python standards (packaging) and Pyramid configuration. This @@ -552,7 +552,7 @@ Let's look at ``pserve`` and configuration in more depth. Application running with ``pserve`` =================================== -Prior to scaffolds, our project mixed a number of operational details into our +Prior to the cookiecutter, our project mixed a number of operational details into our code. Why should my main code care which HTTP server I want and what port number to run on? @@ -582,7 +582,7 @@ Configuration with ``.ini`` files Earlier in *Quick Tour* we first met Pyramid's configuration system. At that point we did all configuration in Python code. For example, the port number -chosen for our HTTP server was right there in Python code. Our scaffold has +chosen for our HTTP server was right there in Python code. Our cookiecutter has moved this decision and more into the ``development.ini`` file: .. literalinclude:: quick_tour/package/development.ini -- cgit v1.2.3 From 54d9ddcd335d45662ca2ec2839574085318e8704 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 02:17:19 -0800 Subject: quick_tour - Configuration with ``.ini`` files section cookiecutter updates - src files - update numbered list for new listen configuration for waitress - fix reference to app, not server - reorder numbered list to align with configuration order --- docs/quick_tour.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index 4c8dfc143..a48ac4137 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -599,15 +599,15 @@ sections: We have a few decisions made for us in this configuration: -#. *Choice of web server:* ``use = egg:hello_world`` tells ``pserve`` to - use the ``waitress`` server. - -#. *Port number:* ``port = 6543`` tells ``waitress`` to listen on port 6543. - #. *WSGI app:* What package has our WSGI application in it? ``use = egg:hello_world`` in the app section tells the configuration what application to load. +#. *Choice of web server:* ``use = egg:waitress#main`` tells ``pserve`` to + use the ``waitress`` server. + +#. *Interfaces:* ``listen = 127.0.0.1:6543 [::1]:6543`` tells ``waitress`` to listen on all interfaces on port 6543 for both IPv4 and IPv6. + #. *Easier development by automatic template reloading:* In development mode, you shouldn't have to restart the server when editing a Jinja2 template. ``pyramid.reload_templates = true`` sets this policy, which might be -- cgit v1.2.3 From 7857763be80aad2e60b95bfed73c641194fb380c Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 02:18:51 -0800 Subject: quick_tour - Configuration with ``.ini`` files section cookiecutter updates - reorder numbered list to align with configuration order, this time for sure! --- docs/quick_tour.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index a48ac4137..ab25f68dc 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -603,16 +603,16 @@ We have a few decisions made for us in this configuration: ``use = egg:hello_world`` in the app section tells the configuration what application to load. -#. *Choice of web server:* ``use = egg:waitress#main`` tells ``pserve`` to - use the ``waitress`` server. - -#. *Interfaces:* ``listen = 127.0.0.1:6543 [::1]:6543`` tells ``waitress`` to listen on all interfaces on port 6543 for both IPv4 and IPv6. - #. *Easier development by automatic template reloading:* In development mode, you shouldn't have to restart the server when editing a Jinja2 template. ``pyramid.reload_templates = true`` sets this policy, which might be different in production. +#. *Choice of web server:* ``use = egg:waitress#main`` tells ``pserve`` to + use the ``waitress`` server. + +#. *Interfaces:* ``listen = 127.0.0.1:6543 [::1]:6543`` tells ``waitress`` to listen on all interfaces on port 6543 for both IPv4 and IPv6. + Additionally the ``development.ini`` generated by this scaffold wired up Python's standard logging. We'll now see in the console, for example, a log on every request that comes in, as well as traceback information. -- cgit v1.2.3 From af1e3221489954cd3001e81e4b94516a820c2f72 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 02:29:14 -0800 Subject: quick_tour - "Easier development with ``debugtoolbar``" updates for cookiecutter - adjust line numbers, grammar, pip command --- docs/quick_tour.rst | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index ab25f68dc..a02d2ab27 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -634,38 +634,35 @@ and earlier we showed ``--reload`` for application reloading. available in your browser. Adding it to your project illustrates several points about configuration. -The scaffold ``pyramid_jinja2_starter`` is already configured to include the +The cookiecutter ``pyramid-cookiecutter-starter`` already configured our package to include the add-on ``pyramid_debugtoolbar`` in its ``setup.py``: .. literalinclude:: quick_tour/package/setup.py :language: python - :linenos: - :lineno-start: 11 + :lineno-match: :lines: 11-16 + :emphasize-lines: 4 It was installed when you previously ran: .. code-block:: bash - $ $VENV/bin/pip install -e . + $ $VENV/bin/pip install -e ".[testing]" The ``pyramid_debugtoolbar`` package is a Pyramid add-on, which means we need -to include its configuration into our web application. The ``pyramid_jinja2`` -add-on already took care of this for us in its ``__init__.py``: +to include its configuration into our web application. The cookiecutter already took care of this for us in its ``__init__.py``: .. literalinclude:: quick_tour/package/hello_world/__init__.py :language: python - :linenos: - :lineno-start: 16 - :lines: 19 + :lineno-match: + :lines: 8 And it uses the ``pyramid.includes`` facility in our ``development.ini``: .. literalinclude:: quick_tour/package/development.ini :language: ini - :linenos: - :lineno-start: 15 - :lines: 15-16 + :lineno-match: + :lines: 14-15 You'll now see a Pyramid logo on the right side of your browser window, which when clicked opens a new window that provides introspective access to debugging -- cgit v1.2.3 From 9483444d55f4dd9be8adc8c386b4af0d8af032a3 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 02:47:16 -0800 Subject: quick_tour - "Unit tests and ``py.test``" updates for cookiecutter - use literal includes instead of inline code - document second test --- docs/quick_tour.rst | 76 ++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 48 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index a02d2ab27..fd35ba419 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -682,42 +682,23 @@ Yikes! We got this far and we haven't yet discussed tests. This is particularly egregious, as Pyramid has had a deep commitment to full test coverage since before its release. -Our ``pyramid_jinja2_starter`` scaffold generated a ``tests.py`` module with -one unit test in it. It also configured ``setup.py`` with test requirements: +Our ``pyramid-cookiecutter-starter`` cookiecutter generated a ``tests.py`` module with +one unit test and one functional test in it. It also configured ``setup.py`` with test requirements: ``py.test`` as the test runner, ``WebTest`` for running view tests, and the ``pytest-cov`` tool which yells at us for code that isn't tested. The highlighted lines show this: -.. code-block:: python - :linenos: - :lineno-start: 11 - :emphasize-lines: 8-12 - - requires = [ - 'pyramid', - 'pyramid_jinja2', - 'pyramid_debugtoolbar', - 'waitress', - ] - - tests_require = [ - 'WebTest >= 1.3.1', # py3 compat - 'pytest', # includes virtualenv - 'pytest-cov', - ] - -.. code-block:: python - :linenos: - :lineno-start: 34 - :emphasize-lines: 2-4 +.. literalinclude:: quick_tour/package/setup.py + :language: python + :lineno-match: + :lines: 18-22 - zip_safe=False, - extras_require={ - 'testing': tests_require, - }, +.. literalinclude:: quick_tour/package/setup.py + :language: python + :lineno-match: + :lines: 42-44 -To install the test requirements, run ``$VENV/bin/pip install -e -".[testing]"``. We can now run all our tests: +We already installed the test requirements when we ran the command ``$VENV/bin/pip install -e ".[testing]"``. We can now run all our tests: .. code-block:: bash @@ -728,34 +709,33 @@ This yields the following output. .. code-block:: text =========================== test session starts =========================== - platform darwin -- Python 3.5.0, pytest-2.9.1, py-1.4.31, pluggy-0.3.1 - rootdir: /Users/stevepiercy/projects/hack-on-pyramid/hello_world, inifile: - plugins: cov-2.2.1 - collected 1 items + platform darwin -- Python 3.6.0, pytest-3.0.5, py-1.4.32, pluggy-0.4.0 + rootdir: /Users/stevepiercy/hello_world, inifile: pytest.ini + plugins: cov-2.4.0 + collected 2 items + + hello_world/tests.py .. - hello_world/tests.py . ------------- coverage: platform darwin, python 3.6.0-final-0 ------------- - Name Stmts Miss Cover Missing - -------------------------------------------------------- - hello_world/__init__.py 11 8 27% 11-23 - hello_world/resources.py 5 1 80% 8 - hello_world/tests.py 14 0 100% - hello_world/views.py 4 0 100% - -------------------------------------------------------- - TOTAL 34 9 74% + Name Stmts Miss Cover Missing + ----------------------------------------------------------------------- + hello_world/__init__.py 8 0 100% + hello_world/views.py 3 0 100% + ----------------------------------------------------------------------- + TOTAL 11 0 100% + - ========================= 1 passed in 0.22 seconds ========================= + ========================= 2 passed in 1.37 seconds ========================= -Our unit test passed, although its coverage is incomplete. What did our test -look like? +Our tests passed, and its coverage is complete. What did our test look like? .. literalinclude:: quick_tour/package/hello_world/tests.py :language: python :linenos: Pyramid supplies helpers for test writing, which we use in the test setup and -teardown. Our one test imports the view, makes a dummy request, and sees if the -view returns what we expected. +teardown. Our first test imports the view, makes a dummy request, and sees if the +view returns what we expected. Our second test verifies that the response body from a request to the web root contains what we expected. .. seealso:: See also: :ref:`Quick Tutorial Unit Testing `, :ref:`Quick -- cgit v1.2.3 From c87565c5ff1a3422e651f369fe4b2f848a9010ed Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 03:07:50 -0800 Subject: quick_tour - "Logging" updates for cookiecutter - fix line numbering - add new src files that were never included --- docs/quick_tour.rst | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index fd35ba419..f5f722053 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -749,38 +749,34 @@ It's important to know what is going on inside our web application. In development we might need to collect some output. In production we might need to detect situations when other people use the site. We need *logging*. -Fortunately Pyramid uses the normal Python approach to logging. The scaffold -generated in your ``development.ini`` has a number of lines that configure the +Fortunately Pyramid uses the normal Python approach to logging. The ``development.ini`` file for your project has a number of lines that configure the logging for you to some reasonable defaults. You then see messages sent by Pyramid (for example, when a new request comes in). Maybe you would like to log messages in your code? In your Python module, -import and set up the logging: +import and set up the logging in your ``views.py``: -.. literalinclude:: quick_tour/package/hello_world/views.py +.. literalinclude:: quick_tour/logging/hello_world/views.py :language: python - :linenos: - :lineno-start: 3 + :lineno-match: :lines: 3-4 You can now, in your code, log messages: -.. literalinclude:: quick_tour/package/hello_world/views.py +.. literalinclude:: quick_tour/logging/hello_world/views.py :language: python - :linenos: - :lineno-start: 9 - :lines: 9-10 + :lineno-match: + :lines: 7-8 :emphasize-lines: 2 -This will log ``Some Message`` at a ``debug`` log level to the +This will log ``Some Message`` at a ``DEBUG`` log level to the application-configured logger in your ``development.ini``. What controls that? These emphasized sections in the configuration file: -.. literalinclude:: quick_tour/package/development.ini +.. literalinclude:: quick_tour/logging/development.ini :language: ini - :linenos: - :lineno-start: 36 - :lines: 36-52 + :lineno-match: + :lines: 34-50 :emphasize-lines: 1-2,14-17 Our application, a package named ``hello_world``, is set up as a logger and @@ -789,7 +785,7 @@ http://localhost:6543, your console will now show: .. code-block:: text - 2016-01-18 13:55:55,040 DEBUG [hello_world.views:10][waitress] Some Message + 2016-12-25 03:03:57,059 DEBUG [hello_world.views:8][waitress] Some Message .. seealso:: See also: :ref:`Quick Tutorial Logging ` and :ref:`logging_chapter`. -- cgit v1.2.3 From 64009ac01e4a8a8526289d600cb3c60ca50257ef Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 03:24:10 -0800 Subject: quick_tour - "Sessions" updates for cookiecutter - add src files - adjust line numbers --- docs/quick_tour.rst | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index f5f722053..97f91d609 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -803,11 +803,10 @@ your own custom sessioning engine. Let's take a look at the :doc:`built-in sessioning support <../narr/sessions>`. In our ``__init__.py`` we first import the kind of sessioning we want: -.. literalinclude:: quick_tour/package/hello_world/__init__.py +.. literalinclude:: quick_tour/sessions/hello_world/__init__.py :language: python - :linenos: - :lineno-start: 2 - :lines: 2-3 + :lineno-match: + :lines: 1-2 :emphasize-lines: 2 .. warning:: @@ -818,31 +817,28 @@ the kind of sessioning we want: Now make a "factory" and pass it to the :term:`configurator`'s ``session_factory`` argument: -.. literalinclude:: quick_tour/package/hello_world/__init__.py +.. literalinclude:: quick_tour/sessions/hello_world/__init__.py :language: python - :linenos: - :lineno-start: 13 - :lines: 13-17 - :emphasize-lines: 3-5 + :lineno-match: + :lines: 10-13 + :emphasize-lines: 2-3 Pyramid's :term:`request` object now has a ``session`` attribute that we can use in our view code in ``views.py``: -.. literalinclude:: quick_tour/package/hello_world/views.py +.. literalinclude:: quick_tour/sessions/hello_world/views.py :language: python - :linenos: - :lineno-start: 9 - :lines: 9-15 + :lineno-match: + :lines: 7- :emphasize-lines: 3-7 -We need to update our Jinja2 template to show counter increment in the session: +We need to update our Jinja2 template ``templates/mytemplate.jinja2`` to show counter increment in the session: -.. literalinclude:: quick_tour/package/hello_world/templates/mytemplate.jinja2 +.. literalinclude:: quick_tour/sessions/hello_world/templates/mytemplate.jinja2 :language: jinja - :linenos: - :lineno-start: 40 - :lines: 40-42 - :emphasize-lines: 3 + :lineno-match: + :lines: 4-8 + :emphasize-lines: 4 .. seealso:: See also: :ref:`Quick Tutorial Sessions `, :ref:`sessions_chapter`, -- cgit v1.2.3 From b488f7f72ff36526cf21798c91c7f09eaf1afa7a Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 03:46:31 -0800 Subject: quick_tour - "Databases" updates for cookiecutter - add src files - adjust line numbers --- docs/quick_tour.rst | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index 97f91d609..68ff76b47 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -519,7 +519,7 @@ If prompted for the first item, accept the default ``yes`` by hitting return. #. ``project_name [Pyramid Scaffold]: hello_world`` #. ``repo_name [scaffold]: hello_world`` -We then run through the following commands +We then run through the following commands. .. code-block:: bash @@ -532,7 +532,7 @@ We then run through the following commands # ...and into which we install our project and its testing requirements. $ env/bin/pip install -e ".[testing]" # Reset our environment variable for a new virtual environment. - $ export VENV=~/env/hello_world/env + $ export VENV=~/hello_world/env We are moving in the direction of a full-featured Pyramid project, with a proper setup for Python standards (packaging) and Pyramid configuration. This @@ -854,13 +854,34 @@ databases frequently mean an "ORM" (object-relational mapper.) In Python, ORM usually leads to the mega-quality *SQLAlchemy*, a Python package that greatly eases working with databases. -Pyramid and SQLAlchemy are great friends. That friendship includes a scaffold! +Pyramid and SQLAlchemy are great friends. That friendship includes a cookiecutter! .. code-block:: bash - $ $VENV/bin/pcreate --scaffold alchemy sqla_demo - $ cd sqla_demo - $ $VENV/bin/pip install -e . + $ cd ~ + $ env/bin/cookiecutter https://github.com/Pylons/pyramid-cookiecutter-alchemy + +If prompted for the first item, accept the default ``yes`` by hitting return. + +#. ``You've cloned ~/.cookiecutters/pyramid-cookiecutter-alchemy before. Is it + okay to delete and re-clone it? [yes]:`` +#. ``project_name [Pyramid Scaffold]: sqla_demo`` +#. ``repo_name [scaffold]: sqla_demo`` + +We then run through the following commands as before. + +.. code-block:: bash + + # Change directory into your newly created project. + $ cd sqla_demo + # Create a new virtual environment... + $ python3 -m venv env + # ...where we upgrade packaging tools... + $ env/bin/pip install --upgrade pip setuptools + # ...and into which we install our project and its testing requirements. + $ env/bin/pip install -e ".[testing]" + # Reset our environment variable for a new virtual environment. + $ export VENV=~/sqla_demo/env We now have a working sample SQLAlchemy application with all dependencies installed. The sample project provides a console script to initialize a SQLite @@ -877,16 +898,16 @@ model: .. literalinclude:: quick_tour/sqla_demo/sqla_demo/models/mymodel.py :language: python - :start-after: Start Sphinx Include - :end-before: End Sphinx Include + :lineno-match: + :pyobject: MyModel View code, which mediates the logic between web requests and the rest of the system, can then easily get at the data thanks to SQLAlchemy: .. literalinclude:: quick_tour/sqla_demo/sqla_demo/views/default.py :language: python - :start-after: Start Sphinx Include - :end-before: End Sphinx Include + :lineno-match: + :lines: 13 .. seealso:: See also: :ref:`Quick Tutorial Databases `, `SQLAlchemy -- cgit v1.2.3 From a0ad6ffc14ef8dfde70e487fb057433ff942b001 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 25 Dec 2016 03:57:14 -0800 Subject: quick_tour - "Forms" update for recent Deform changes --- docs/quick_tour.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'docs/quick_tour.rst') diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst index 68ff76b47..186cab29e 100644 --- a/docs/quick_tour.rst +++ b/docs/quick_tour.rst @@ -966,14 +966,10 @@ Deform and Colander provide a very flexible combination for forms, widgets, schemas, and validation. Recent versions of Deform also include a :ref:`retail mode ` for gaining Deform features on custom forms. -Also the ``deform_bootstrap`` Pyramid add-on restyles the stock Deform widgets -using attractive CSS from Twitter Bootstrap and more powerful widgets from -Chosen. +Deform uses attractive CSS from Twitter Bootstrap and more powerful select, checkbox, and date and time widgets. .. seealso:: See also: - :ref:`Quick Tutorial Forms `, :ref:`Deform `, - :ref:`Colander `, and `deform_bootstrap - `_. + :ref:`Quick Tutorial Forms `, :ref:`Deform `, and :ref:`Colander `. Conclusion ========== -- cgit v1.2.3