Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify the default scan categories to be limited to only 'pyramid' #3510

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ Backward Incompatibilities
by the default execution policy.
See https://github.com/Pylons/pyramid/pull/3496

- ``pyramid.config.Configurator.scan`` will no longer, by default, execute
Venusian decorator callbacks registered for categories other than
``'pyramid'``. To find any decorator regardless of category, specify
``config.scan(..., categories=None)``.
See https://github.com/Pylons/pyramid/pull/3510

Documentation Changes
---------------------

Expand Down
23 changes: 16 additions & 7 deletions src/pyramid/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,12 @@ def __exit__(self, exc_type, exc_value, exc_traceback):

# this is *not* an action method (uses caller_package)
def scan(
self, package=None, categories=None, onerror=None, ignore=None, **kw
self,
package=None,
categories=('pyramid',),
onerror=None,
ignore=None,
**kw
):
"""Scan a Python package and any of its subpackages for objects
marked with :term:`configuration decoration` such as
Expand All @@ -820,12 +825,12 @@ def scan(
The ``categories`` argument, if provided, should be the
:term:`Venusian` 'scan categories' to use during scanning. Providing
this argument is not often necessary; specifying scan categories is
an extremely advanced usage. By default, ``categories`` is ``None``
which will execute *all* Venusian decorator callbacks including
:app:`Pyramid`-related decorators such as
:class:`pyramid.view.view_config`. See the :term:`Venusian`
documentation for more information about limiting a scan by using an
explicit set of categories.
an extremely advanced usage. By default, ``categories`` is
``['pyramid']`` which will execute only :app:`Pyramid`-related Venusian
decorator callbacks such as from :class:`pyramid.view.view_config`.
See the :term:`Venusian` documentation for more information about
limiting a scan by using an explicit set of categories. Pass ``None``
to pick up *all* Venusian decorators.

The ``onerror`` argument, if provided, should be a Venusian
``onerror`` callback function. The onerror function is passed to
Expand Down Expand Up @@ -863,6 +868,10 @@ def scan(
.. versionadded:: 1.3
The ``ignore`` argument.

.. versionchanged:: 2.0
The ``categories`` argument now defaults to ``['pyramid']`` instead
of ``None`` to control which decorator callbacks are executed.

"""
package = self.maybe_dotted(package)
if package is None: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def test_scan_integration_dottedname_package(self):

def test_scan_integration_with_extra_kw(self):
config = self._makeOne(autocommit=True)
config.scan('tests.test_config.pkgs.scanextrakw', a=1)
config.scan('tests.test_config.pkgs.scanextrakw', a=1, categories=None)
self.assertEqual(config.a, 1)

def test_scan_integration_with_onerror(self):
Expand Down