Chris McDonough
2010-11-20 614f00c88733b5248922e2b610c96f7c8c3ff57c
- Remove calls to config.begin()/config.end() from startup config code in
tutorials and paster templates (no longer required).
26 files modified
150 ■■■■ changed files
CHANGES.txt 10 ●●●●● patch | view | raw | blame | history
TODO.txt 5 ●●●● patch | view | raw | blame | history
docs/narr/MyProject/myproject/__init__.py 3 ●●●●● patch | view | raw | blame | history
docs/narr/configuration.rst 18 ●●●●● patch | view | raw | blame | history
docs/narr/firstapp.rst 49 ●●●●● patch | view | raw | blame | history
docs/narr/project.rst 8 ●●●● patch | view | raw | blame | history
docs/narr/unittesting.rst 2 ●●● patch | view | raw | blame | history
docs/tutorials/wiki/basiclayout.rst 9 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki/src/authorization/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki/src/models/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki/src/viewdecorators/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki/src/views/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki2/basiclayout.rst 12 ●●●● patch | view | raw | blame | history
docs/tutorials/wiki2/src/authorization/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki2/src/models/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
docs/tutorials/wiki2/src/views/tutorial/__init__.py 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/alchemy/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/pylons_basic/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/pylons_minimal/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/pylons_sqla/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/routesalchemy/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/zodb/+package+/__init__.py_tmpl 2 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -26,6 +26,16 @@
- Make test suite pass on PyPy (Chameleon doesn't work).
- Surrounding application configuration with ``config.begin()`` and
  ``config.end()`` is no longer necessary.  All paster templates have been
  changed to no longer call these functions.
Documentation
-------------
- SQLAlchemy+URLDispatch and ZODB+Traversal tutorials have been updated to
  not call ``config.begin()`` or ``config.end()``.
Bug Fixes
---------
TODO.txt
@@ -16,9 +16,6 @@
- Use ``@register_view`` instead of ``@view_config`` and change view docs to
  use "view registration" instead of "view configuration".
- Remove calls to config.begin()/config.end() from startup config code in
  tutorials and paster templates (no longer required).
- SQLAlchemy idiomatics:
   <RaFromBRC> mcdonc: those paster templates all look pretty good... the
@@ -59,7 +56,7 @@
Should-Have
-----------
- Try to make test suite pass on PyPy, IronPython.
- Try to make test suite pass on IronPython.
- Add docs for httpexceptions module for each webob.exc class that inherits
  from WSGIHTTPException.
docs/narr/MyProject/myproject/__init__.py
@@ -5,11 +5,8 @@
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.add_view('myproject.views.my_view',
                    context='myproject.models.MyModel',
                    renderer='myproject:templates/mytemplate.pt')
    config.add_static_view('static', 'myproject:static')
    config.end()
    return config.make_wsgi_app()
docs/narr/configuration.rst
@@ -47,20 +47,16 @@
   if __name__ == '__main__':
       config = Configurator()
       config.begin()
       config.add_view(hello_world)
       config.end()
       app = config.make_wsgi_app()
       serve(app, host='0.0.0.0')
We won't talk much about what this application does yet.  Just note
that the "configuration' statements take place underneath the ``if
__name__ == '__main__':`` stanza in the form of method calls on a
:term:`Configurator` object (e.g. ``config.begin()``,
``config.add_view(...)``, and ``config.end()``.  These statements take
place one after the other, and are executed in order, so the full
power of Python, including conditionals, can be employed in this mode
of configuration.
We won't talk much about what this application does yet.  Just note that the
"configuration' statements take place underneath the ``if __name__ ==
'__main__':`` stanza in the form of method calls on a :term:`Configurator`
object (e.g. ``config.add_view(...)``).  These statements take place one
after the other, and are executed in order, so the full power of Python,
including conditionals, can be employed in this mode of configuration.
.. index::
   single: view_config
@@ -123,9 +119,7 @@
      if __name__ == '__main__':
          from pyramid.configuration import Configurator
          config = Configurator()
          config.begin()
          config.scan()
          config.end()
          app = config.make_wsgi_app()
          serve(app, host='0.0.0.0')
docs/narr/firstapp.rst
@@ -38,10 +38,8 @@
   if __name__ == '__main__':
       config = Configurator()
       config.begin()
       config.add_view(hello_world)
       config.add_view(goodbye_world, name='goodbye')
       config.end()
       app = config.make_wsgi_app()
       serve(app, host='0.0.0.0')
@@ -149,10 +147,8 @@
   if __name__ == '__main__':
       config = Configurator()
       config.begin()
       config.add_view(hello_world)
       config.add_view(goodbye_world, name='goodbye')
       config.end()
       app = config.make_wsgi_app()
       serve(app, host='0.0.0.0')
@@ -189,29 +185,6 @@
this particular :app:`Pyramid` application.  Methods called on the
Configurator will cause registrations to be made in a
:term:`application registry` associated with the application.
Beginning Configuration
~~~~~~~~~~~~~~~~~~~~~~~
.. ignore-next-block
.. code-block:: python
   config.begin()
The :meth:`pyramid.configuration.Configurator.begin` method tells
the system that application configuration has begun.  In particular,
this causes the :term:`application registry` associated with this
configurator to become the "current" application registry, meaning
that code which attempts to use the application registry :term:`thread
local` will obtain the registry associated with the configurator.
This is an explicit step because it's sometimes convenient to use a
configurator without causing the registry associated with the
configurator to become "current".
.. note::
   See :ref:`threadlocals_chapter` for a discussion about what it
   means for an application registry to be "current".
.. _adding_configuration:
@@ -280,28 +253,6 @@
important.  We can register ``goodbye_world`` first and
``hello_world`` second; :app:`Pyramid` will still give us the most
specific callable when a request is dispatched to it.
Ending Configuration
~~~~~~~~~~~~~~~~~~~~
.. ignore-next-block
.. code-block:: python
   config.end()
The :meth:`pyramid.configuration.Configurator.end` method tells the
system that application configuration has ended.  It is the inverse of
:meth:`pyramid.configuration.Configurator.begin`.  In particular,
this causes the :term:`application registry` associated with this
configurator to no longer be the "current" application registry,
meaning that code which attempts to use the application registry
:term:`thread local` will no longer obtain the registry associated
with the configurator.
.. note::
   See :ref:`threadlocals_chapter` for a discussion about what it
   means for an application registry to be "current".
.. index::
   single: make_wsgi_app
docs/narr/project.rst
@@ -740,14 +740,14 @@
#. Line 2 imports the ``get_root`` function from
   :mod:`myproject.models` that we use later.
#. Lines 4-14 define a function that returns a :app:`Pyramid`
#. Lines 4-12 define a function that returns a :app:`Pyramid`
   WSGI application.  This function is meant to be called
   by the :term:`PasteDeploy` framework as a result of running
   ``paster serve``.
   Within this function, configuration is performed.
   Lines 9-11 register a "default view" (a view that has no ``name``
   Lines 8-10 register a "default view" (a view that has no ``name``
   attribute).  It is registered so that it will be found when the
   :term:`context` of the request is an instance of the
   :class:`myproject.models.MyModel` class.  The first argument to
@@ -761,11 +761,11 @@
   ``templates`` directory of the ``myproject`` package.  The template file
   it actually points to is a :term:`Chameleon` ZPT template file.
   Line 12 registers a static view, which will serve up the files from the
   Line 11 registers a static view, which will serve up the files from the
   ``mypackage:static`` :term:`resource specification` (the ``static``
   directory of the ``mypackage`` package).
   Line 14 returns a :term:`WSGI` application to the caller of the function
   Line 12 returns a :term:`WSGI` application to the caller of the function
   (Paste).
``views.py``
docs/narr/unittesting.rst
@@ -1,4 +1,4 @@
.. index::
\.. index::
   single: unit testing
   single: integration testing
docs/tutorials/wiki/basiclayout.rst
@@ -48,14 +48,11 @@
   factory` and the settings keywords parsed by PasteDeploy.  The root
   factory is named ``get_root``.
#. *Lines 16-18*.  Begin configuration using the ``begin`` method of
   the :meth:`pyramid.configuration.Configurator` class, load the
#. *Line 16*.  Load the
   ``configure.zcml`` file from our package using the
   :meth:`pyramid.configuration.Configurator.load_zcml` method, and
   end configuration using the
   :meth:`pyramid.configuration.Configurator.end` method.
   :meth:`pyramid.configuration.Configurator.load_zcml` method.
#. *Line 19*.  Use the
#. *Line 17*.  Use the
   :meth:`pyramid.configuration.Configurator.make_wsgi_app` method
   to return a :term:`WSGI` application.
docs/tutorials/wiki/src/authorization/tutorial/__init__.py
@@ -16,7 +16,5 @@
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml('configure.zcml')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py
@@ -13,8 +13,6 @@
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml('configure.zcml')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki/src/models/tutorial/__init__.py
@@ -16,8 +16,6 @@
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml('configure.zcml')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki/src/viewdecorators/tutorial/__init__.py
@@ -16,8 +16,6 @@
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml('configure.zcml')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki/src/views/tutorial/__init__.py
@@ -16,8 +16,6 @@
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml('configure.zcml')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki2/basiclayout.rst
@@ -52,10 +52,7 @@
   deployment-related values such as ``reload_templates``,
   ``db_string``, etc.
#. *Line 15*.  We call :meth:`pyramid.configuration.Configurator.begin` which
    tells the configuration machinery we are starting configuration.
#. *Line 16*.  We call
#. *Line 15*.  We call
   :meth:`pyramid.configuration.Configurator.add_static_view` with the
   arguments ``static`` (the name), and ``tutorial:static`` (the path).  This
   registers a static resource view which will match any URL that starts with
@@ -67,7 +64,7 @@
   ``/static/foo``) will be used to compose a path to a static file resource,
   such as a CSS file.
#. *Lines 17-18*.  Register a :term:`route configuration` via the
#. *Lines 16-17*.  Register a :term:`route configuration` via the
   :meth:`pyramid.configuration.Configurator.add_route` method that will be
   used when the URL is ``/``.  Since this route has an ``pattern`` equalling
   ``/`` it is the "default" route. The argument named ``view`` with the
@@ -81,10 +78,7 @@
   ``tutorial.views.my_view`` view returns a dictionary, a :term:`renderer`
   will use this template to create a response.
#. *Line 19*.  We call :meth:`pyramid.configuration.Configurator.end` which
    tells the configuration machinery we are ending configuration.
#. *Line 20*.  We use the
#. *Line 18*.  We use the
   :meth:`pyramid.configuration.Configurator.make_wsgi_app` method to return
   a :term:`WSGI` application.
docs/tutorials/wiki2/src/authorization/tutorial/__init__.py
@@ -22,7 +22,6 @@
                          root_factory='tutorial.models.RootFactory',
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy)
    config.begin()
    config.add_static_view('static', 'tutorial:static')
    config.add_route('view_wiki', '/', view='tutorial.views.view_wiki')
    config.add_route('login', '/login',
@@ -44,6 +43,5 @@
    config.add_view('tutorial.login.login',
                    renderer='tutorial:templates/login.pt',
                    context='pyramid.exceptions.Forbidden')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py
@@ -12,11 +12,9 @@
    db_echo = settings.get('db_echo', 'false')
    initialize_sql(db_string, asbool(db_echo))
    config = Configurator(settings=settings)
    config.begin()
    config.add_static_view('static', 'tutorial:static')
    config.add_route('home', '/', view='tutorial.views.my_view',
                     view_renderer='templates/mytemplate.pt')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki2/src/models/tutorial/__init__.py
@@ -12,9 +12,7 @@
    db_echo = settings.get('db_echo', 'false')
    initialize_sql(db_string, asbool(db_echo))
    config = Configurator(settings=settings)
    config.begin()
    config.add_static_view('static', 'tutorial:static')
    config.add_route('home', '/', view='tutorial.views.my_view',
                     view_renderer='templates/mytemplate.pt')
    config.end()
    return config.make_wsgi_app()
docs/tutorials/wiki2/src/views/tutorial/__init__.py
@@ -12,7 +12,6 @@
    db_echo = settings.get('db_echo', 'false')
    initialize_sql(db_string, asbool(db_echo))
    config = Configurator(settings=settings)
    config.begin()
    config.add_static_view('static', 'tutorial:static')
    config.add_route('home', '/', view='tutorial.views.view_wiki')
    config.add_route('view_page', '/:pagename',
@@ -24,6 +23,5 @@
    config.add_route('edit_page', '/:pagename/edit_page',
                     view='tutorial.views.edit_page',
                     view_renderer='tutorial:templates/edit.pt')
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/alchemy/+package+/__init__.py_tmpl
@@ -12,7 +12,6 @@
    db_echo = settings.get('db_echo', 'false')
    get_root = appmaker(db_string, asbool(db_echo))
    config = Configurator(settings=settings, root_factory=get_root)
    config.begin()
    config.add_static_view('static', '{{package}}:static')
    config.add_view('{{package}}.views.view_root', 
                    context='{{package}}.models.MyApp', 
@@ -20,7 +19,6 @@
    config.add_view('{{package}}.views.view_model',
                    context='{{package}}.models.MyModel',
                    renderer="templates/model.pt")
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/pylons_basic/+package+/__init__.py_tmpl
@@ -5,7 +5,6 @@
    """
    from pyramid.configuration import Configurator
    config = Configurator(settings=settings)
    config.begin()
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    config.add_static_view('static', '{{package}}:static/')
@@ -15,5 +14,4 @@
                       action='index')
    config.add_subscriber('{{package}}.lib.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/pylons_minimal/+package+/__init__.py_tmpl
@@ -5,7 +5,6 @@
    """
    from pyramid.configuration import Configurator
    config = Configurator(settings=settings)
    config.begin()
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    config.add_static_view('static', '{{package}}:static/')
@@ -14,6 +13,5 @@
                       action='index')
    config.add_subscriber('{{package}}.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/pylons_sqla/+package+/__init__.py_tmpl
@@ -13,7 +13,6 @@
                         "configuration.")
    initialize_sql(db_string, asbool(settings.get('db_echo')))
    config = Configurator(settings=settings)
    config.begin()
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    config.add_static_view('static', '{{package}}:static/')
@@ -22,5 +21,4 @@
                       action='index')
    config.add_subscriber('{{package}}.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/routesalchemy/+package+/__init__.py_tmpl
@@ -12,11 +12,9 @@
    db_echo = settings.get('db_echo', 'false')
    initialize_sql(db_string, asbool(db_echo))
    config = Configurator(settings=settings)
    config.begin()
    config.add_static_view('static', '{{package}}:static')
    config.add_route('home', '/', view='{{package}}.views.my_view',
                     view_renderer='templates/mytemplate.pt')
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/starter/+package+/__init__.py_tmpl
@@ -5,11 +5,9 @@
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.add_view('{{package}}.views.my_view',
                    context='{{package}}.models.MyModel',
                    renderer='{{package}}:templates/mytemplate.pt')
    config.add_static_view('static', '{{package}}:static')
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl
@@ -6,8 +6,6 @@
    """
    zcml_file = settings.get('configure_zcml', 'configure.zcml')
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml(zcml_file)
    config.end()
    return config.make_wsgi_app()
pyramid/paster_templates/zodb/+package+/__init__.py_tmpl
@@ -14,7 +14,5 @@
    def get_root(request):
        return finder(request.environ)
    config = Configurator(root_factory=get_root, settings=settings)
    config.begin()
    config.load_zcml(zcml_file)
    config.end()
    return config.make_wsgi_app()