diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2013-08-09 13:51:07 -0400 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2013-08-09 13:51:07 -0400 |
commit | 5a74054661a8dcaa1dc84425daad40e796d54a3a (patch) | |
tree | 925aad0581b8ad9e00885dc2e43a64bf722acac9 | |
parent | fb2cf166aaf5b5af461879ec5b7a46806e8aee45 (diff) | |
download | pecan-5a74054661a8dcaa1dc84425daad40e796d54a3a.tar.gz |
Add a deprecation warning for ``pecan.conf.requestviewer``.
-rw-r--r-- | pecan/__init__.py | 31 | ||||
-rw-r--r-- | pecan/scaffolds/base/+package+/app.py_tmpl | 6 | ||||
-rw-r--r-- | pecan/scaffolds/base/config.py_tmpl | 4 |
3 files changed, 36 insertions, 5 deletions
diff --git a/pecan/__init__.py b/pecan/__init__.py index cf93e05..c294572 100644 --- a/pecan/__init__.py +++ b/pecan/__init__.py @@ -17,6 +17,8 @@ try: except ImportError: from logutils.dictconfig import dictConfig as load_logging_config # noqa +import warnings + __all__ = [ 'make_app', 'load_app', 'Pecan', 'request', 'response', @@ -55,7 +57,22 @@ def make_app(root, **kw): ''' # Pass logging configuration (if it exists) on to the Python logging module logging = kw.get('logging', {}) + debug = kw.get('debug', False) if logging: + if debug: + try: + # + # By default, Python 2.7+ silences DeprecationWarnings. + # However, if conf.app.debug is True, we should probably ensure + # that users see these types of warnings. + # + from logging import captureWarnings + captureWarnings(True) + warnings.simplefilter("default", DeprecationWarning) + except ImportError: + # No captureWarnings on Python 2.6, DeprecationWarnings are on + pass + if isinstance(logging, Config): logging = logging.to_dict() if 'version' not in logging: @@ -80,18 +97,26 @@ def make_app(root, **kw): # When in debug mode, load our exception dumping middleware static_root = kw.get('static_root', None) - debug = kw.get('debug', False) if debug: app = DebugMiddleware(app) # Support for serving static files (for development convenience) if static_root: app = StaticFileMiddleware(app, static_root) + elif static_root: - from warnings import warn - warn( + warnings.warn( "`static_root` is only used when `debug` is True, ignoring", RuntimeWarning ) + if hasattr(conf, 'requestviewer'): + warnings.warn(''.join([ + "`pecan.conf.requestviewer` is deprecated. To apply the ", + "`RequestViewerHook` to your application, add it to ", + "`pecan.conf.app.hooks` or manually in your project's `app.py` ", + "file."]), + DeprecationWarning + ) + return app diff --git a/pecan/scaffolds/base/+package+/app.py_tmpl b/pecan/scaffolds/base/+package+/app.py_tmpl index 098deb4..bf904b6 100644 --- a/pecan/scaffolds/base/+package+/app.py_tmpl +++ b/pecan/scaffolds/base/+package+/app.py_tmpl @@ -7,4 +7,8 @@ def setup_app(config): model.init_model() app_conf = dict(config.app) - return make_app(app_conf.pop('root'), **app_conf) + return make_app( + app_conf.pop('root'), + logging=getattr(config, 'logging', {}), + **app_conf + ) diff --git a/pecan/scaffolds/base/config.py_tmpl b/pecan/scaffolds/base/config.py_tmpl index e37ffb0..16b70f3 100644 --- a/pecan/scaffolds/base/config.py_tmpl +++ b/pecan/scaffolds/base/config.py_tmpl @@ -20,7 +20,9 @@ app = { logging = { 'loggers': { 'root': {'level': 'INFO', 'handlers': ['console']}, - '${package}': {'level': 'DEBUG', 'handlers': ['console']} + '${package}': {'level': 'DEBUG', 'handlers': ['console']}, + 'py.warnings': {'handlers': ['console']}, + '__force_dict__': True }, 'handlers': { 'console': { |