Skip to content

Commit

Permalink
Merge pull request #4490 from NyanKiyoshi/deps/dev/warn
Browse files Browse the repository at this point in the history
Ensure the debug toolbar is installed
  • Loading branch information
maarcingebala committed Jul 19, 2019
2 parents 70d6690 + 334bc8f commit 2a08e86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 14 additions & 2 deletions saleor/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
import os.path
import warnings

import dj_database_url
import dj_email_url
Expand Down Expand Up @@ -269,8 +270,19 @@ def get_bool_from_env(name, default_value):

ENABLE_DEBUG_TOOLBAR = get_bool_from_env("ENABLE_DEBUG_TOOLBAR", False)
if ENABLE_DEBUG_TOOLBAR:
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
INSTALLED_APPS.append("debug_toolbar")
# Ensure the debug toolbar is actually installed before adding it
try:
__import__("debug_toolbar")
except ImportError as exc:
msg = (
f"{exc} -- Install the missing dependencies by "
f"running `pip install -r requirements_dev.txt`"
)
warnings.warn(msg)
else:
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
INSTALLED_APPS.append("debug_toolbar")

DEBUG_TOOLBAR_PANELS = [
# adds a request history to the debug toolbar
"ddt_request_history.panels.request_history.RequestHistoryPanel",
Expand Down
11 changes: 8 additions & 3 deletions saleor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@
urlpatterns = non_translatable_urlpatterns + i18n_patterns(*translatable_urlpatterns)

if settings.DEBUG:
import debug_toolbar
try:
import debug_toolbar
except ImportError:
"""The debug toolbar was not installed. Ignore the error.
settings.py should already have warned the user about it."""
else:
urlpatterns += [url(r"^__debug__/", include(debug_toolbar.urls))]

urlpatterns += [
url(r"^__debug__/", include(debug_toolbar.urls)),
# static files (images, css, javascript, etc.)
url(r"^static/(?P<path>.*)$", serve),
url(r"^static/(?P<path>.*)$", serve)
] + static("/media/", document_root=settings.MEDIA_ROOT)

if settings.ENABLE_SILK:
Expand Down

0 comments on commit 2a08e86

Please sign in to comment.