Skip to content

Commit

Permalink
Merge pull request #738 from ppaez/pep8_scaffolds
Browse files Browse the repository at this point in the history
Improve pep8 compliance of scaffolds
  • Loading branch information
mcdonc committed Dec 10, 2012
2 parents a078e19 + 95a0b80 commit 551ac9d
Show file tree
Hide file tree
Showing 73 changed files with 192 additions and 150 deletions.
1 change: 1 addition & 0 deletions docs/narr/MyProject/myproject/__init__.py
@@ -1,5 +1,6 @@
from pyramid.config import Configurator


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
Expand Down
1 change: 1 addition & 0 deletions docs/narr/MyProject/myproject/tests.py
Expand Up @@ -2,6 +2,7 @@

from pyramid import testing


class ViewTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
Expand Down
3 changes: 2 additions & 1 deletion docs/narr/MyProject/myproject/views.py
@@ -1,5 +1,6 @@
from pyramid.view import view_config


@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
return {'project':'MyProject'}
return {'project': 'MyProject'}
6 changes: 3 additions & 3 deletions docs/narr/MyProject/setup.py
Expand Up @@ -15,10 +15,10 @@
setup(name='MyProject',
version='0.0',
description='MyProject',
long_description=README + '\n\n' + CHANGES,
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pylons",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
Expand All @@ -32,7 +32,7 @@
install_requires=requires,
tests_require=requires,
test_suite="myproject",
entry_points = """\
entry_points="""\
[paste.app_factory]
main = myproject:main
""",
Expand Down
14 changes: 7 additions & 7 deletions docs/narr/project.rst
Expand Up @@ -829,25 +829,25 @@ also informs Python that the directory which contains it is a *package*.
#. Line 1 imports the :term:`Configurator` class from :mod:`pyramid.config`
that we use later.

#. Lines 3-10 define a function named ``main`` that returns a :app:`Pyramid`
#. Lines 4-11 define a function named ``main`` that returns a :app:`Pyramid`
WSGI application. This function is meant to be called by the
:term:`PasteDeploy` framework as a result of running ``pserve``.

Within this function, application configuration is performed.

Line 6 creates an instance of a :term:`Configurator`.
Line 7 creates an instance of a :term:`Configurator`.

Line 7 registers a static view, which will serve up the files from the
Line 8 registers a static view, which will serve up the files from the
``myproject:static`` :term:`asset specification` (the ``static``
directory of the ``myproject`` package).

Line 8 adds a :term:`route` to the configuration. This route is later
Line 9 adds a :term:`route` to the configuration. This route is later
used by a view in the ``views`` module.

Line 9 calls ``config.scan()``, which picks up view registrations declared
Line 10 calls ``config.scan()``, which picks up view registrations declared
elsewhere in the package (in this case, in the ``views.py`` module).

Line 10 returns a :term:`WSGI` application to the caller of the function
Line 11 returns a :term:`WSGI` application to the caller of the function
(Pyramid's pserve).

.. index::
Expand All @@ -865,7 +865,7 @@ and which returns a :term:`response`.
:language: python
:linenos:

Lines 3-5 define and register a :term:`view callable` named ``my_view``. The
Lines 4-6 define and register a :term:`view callable` named ``my_view``. The
function named ``my_view`` is decorated with a ``view_config`` decorator
(which is processed by the ``config.scan()`` line in our ``__init__.py``).
The view_config decorator asserts that this view be found when a
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/wiki/authorization.rst
Expand Up @@ -127,7 +127,7 @@ add these import statements:
Now add those policies to the configuration:

.. literalinclude:: src/authorization/tutorial/__init__.py
:lines: 17-22
:lines: 18-23
:linenos:
:emphasize-lines: 1-3,5-6
:language: python
Expand Down Expand Up @@ -213,7 +213,7 @@ expire an auth ticket cookie.
Now add the ``login`` and ``logout`` views:

.. literalinclude:: src/authorization/tutorial/views.py
:lines: 87-120
:lines: 82-120
:linenos:
:language: python

Expand Down Expand Up @@ -306,7 +306,7 @@ when we're done:

.. literalinclude:: src/authorization/tutorial/__init__.py
:linenos:
:emphasize-lines: 4-5,8,17-19,21-22
:emphasize-lines: 4-5,8,18-20,22-23
:language: python

(Only the highlighted lines need to be added.)
Expand Down
18 changes: 9 additions & 9 deletions docs/tutorials/wiki/basiclayout.rst
Expand Up @@ -31,13 +31,13 @@ point happens to be the ``main`` function within the file named

#. *Lines 1-3*. Perform some dependency imports.

#. *Lines 5-7* Define a root factory for our Pyramid application.
#. *Lines 6-8* Define a root factory for our Pyramid application.

#. *Line 12*. We construct a :term:`Configurator` with a :term:`root
#. *Line 14*. We construct a :term:`Configurator` with a :term:`root
factory` and the settings keywords parsed by :term:`PasteDeploy`. The root
factory is named ``root_factory``.

#. *Line 13*. Register a 'static view' which answers requests which start
#. *Line 15*. Register a 'static view' which answers requests which start
with with URL path ``/static`` using the
:meth:`pyramid.config.Configurator.add_static_view method`. This
statement registers a view that will serve up static assets, such as CSS
Expand All @@ -50,7 +50,7 @@ point happens to be the ``main`` function within the file named
package. The scaffold could have alternately used an *absolute* asset
specification as the path (``tutorial:static``) but it does not.

#. *Line 14*. Perform a :term:`scan`. A scan will find :term:`configuration
#. *Line 16*. Perform a :term:`scan`. A scan will find :term:`configuration
decoration`, such as view configuration decorators (e.g. ``@view_config``)
in the source code of the ``tutorial`` package and will take actions based
on these decorators. We don't pass any arguments to
Expand All @@ -59,7 +59,7 @@ point happens to be the ``main`` function within the file named
The scaffold could have equivalently said ``config.scan('tutorial')`` but
it chose to omit the package name argument.

#. *Line 15*. Use the
#. *Line 17*. Use the
:meth:`pyramid.config.Configurator.make_wsgi_app` method
to return a :term:`WSGI` application.

Expand All @@ -81,15 +81,15 @@ Here is the source for ``models.py``:
:linenos:
:language: py

#. *Lines 3-4*. The ``MyModel`` :term:`resource` class is implemented here.
#. *Lines 4-5*. The ``MyModel`` :term:`resource` class is implemented here.
Instances of this class will be capable of being persisted in :term:`ZODB`
because the class inherits from the
:class:`persistent.mapping.PersistentMapping` class. The ``__parent__``
and ``__name__`` are important parts of the :term:`traversal` protocol.
By default, have these as ``None`` indicating that this is the
:term:`root` object.

#. *Lines 6-12*. ``appmaker`` is used to return the *application
#. *Lines 8-14*. ``appmaker`` is used to return the *application
root* object. It is called on *every request* to the
:app:`Pyramid` application. It also performs bootstrapping by
*creating* an application root (inside the ZODB root object) if one
Expand Down Expand Up @@ -118,7 +118,7 @@ Let's try to understand the components in this module:

#. *Lines 1-2*. Perform some dependency imports.

#. *Line 4*. Use the :func:`pyramid.view.view_config` :term:`configuration
#. *Line 5*. Use the :func:`pyramid.view.view_config` :term:`configuration
decoration` to perform a :term:`view configuration` registration. This
view configuration registration will be activated when the application is
started. It will be activated by virtue of it being found as the result
Expand Down Expand Up @@ -148,7 +148,7 @@ Let's try to understand the components in this module:
``my_view`` function which it decorates represents the "default" view
callable used when the context is of the type ``MyModel``.

#. *Lines 5-6*. We define a :term:`view callable` named ``my_view``, which
#. *Lines 6-7*. We define a :term:`view callable` named ``my_view``, which
we decorated in the step above. This view callable is a *function* we
write generated by the ``zodb`` scaffold that is given a
``request`` and which returns a dictionary. The ``mytemplate.pt``
Expand Down
9 changes: 4 additions & 5 deletions docs/tutorials/wiki/src/authorization/setup.py
Expand Up @@ -20,7 +20,7 @@
setup(name='tutorial',
version='0.0',
description='tutorial',
long_description=README + '\n\n' + CHANGES,
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
Expand All @@ -34,12 +34,11 @@
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires = requires,
tests_require= requires,
install_requires=requires,
tests_require=requires,
test_suite="tutorial",
entry_points = """\
entry_points="""\
[paste.app_factory]
main = tutorial:main
""",
)

