Commit 3b5d1df5 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[pyramid/ctl] add a new option to activate the debugtoolbar (-t)

While this toolbar isn't yet very integrated with CW, it integrates an inline
debugging shell like werkzeug for flask or django_extensions which greatly
helps debugging on exception.

It can already be manually activated by writting "pyramid.includes =
pyramid_debugtoolbar" but it's hidden somewhere in the documentation and not
very accessible and annoying to do.

Closes #17219765
parent 74b473f288d5
......@@ -33,7 +33,7 @@ from pyramid.exceptions import ConfigurationError
from pyramid.settings import asbool, aslist
def config_from_cwconfig(cwconfig, settings=None):
def config_from_cwconfig(cwconfig, settings=None, debugtoolbar=False):
"""Return a Pyramid Configurator instance built from a CubicWeb config and
Pyramid-specific configuration files (pyramid.ini).
......@@ -41,14 +41,18 @@ def config_from_cwconfig(cwconfig, settings=None):
:returns: A Pyramid config object
settings = dict(settings) if settings else {}
settings.update(settings_from_cwconfig(cwconfig, debugtoolbar=debugtoolbar))
config = Configurator(settings=settings)
config.registry['cubicweb.config'] = cwconfig
if debugtoolbar:
return config
def settings_from_cwconfig(cwconfig):
def settings_from_cwconfig(cwconfig, debugtoolbar=False):
Extract settings from pyramid.ini and pyramid-debug.ini (if in debug)
......@@ -82,7 +86,7 @@ def settings_from_cwconfig(cwconfig):
def wsgi_application_from_cwconfig(
profile=False, profile_output=None, profile_dump_every=None):
profile=False, profile_output=None, profile_dump_every=None, debugtoolbar=False):
""" Build a WSGI application from a cubicweb configuration
:param cwconfig: A CubicWeb configuration
......@@ -90,10 +94,12 @@ def wsgi_application_from_cwconfig(
:param profile_output: Profiling output filename. See :ref:`profiling`.
:param profile_dump_every: Profiling number of requests before dumping the
stats. See :ref:`profiling`.
:param debugtoolbar: Activate pyramid debugtoolbar when True.
:returns: A fully operationnal WSGI application
config = config_from_cwconfig(cwconfig)
config = config_from_cwconfig(cwconfig, debugtoolbar=debugtoolbar)
profile = profile or asbool(config.registry.settings.get(
'cubicweb.profile.enable', False))
if profile:
......@@ -99,6 +99,10 @@ class PyramidStartHandler(InstanceCommand):
{'short': 'D', 'action': 'store_true',
'help': 'Equals to "--debug-mode --reload"'}),
{'short': 't', 'action': 'store_true',
'help': 'Activate the pyramid debug toolbar'
'(the pypi "pyramid_debugtoolbar" package must be installed)'}),
{'action': 'store_true',
'help': 'Restart the server if any source file is changed'}),
......@@ -255,10 +259,23 @@ class PyramidStartHandler(InstanceCommand):
if self['loglevel'] is None and self['debug']:
init_cmdline_log_threshold(self.cwconfig, 'debug')
# if the debugtoolbar is activated, test if it's importable
if self['toolbar']:
import pyramid_debugtoolbar # noqa
except ImportError:
print("Error: you've tried to activate the pyramid debugtoolbar but it failed to "
"import, make sure it's correctly installed by doing a "
"'pip install pyramid_debugtoolbar'.\nYou can find more information on the "
"official documentation: "
app = wsgi_application_from_cwconfig(
cwconfig, profile=self['profile'],
host = cwconfig['interface']
......@@ -47,6 +47,8 @@ New features
* on DBG_SQL and/or DBG_RQL, if pygments is installed, syntax highlight sql/rql
debug output
* add a new '-t/--toolbar' option the pyramid command to activate the pyramid debugtoolbar
Backwards incompatible changes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment