# HG changeset patch # User Laurent Peuch # Date 1575391468 -3600 # Node ID a073ebcb651819adc92cd3e8fd9c96e55a2adf5f # Parent 6086f3d503a5729f67bc381622175e961a28ebad [debug-toolbar/fix] only import mako when the toolbar is loaded diff -r 6086f3d503a5 -r a073ebcb6518 cubicweb/pyramid/__init__.py --- a/cubicweb/pyramid/__init__.py Wed Dec 04 16:12:15 2019 +0100 +++ b/cubicweb/pyramid/__init__.py Tue Dec 03 17:44:28 2019 +0100 @@ -20,7 +20,9 @@ """Pyramid interface to CubicWeb""" +import sys import atexit +import logging from configparser import ConfigParser import os import warnings @@ -28,10 +30,6 @@ import wsgicors from cubicweb.cwconfig import CubicWebConfiguration as cwcfg -from cubicweb.pyramid.debug_source_code import ( - debug_display_source_code, - DEBUG_DISPLAY_SOURCE_CODE_PATH, -) from pyramid.config import Configurator from pyramid.exceptions import ConfigurationError @@ -116,8 +114,19 @@ config.scan('cubicweb.pyramid.profile') if debugtoolbar: - config.add_route('debug_display_source_code', DEBUG_DISPLAY_SOURCE_CODE_PATH) - config.add_view(debug_display_source_code, route_name='debug_display_source_code') + try: + from cubicweb.pyramid.debug_source_code import ( + debug_display_source_code, + DEBUG_DISPLAY_SOURCE_CODE_PATH, + ) + except ImportError as e: + logging.exception("Error: you tried to activate the debug toolbar but you have missing " + "dependencies: %s" % e) + + sys.exit(1) + else: + config.add_route('debug_display_source_code', DEBUG_DISPLAY_SOURCE_CODE_PATH) + config.add_view(debug_display_source_code, route_name='debug_display_source_code') app = config.make_wsgi_app() # This replaces completely web/cors.py, which is not used by