diff options
| -rw-r--r-- | CHANGES.txt | 5 | ||||
| -rw-r--r-- | docs/whatsnew-1.1.rst | 5 | ||||
| -rw-r--r-- | pyramid/config.py | 20 | ||||
| -rw-r--r-- | pyramid/tests/test_config.py | 5 | ||||
| -rw-r--r-- | pyramid/tests/venusianapp/__init__.py | 14 |
5 files changed, 47 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 0eb02baad..041ff0bb7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,11 @@ Next release Features -------- +- The ``config.scan`` method has grown a ``**kw`` argument. ``kw`` argument + represents a set of keyword arguments to pass to the Venusian ``Scanner`` + object created by Pyramid. (See the Venusian documentation for more + information about ``Scanner``). + - New request attribute: ``json``. If the request's ``content_type`` is ``application/json``, this attribute will contain the JSON-decoded variant of the request body. If the request's ``content_type`` is not diff --git a/docs/whatsnew-1.1.rst b/docs/whatsnew-1.1.rst index fdf3b1c74..a6bb8e99d 100644 --- a/docs/whatsnew-1.1.rst +++ b/docs/whatsnew-1.1.rst @@ -94,6 +94,11 @@ Default HTTP Exception View Minor Feature Additions ----------------------- +- The :meth:`pyramid.config.Configurator.scan` method has grown a ``**kw`` + argument. ``kw`` argument represents a set of keyword arguments to pass to + the Venusian ``Scanner`` object created by Pyramid. (See the + :term:`Venusian` documentation for more information about ``Scanner``). + - New request attribute: ``json``. If the request's ``content_type`` is ``application/json``, this attribute will contain the JSON-decoded variant of the request body. If the request's ``content_type`` is not diff --git a/pyramid/config.py b/pyramid/config.py index 3ad872e27..2a1a179e5 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -1950,7 +1950,7 @@ class Configurator(object): return mapper # this is *not* an action method (uses caller_package) - def scan(self, package=None, categories=None): + def scan(self, package=None, categories=None, **kw): """Scan a Python package and any of its subpackages for objects marked with :term:`configuration decoration` such as :class:`pyramid.view.view_config`. Any decorated object found will @@ -1970,12 +1970,28 @@ class Configurator(object): :class:`pyramid.view.view_config`. See the :term:`Venusian` documentation for more information about limiting a scan by using an explicit set of categories. + + To perform a ``scan``, Pyramid creates a Venusian ``Scanner`` object. + The ``kw`` argument represents a set of keyword arguments to pass to + the Venusian ``Scanner`` object's constructor. See the + :term:`venusian` documentation (its ``Scanner`` class) for more + information. By default, the only keyword arguments passed to the + Scanner constructor are ``{'config':self}`` where ``self`` is this + configurator object. This services the requirement of all built-in + Pyramid decorators, but extension systems may require additional + arguments. Providing this argument is not often necessary; it's an + advanced usage. + + .. note:: the ``**kw`` argument is new in Pyramid 1.1 """ package = self.maybe_dotted(package) if package is None: # pragma: no cover package = caller_package() - scanner = self.venusian.Scanner(config=self) + scankw = {'config':self} + scankw.update(kw) + + scanner = self.venusian.Scanner(**scankw) scanner.scan(package, categories=categories) @action_method diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py index fa1ad2b88..45b5b25f1 100644 --- a/pyramid/tests/test_config.py +++ b/pyramid/tests/test_config.py @@ -2848,6 +2848,11 @@ class ConfiguratorTests(unittest.TestCase): result = render_view_to_response(ctx, req, '') self.assertEqual(result, 'grokked') + def test_scan_integration_with_extra_kw(self): + config = self._makeOne(autocommit=True) + config.scan('pyramid.tests.venusianapp', a=1) + self.assertEqual(config.a, 1) + def test_testing_securitypolicy(self): from pyramid.testing import DummySecurityPolicy config = self._makeOne(autocommit=True) diff --git a/pyramid/tests/venusianapp/__init__.py b/pyramid/tests/venusianapp/__init__.py new file mode 100644 index 000000000..ce5e07238 --- /dev/null +++ b/pyramid/tests/venusianapp/__init__.py @@ -0,0 +1,14 @@ +import venusian + +def foo(wrapped): + def bar(scanner, name, wrapped): + scanner.config.a = scanner.a + venusian.attach(wrapped, bar) + return wrapped + +@foo +def hello(): + pass + +hello() # appease coverage + |
