commit | author | age
|
555838
|
1 |
What's New in Pyramid 1.6 |
bfe000
|
2 |
========================= |
CM |
3 |
|
|
4 |
This article explains the new features in :app:`Pyramid` version 1.6 as |
555838
|
5 |
compared to its predecessor, :app:`Pyramid` 1.5. It also documents backwards |
bfe000
|
6 |
incompatibilities between the two versions and deprecations added to |
CM |
7 |
:app:`Pyramid` 1.6, as well as software dependency changes and notable |
|
8 |
documentation additions. |
|
9 |
|
555838
|
10 |
|
bfe000
|
11 |
Backwards Incompatibilities |
CM |
12 |
--------------------------- |
|
13 |
|
555838
|
14 |
- IPython and BPython support have been removed from pshell in the core. To |
MM |
15 |
continue using them on Pyramid 1.6+, you must install the binding packages |
|
16 |
explicitly. One way to do this is by adding ``pyramid_ipython`` (or |
|
17 |
``pyramid_bpython``) to the ``install_requires`` section of your package's |
|
18 |
``setup.py`` file, then re-running ``setup.py develop``:: |
|
19 |
|
|
20 |
setup( |
|
21 |
#... |
|
22 |
install_requires=[ |
|
23 |
'pyramid_ipython', # new dependency |
|
24 |
'pyramid', |
|
25 |
#... |
|
26 |
], |
|
27 |
) |
|
28 |
|
bfe000
|
29 |
- ``request.response`` will no longer be mutated when using the |
555838
|
30 |
:func:`~pyramid.renderers.render_to_response` API. It is now necessary to |
MM |
31 |
pass in a ``response=`` argument to |
|
32 |
:func:`~pyramid.renderers.render_to_response` if you wish to supply the |
|
33 |
renderer with a custom response object. If you do not pass one, then a |
|
34 |
response object will be created using the current response factory. Almost |
|
35 |
all renderers mutate the ``request.response`` response object (for example, |
|
36 |
the JSON renderer sets ``request.response.content_type`` to |
|
37 |
``application/json``). However, when invoking ``render_to_response``, it is |
|
38 |
not expected that the response object being returned would be the same one |
|
39 |
used later in the request. The response object returned from |
|
40 |
``render_to_response`` is now explicitly different from ``request.response``. |
|
41 |
This does not change the API of a renderer. See |
bfe000
|
42 |
https://github.com/Pylons/pyramid/pull/1563 |
CM |
43 |
|
0f451b
|
44 |
- In an effort to combat a common issue it is now a |
MM |
45 |
:class:`~pyramid.exceptions.ConfigurationError` to register a view |
|
46 |
callable that is actually an unbound method when using the default view |
|
47 |
mapper. As unbound methods do not exist in PY3+ possible errors are detected |
|
48 |
by checking if the first parameter is named ``self``. For example, |
|
49 |
`config.add_view(ViewClass.some_method, ...)` should actually be |
|
50 |
`config.add_view(ViewClass, attr='some_method)'`. This was always an issue |
|
51 |
in Pyramid on PY2 but the backward incompatibility is on PY3+ where you may |
|
52 |
not use a function with the first parameter named ``self``. In this case |
|
53 |
it looks too much like a common error and the exception will be raised. |
|
54 |
See https://github.com/Pylons/pyramid/pull/1498 |
|
55 |
|
bfe000
|
56 |
|
CM |
57 |
Feature Additions |
|
58 |
----------------- |
|
59 |
|
555838
|
60 |
- Python 3.5 and pypy3 compatibility. |
MM |
61 |
|
|
62 |
- ``pserve --reload`` will no longer crash on syntax errors. See |
|
63 |
https://github.com/Pylons/pyramid/pull/2044 |
|
64 |
|
|
65 |
- Cache busting for static resources has been added and is available via a new |
|
66 |
:meth:`pyramid.config.Configurator.add_cache_buster` API. Core APIs are |
|
67 |
shipped for both cache busting via query strings and via asset manifests for |
|
68 |
integrating into custom asset pipelines. See |
|
69 |
https://github.com/Pylons/pyramid/pull/1380 and |
|
70 |
https://github.com/Pylons/pyramid/pull/1583 and |
|
71 |
https://github.com/Pylons/pyramid/pull/2171 |
bfe000
|
72 |
|
CM |
73 |
- Assets can now be overidden by an absolute path on the filesystem when using |
|
74 |
the :meth:`~pyramid.config.Configurator.override_asset` API. This makes it |
|
75 |
possible to fully support serving up static content from a mutable directory |
|
76 |
while still being able to use the :meth:`~pyramid.request.Request.static_url` |
|
77 |
API and :meth:`~pyramid.config.Configurator.add_static_view`. Previously it |
|
78 |
was not possible to use :meth:`~pyramid.config.Configurator.add_static_view` |
|
79 |
with an absolute path **and** generate urls to the content. This change |
|
80 |
replaces the call, ``config.add_static_view('/abs/path', 'static')``, with |
|
81 |
``config.add_static_view('myapp:static', 'static')`` and |
|
82 |
``config.override_asset(to_override='myapp:static/', |
|
83 |
override_with='/abs/path/')``. The ``myapp:static`` asset spec is completely |
555838
|
84 |
made up and does not need to exist—it is used for generating URLs via |
MM |
85 |
``request.static_url('myapp:static/foo.png')``. See |
bfe000
|
86 |
https://github.com/Pylons/pyramid/issues/1252 |
CM |
87 |
|
|
88 |
- Added :meth:`~pyramid.config.Configurator.set_response_factory` and the |
|
89 |
``response_factory`` keyword argument to the constructor of |
|
90 |
:class:`~pyramid.config.Configurator` for defining a factory that will return |
555838
|
91 |
a custom ``Response`` class. See https://github.com/Pylons/pyramid/pull/1499 |
bfe000
|
92 |
|
555838
|
93 |
- Added :attr:`pyramid.config.Configurator.root_package` attribute and init |
MM |
94 |
parameter to assist with includible packages that wish to resolve resources |
|
95 |
relative to the package in which the configurator was created. This is |
|
96 |
especially useful for add-ons that need to load asset specs from settings, in |
|
97 |
which case it may be natural for a developer to define imports or assets |
|
98 |
relative to the top-level package. See |
|
99 |
https://github.com/Pylons/pyramid/pull/1337 |
bfe000
|
100 |
|
093605
|
101 |
- Overall improvements for the ``proutes`` command. Added ``--format`` and |
bfe000
|
102 |
``--glob`` arguments to the command, introduced the ``method`` |
CM |
103 |
column for displaying available request methods, and improved the ``view`` |
555838
|
104 |
output by showing the module instead of just ``__repr__``. See |
MM |
105 |
https://github.com/Pylons/pyramid/pull/1488 |
bfe000
|
106 |
|
CM |
107 |
- ``pserve`` can now take a ``-b`` or ``--browser`` option to open the server |
|
108 |
URL in a web browser. See https://github.com/Pylons/pyramid/pull/1533 |
|
109 |
|
555838
|
110 |
- Support keyword-only arguments and function annotations in views in Python 3. |
MM |
111 |
See https://github.com/Pylons/pyramid/pull/1556 |
bfe000
|
112 |
|
CM |
113 |
- The ``append_slash`` argument of |
|
114 |
:meth:`~pyramid.config.Configurator.add_notfound_view()` will now accept |
|
115 |
anything that implements the :class:`~pyramid.interfaces.IResponse` interface |
|
116 |
and will use that as the response class instead of the default |
555838
|
117 |
:class:`~pyramid.httpexceptions.HTTPFound`. See |
bfe000
|
118 |
https://github.com/Pylons/pyramid/pull/1610 |
CM |
119 |
|
|
120 |
- The :class:`~pyramid.config.Configurator` has grown the ability to allow |
555838
|
121 |
actions to call other actions during a commit cycle. This enables much more |
bfe000
|
122 |
logic to be placed into actions, such as the ability to invoke other actions |
CM |
123 |
or group them for improved conflict detection. We have also exposed and |
555838
|
124 |
documented the configuration phases that Pyramid uses in order to further |
MM |
125 |
assist in building conforming add-ons. See |
|
126 |
https://github.com/Pylons/pyramid/pull/1513 |
bfe000
|
127 |
|
CM |
128 |
- Allow an iterator to be returned from a renderer. Previously it was only |
555838
|
129 |
possible to return bytes or unicode. See |
MM |
130 |
https://github.com/Pylons/pyramid/pull/1417 |
bfe000
|
131 |
|
CM |
132 |
- Improve robustness to timing attacks in the |
|
133 |
:class:`~pyramid.authentication.AuthTktCookieHelper` and the |
|
134 |
:class:`~pyramid.session.SignedCookieSessionFactory` classes by using the |
555838
|
135 |
stdlib's ``hmac.compare_digest`` if it is available (such as Python 2.7.7+ |
MM |
136 |
and 3.3+). See https://github.com/Pylons/pyramid/pull/1457 |
bfe000
|
137 |
|
555838
|
138 |
- Improve the readability of the ``pcreate`` shell script output. See |
MM |
139 |
https://github.com/Pylons/pyramid/pull/1453 |
bfe000
|
140 |
|
555838
|
141 |
- Make it simple to define ``notfound`` and ``forbidden`` views that wish to |
MM |
142 |
use the default exception-response view, but with altered predicates and |
|
143 |
other configuration options. The ``view`` argument is now optional in |
bfe000
|
144 |
:meth:`~pyramid.config.Configurator.add_notfound_view` and |
CM |
145 |
:meth:`~pyramid.config.Configurator.add_forbidden_view` See |
|
146 |
https://github.com/Pylons/pyramid/issues/494 |
|
147 |
|
|
148 |
- The ``pshell`` script will now load a ``PYTHONSTARTUP`` file if one is |
555838
|
149 |
defined in the environment prior to launching the interpreter. See |
MM |
150 |
https://github.com/Pylons/pyramid/pull/1448 |
bfe000
|
151 |
|
555838
|
152 |
- Add new HTTP exception objects for status codes ``428 Precondition |
MM |
153 |
Required``, ``429 Too Many Requests`` and ``431 Request Header Fields Too |
|
154 |
Large`` in ``pyramid.httpexceptions``. See |
|
155 |
https://github.com/Pylons/pyramid/pull/1372/files |
bfe000
|
156 |
|
CM |
157 |
- ``pcreate`` when run without a scaffold argument will now print information |
555838
|
158 |
on the missing flag, as well as a list of available scaffolds. See |
bfe000
|
159 |
https://github.com/Pylons/pyramid/pull/1566 and |
CM |
160 |
https://github.com/Pylons/pyramid/issues/1297 |
555838
|
161 |
|
MM |
162 |
- ``pcreate`` will now ask for confirmation if invoked with an argument for a |
|
163 |
project name that already exists or is importable in the current environment. |
|
164 |
See https://github.com/Pylons/pyramid/issues/1357 and |
|
165 |
https://github.com/Pylons/pyramid/pull/1837 |
bfe000
|
166 |
|
CM |
167 |
- Add :func:`pyramid.request.apply_request_extensions` function which can be |
|
168 |
used in testing to apply any request extensions configured via |
|
169 |
``config.add_request_method``. Previously it was only possible to test the |
555838
|
170 |
extensions by going through Pyramid's router. See |
bfe000
|
171 |
https://github.com/Pylons/pyramid/pull/1581 |
CM |
172 |
|
|
173 |
- Make it possible to subclass ``pyramid.request.Request`` and also use |
555838
|
174 |
``pyramid.request.Request.add_request.method``. See |
bfe000
|
175 |
https://github.com/Pylons/pyramid/issues/1529 |
555838
|
176 |
|
MM |
177 |
- Additional shells for ``pshell`` can now be registered as entry points. See |
|
178 |
https://github.com/Pylons/pyramid/pull/1891 and |
|
179 |
https://github.com/Pylons/pyramid/pull/2012 |
|
180 |
|
|
181 |
- The variables injected into ``pshell`` are now displayed with their |
|
182 |
docstrings instead of the default ``str(obj)`` when possible. See |
|
183 |
https://github.com/Pylons/pyramid/pull/1929 |
|
184 |
|
bfe000
|
185 |
|
CM |
186 |
Deprecations |
|
187 |
------------ |
|
188 |
|
555838
|
189 |
- The ``pserve`` command's daemonization features, as well as |
MM |
190 |
``--monitor-restart``, have been deprecated. This includes the |
|
191 |
``[start,stop,restart,status]`` subcommands, as well as the ``--daemon``, |
|
192 |
``--stop-daemon``, ``--pid-file``, ``--status``, ``--user``, and ``--group`` |
|
193 |
flags. See https://github.com/Pylons/pyramid/pull/2120 and |
|
194 |
https://github.com/Pylons/pyramid/pull/2189 and |
|
195 |
https://github.com/Pylons/pyramid/pull/1641 |
|
196 |
|
|
197 |
Please use a real process manager in the future instead of relying on |
|
198 |
``pserve`` to daemonize itself. Many options exist, including your operating |
|
199 |
system's services, such as Systemd or Upstart, as well as Python-based |
|
200 |
solutions like Circus and Supervisor. |
|
201 |
|
|
202 |
See https://github.com/Pylons/pyramid/pull/1641 and |
|
203 |
https://github.com/Pylons/pyramid/pull/2120 |
|
204 |
|
bfe000
|
205 |
- The ``principal`` argument to :func:`pyramid.security.remember` was renamed |
555838
|
206 |
to ``userid``. Using ``principal`` as the argument name still works and will |
bfe000
|
207 |
continue to work for the next few releases, but a deprecation warning is |
CM |
208 |
printed. |
|
209 |
|
|
210 |
|
|
211 |
Scaffolding Enhancements |
|
212 |
------------------------ |
|
213 |
|
|
214 |
- Added line numbers to the log formatters in the scaffolds to assist with |
|
215 |
debugging. See https://github.com/Pylons/pyramid/pull/1326 |
|
216 |
|
555838
|
217 |
- Updated scaffold generating machinery to return the version of :app:`Pyramid` |
MM |
218 |
and its documentation for use in scaffolds. Updated ``starter``, ``alchemy`` |
|
219 |
and ``zodb`` templates to have links to correctly versioned documentation, |
|
220 |
and to reflect which :app:`Pyramid` was used to generate the scaffold. |
978135
|
221 |
|
555838
|
222 |
- Removed non-ASCII copyright symbol from templates, as this was causing the |
MM |
223 |
scaffolds to fail for project generation. |
|
224 |
|
978135
|
225 |
|
CM |
226 |
Documentation Enhancements |
|
227 |
-------------------------- |
|
228 |
|
555838
|
229 |
- Removed logging configuration from Quick Tutorial ``ini`` files, except for |
MM |
230 |
scaffolding- and logging-related chapters, to avoid needing to explain it too |
978135
|
231 |
early. |
CM |
232 |
|
555838
|
233 |
- Improve and clarify the documentation on what :app:`Pyramid` defines as a |
MM |
234 |
``principal`` and a ``userid`` in its security APIs. See |
|
235 |
https://github.com/Pylons/pyramid/pull/1399 |
|
236 |
|
|
237 |
- Moved the documentation for ``accept`` on |
|
238 |
:meth:`pyramid.config.Configurator.add_view` to no longer be part of the |
|
239 |
predicate list. See https://github.com/Pylons/pyramid/issues/1391 for a bug |
|
240 |
report stating ``not_`` was failing on ``accept``. Discussion with @mcdonc |
|
241 |
led to the conclusion that it should not be documented as a predicate. |
|
242 |
See https://github.com/Pylons/pyramid/pull/1487 for this PR. |
|
243 |
|
|
244 |
- Clarify a previously-implied detail of the ``ISession.invalidate`` API |
|
245 |
documentation. |
|
246 |
|
|
247 |
- Add documentation of command line programs (``p*`` scripts). See |
|
248 |
https://github.com/Pylons/pyramid/pull/2191 |