summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkmcclain <mark.mcclain@dreamhost.com>2013-08-09 11:11:44 -0700
committermarkmcclain <mark.mcclain@dreamhost.com>2013-08-09 11:11:44 -0700
commitee7c3544bf2288f1e9cbb81d9609ca742a262ce0 (patch)
treece3acb11f8e98391d93987c259f0a27ccc76e4b0
parentbf2a663f211e9392ffe97fb7026946513bbd8133 (diff)
parent5a74054661a8dcaa1dc84425daad40e796d54a3a (diff)
downloadpecan-ee7c3544bf2288f1e9cbb81d9609ca742a262ce0.tar.gz
Merge pull request #228 from ryanpetrello/next
Add a deprecation warning for ``pecan.conf.requestviewer``.
-rw-r--r--pecan/__init__.py31
-rw-r--r--pecan/scaffolds/base/+package+/app.py_tmpl6
-rw-r--r--pecan/scaffolds/base/config.py_tmpl4
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': {