Skip to content

Commit 49f29eb

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 48ac250 commit 49f29eb

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

debug_toolbar/panels/profiling.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import cProfile
22
import os
3+
import tempfile
34
from colorsys import hsv_to_rgb
45
from pstats import Stats
5-
import tempfile
66

77
from django.conf import settings
88
from django.utils.html import format_html
@@ -169,9 +169,11 @@ def generate_stats(self, request, response):
169169
self.stats = Stats(self.profiler)
170170
self.stats.calc_callees()
171171

172-
prof_file_path = os.path.join(tempfile.gettempdir(), next(tempfile._get_candidate_names()) + ".prof")
172+
prof_file_path = os.path.join(
173+
tempfile.gettempdir(), next(tempfile._get_candidate_names()) + ".prof"
174+
)
173175
self.profiler.dump_stats(prof_file_path)
174-
self.prof_file_path = prof_file_path
176+
self.prof_file_path = prof_file_path
175177

176178
root_func = cProfile.label(super().process_request.__code__)
177179
if root_func in self.stats.stats:
@@ -186,9 +188,6 @@ def generate_stats(self, request, response):
186188
dt_settings.get_config()["PROFILER_MAX_DEPTH"],
187189
cum_time_threshold,
188190
)
189-
self.record_stats({
190-
"func_list": func_list,
191-
"prof_file_path": self.prof_file_path
192-
})
193-
194-
191+
self.record_stats(
192+
{"func_list": func_list, "prof_file_path": self.prof_file_path}
193+
)

debug_toolbar/panels/sql/tracking.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ def _last_executed_query(self, sql, params):
143143
self.db._djdt_logger = None
144144
try:
145145
# Handle executemany: take the first set of parameters for formatting
146-
if isinstance(params, (list, tuple)) and len(params) > 0 and isinstance(params[0], (list, tuple)):
146+
if (
147+
isinstance(params, (list, tuple))
148+
and len(params) > 0
149+
and isinstance(params[0], (list, tuple))
150+
):
147151
sample_params = params[0]
148152
else:
149153
sample_params = params

debug_toolbar/urls.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from django.urls import path
2-
from debug_toolbar import APP_NAME
3-
from debug_toolbar import views as debug_toolbar_views
2+
3+
from debug_toolbar import APP_NAME, views as debug_toolbar_views
44
from debug_toolbar.toolbar import DebugToolbar
5-
from debug_toolbar import APP_NAME
65

76
app_name = APP_NAME
87

98
urlpatterns = DebugToolbar.get_urls() + [
109
path(
1110
"download_prof_file/",
12-
debug_toolbar_views.download_prof_file,
13-
name="debug_toolbar_download_prof_file"
11+
debug_toolbar_views.download_prof_file,
12+
name="debug_toolbar_download_prof_file",
1413
),
1514
]

debug_toolbar/views.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
2-
from django.http import JsonResponse, FileResponse, Http404
2+
3+
from django.http import FileResponse, Http404, JsonResponse
34
from django.utils.html import escape
45
from django.utils.translation import gettext as _
5-
66
from django.views.decorators.http import require_GET
77

88
from debug_toolbar._compat import login_not_required
@@ -33,12 +33,15 @@ def render_panel(request):
3333
@require_GET
3434
def download_prof_file(request):
3535
file_path = request.GET.get("path")
36-
print("Serving .prof file:", file_path)
36+
print("Serving .prof file:", file_path)
3737
if not file_path or not os.path.exists(file_path):
38-
print("File does not exist:", file_path)
38+
print("File does not exist:", file_path)
3939
raise Http404("File not found.")
4040

41-
response = FileResponse(open(file_path, 'rb'), content_type='application/octet-stream')
42-
response['Content-Disposition'] = f'attachment; filename="{os.path.basename(file_path)}"'
41+
response = FileResponse(
42+
open(file_path, "rb"), content_type="application/octet-stream"
43+
)
44+
response["Content-Disposition"] = (
45+
f'attachment; filename="{os.path.basename(file_path)}"'
46+
)
4347
return response
44-

0 commit comments

Comments
 (0)