# HG changeset patch # User Laurent Peuch # Date 1559154547 -7200 # Node ID 30b205676182b2d1fdedd60c1098ad2fe2711bf7 # Parent 74b473f288d536a57dccbfbb7a2873bbd3bde3bb [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 diff -r 74b473f288d5 -r 30b205676182 cubicweb/pyramid/__init__.py --- a/cubicweb/pyramid/__init__.py Wed Oct 23 04:28:45 2019 +0200 +++ b/cubicweb/pyramid/__init__.py Wed May 29 20:29:07 2019 +0200 @@ -33,7 +33,7 @@ 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 @@ :returns: A Pyramid config object """ settings = dict(settings) if settings else {} - settings.update(settings_from_cwconfig(cwconfig)) + settings.update(settings_from_cwconfig(cwconfig, debugtoolbar=debugtoolbar)) config = Configurator(settings=settings) config.registry['cubicweb.config'] = cwconfig config.include('cubicweb.pyramid') + + if debugtoolbar: + config.include("pyramid_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 wsgi_application_from_cwconfig( 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 @@ :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: diff -r 74b473f288d5 -r 30b205676182 cubicweb/pyramid/pyramidctl.py --- a/cubicweb/pyramid/pyramidctl.py Wed Oct 23 04:28:45 2019 +0200 +++ b/cubicweb/pyramid/pyramidctl.py Wed May 29 20:29:07 2019 +0200 @@ -99,6 +99,10 @@ ('debug', {'short': 'D', 'action': 'store_true', 'help': 'Equals to "--debug-mode --reload"'}), + ('toolbar', + {'short': 't', 'action': 'store_true', + 'help': 'Activate the pyramid debug toolbar' + '(the pypi "pyramid_debugtoolbar" package must be installed)'}), ('reload', {'action': 'store_true', 'help': 'Restart the server if any source file is changed'}), @@ -255,10 +259,23 @@ 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']: + try: + 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: " + "https://docs.pylonsproject.org/projects/pyramid_debugtoolbar/en/latest/") + sys.exit(1) + app = wsgi_application_from_cwconfig( cwconfig, profile=self['profile'], profile_output=self['profile-output'], - profile_dump_every=self['profile-dump-every'] + profile_dump_every=self['profile-dump-every'], + debugtoolbar=self['toolbar'] ) host = cwconfig['interface'] diff -r 74b473f288d5 -r 30b205676182 doc/changes/3.27.rst --- a/doc/changes/3.27.rst Wed Oct 23 04:28:45 2019 +0200 +++ b/doc/changes/3.27.rst Wed May 29 20:29:07 2019 +0200 @@ -47,6 +47,8 @@ * 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 ------------------------------