3 changes: 2 additions & 1 deletion docs/tutorials/wiki/src/authorization/tutorial/__init__.py
Expand Up @@ -11,8 +11,9 @@ def root_factory(request):
conn = get_connection(request)
return appmaker(conn.root())


def main(global_config, **settings):
""" This function returns a WSGI application.
""" This function returns a Pyramid WSGI application.
"""
authn_policy = AuthTktAuthenticationPolicy(
'sosecret', callback=groupfinder, hashalg='sha512')
Expand Down
9 changes: 5 additions & 4 deletions docs/tutorials/wiki/src/authorization/tutorial/tests.py
Expand Up @@ -30,6 +30,7 @@ def test_it(self):
self.assertEqual(wiki.__name__, None)

class AppmakerTests(unittest.TestCase):

def _callFUT(self, zodb_root):
from .models import appmaker
return appmaker(zodb_root)
Expand Down Expand Up @@ -63,7 +64,7 @@ def test_it(self):
info = self._callFUT(context, request)
self.assertEqual(info['page'], context)
self.assertEqual(
info['content'],
info['content'],
'<div class="document">\n'
'<p>Hello <a href="http://example.com/add_page/CruelWorld">'
'CruelWorld</a> '
Expand All @@ -85,9 +86,9 @@ def test_it_notsubmitted(self):
request.subpath = ['AnotherPage']
info = self._callFUT(context, request)
self.assertEqual(info['page'].data,'')
self.assertEqual(info['save_url'],
request.resource_url(
context, 'add_page', 'AnotherPage'))
self.assertEqual(
info['save_url'],
request.resource_url(context, 'add_page', 'AnotherPage'))

def test_it_submitted(self):
context = testing.DummyResource()
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/wiki/src/authorization/tutorial/views.py
Expand Up @@ -64,8 +64,8 @@ def add_page(context, request):
page.__name__ = pagename
page.__parent__ = context

return dict(page = page, save_url = save_url,
logged_in = authenticated_userid(request))
return dict(page=page, save_url=save_url,
logged_in=authenticated_userid(request))

@view_config(name='edit_page', context='.models.Page',
renderer='templates/edit.pt',
Expand All @@ -75,9 +75,9 @@ def edit_page(context, request):
context.data = request.params['body']
return HTTPFound(location = request.resource_url(context))

return dict(page = context,
save_url = request.resource_url(context, 'edit_page'),
logged_in = authenticated_userid(request))
return dict(page=context,
save_url=request.resource_url(context, 'edit_page'),
logged_in=authenticated_userid(request))

@view_config(context='.models.Wiki', name='login',
renderer='templates/login.pt')
Expand Down
9 changes: 4 additions & 5 deletions docs/tutorials/wiki/src/basiclayout/setup.py
Expand Up @@ -19,7 +19,7 @@
setup(name='tutorial',
version='0.0',
description='tutorial',
long_description=README + '\n\n' + CHANGES,
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
Expand All @@ -33,12 +33,11 @@
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires = requires,
tests_require= requires,
install_requires=requires,
tests_require=requires,
test_suite="tutorial",
entry_points = """\
entry_points="""\
[paste.app_factory]
main = tutorial:main
""",
)

2 changes: 2 additions & 0 deletions docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py
Expand Up @@ -2,10 +2,12 @@
from pyramid_zodbconn import get_connection
from .models import appmaker


def root_factory(request):
conn = get_connection(request)
return appmaker(conn.root())


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorials/wiki/src/basiclayout/tutorial/models.py
@@ -1,8 +1,10 @@
from persistent.mapping import PersistentMapping


class MyModel(PersistentMapping):
__parent__ = __name__ = None


def appmaker(zodb_root):
if not 'app_root' in zodb_root:
app_root = MyModel()
Expand Down
1 change: 0 additions & 1 deletion docs/tutorials/wiki/src/basiclayout/tutorial/tests.py
Expand Up @@ -14,4 +14,3 @@ def test_my_view(self):
request = testing.DummyRequest()
info = my_view(request)
self.assertEqual(info['project'], 'tutorial')

3 changes: 2 additions & 1 deletion docs/tutorials/wiki/src/basiclayout/tutorial/views.py
@@ -1,6 +1,7 @@
from pyramid.view import view_config
from .models import MyModel


@view_config(context=MyModel, renderer='templates/mytemplate.pt')
def my_view(request):
return {'project':'tutorial'}
return {'project': 'tutorial'}
9 changes: 4 additions & 5 deletions docs/tutorials/wiki/src/models/setup.py
Expand Up @@ -19,7 +19,7 @@
setup(name='tutorial',
version='0.0',
description='tutorial',
long_description=README + '\n\n' + CHANGES,
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
Expand All @@ -33,12 +33,11 @@
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires = requires,
tests_require= requires,
install_requires=requires,
tests_require=requires,
test_suite="tutorial",
entry_points = """\
entry_points="""\
[paste.app_factory]
main = tutorial:main
""",
)

5 changes: 3 additions & 2 deletions docs/tutorials/wiki/src/models/tutorial/__init__.py
Expand Up @@ -2,15 +2,16 @@
from pyramid_zodbconn import get_connection
from .models import appmaker


def root_factory(request):
conn = get_connection(request)
return appmaker(conn.root())


def main(global_config, **settings):
""" This function returns a WSGI application.
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=root_factory, settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.scan()
return config.make_wsgi_app()

6 changes: 4 additions & 2 deletions docs/tutorials/wiki/src/models/tutorial/views.py
@@ -1,5 +1,7 @@
from pyramid.view import view_config
from .models import MyModel

@view_config(renderer='templates/mytemplate.pt')

@view_config(context=MyModel, renderer='templates/mytemplate.pt')
def my_view(request):
return {'project':'tutorial'}
return {'project': 'tutorial'}

0 comments on commit 551ac9d

Please sign in to comment.