Skip to content

Commit 6d3eb44

Browse files
Utilize pre-commit to help devs follow style guidelines (#1495)
* Utilize pre-commit to enforce style guidelines. * Fix blanket noqa statements. * Fix doc8 linting issues. * Fix prettier types. * Removing F401 violations.
1 parent 3ed59cb commit 6d3eb44

File tree

31 files changed

+132
-59
lines changed

31 files changed

+132
-59
lines changed

.pre-commit-config.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: mixed-line-ending
9+
- repo: https://github.com/pycqa/flake8
10+
rev: 3.9.2
11+
hooks:
12+
- id: flake8
13+
- repo: https://github.com/pycqa/doc8
14+
rev: 0.9.0
15+
hooks:
16+
- id: doc8
17+
- repo: https://github.com/pycqa/isort
18+
rev: 5.9.3
19+
hooks:
20+
- id: isort
21+
- repo: https://github.com/pre-commit/pygrep-hooks
22+
rev: v1.9.0
23+
hooks:
24+
- id: python-check-blanket-noqa
25+
- id: python-check-mock-methods
26+
- id: python-no-eval
27+
- id: python-no-log-warn
28+
- id: rst-backticks
29+
- id: rst-directive-colons
30+
- repo: https://github.com/pre-commit/mirrors-prettier
31+
rev: v2.3.2
32+
hooks:
33+
- id: prettier
34+
types_or: [javascript, css]
35+
- repo: https://github.com/pre-commit/mirrors-eslint
36+
rev: v8.0.0-beta.0
37+
hooks:
38+
- id: eslint
39+
files: \.js?$
40+
types: [file]
41+
- repo: https://github.com/psf/black
42+
rev: 21.7b0
43+
hooks:
44+
- id: black
45+
language_version: python3
46+
entry: black --target-version=py36

.tx/config

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ lang_map = sr@latin:sr_Latn
66
file_filter = debug_toolbar/locale/<lang>/LC_MESSAGES/django.po
77
source_file = debug_toolbar/locale/en/LC_MESSAGES/django.po
88
source_lang = en
9-

LICENSE

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ All rights reserved.
44
Redistribution and use in source and binary forms, with or without modification,
55
are permitted provided that the following conditions are met:
66

7-
1. Redistributions of source code must retain the above copyright notice,
7+
1. Redistributions of source code must retain the above copyright notice,
88
this list of conditions and the following disclaimer.
9-
10-
2. Redistributions in binary form must reproduce the above copyright
9+
10+
2. Redistributions in binary form must reproduce the above copyright
1111
notice, this list of conditions and the following disclaimer in the
1212
documentation and/or other materials provided with the distribution.
1313

debug_toolbar/locale/ca/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Libre El Chaval <el.libre@gmail.com>, 2013
77
msgid ""

debug_toolbar/locale/cs/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Vlada Macek <macek@sandbox.cz>, 2013
77
msgid ""

debug_toolbar/locale/de/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Jannis Leidel <jannis@leidel.info>, 2012-2013
77
msgid ""

debug_toolbar/locale/en/LC_MESSAGES/django.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: Django Debug Toolbar\n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2021-08-14 10:25-0500\n"
9+
"POT-Creation-Date: 2021-08-23 19:54-0500\n"
1010
"PO-Revision-Date: 2012-03-31 20:10+0000\n"
1111
"Last-Translator: \n"
1212
"Language-Team: \n"

debug_toolbar/locale/es/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# jcatalan <catalanojuan@gmail.com>, 2014
77
# Leonardo J. Caballero G. <leonardocaballero@gmail.com>, 2013-2014

debug_toolbar/locale/fi/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# nanook <klaus.dahlen@gmail.com>, 2012
77
msgid ""

debug_toolbar/locale/fr/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Pingax <pingax@frugalware.org>, 2013
77
# claudep <claude@2xlibre.net>, 2013

debug_toolbar/locale/he/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# shaib <shai@platonix.com>, 2012
77
msgid ""

debug_toolbar/locale/id/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Muhammad Panji <sumodirjo@gmail.com>, 2012
77
msgid ""

debug_toolbar/locale/nl/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Ingo Berben <ingoberben@gmail.com>, 2012-2013
77
msgid ""

debug_toolbar/locale/pl/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Konrad Mosoń <mosonkonrad@gmail.com>, 2013
77
msgid ""

debug_toolbar/locale/pt/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# joseduraes <jdmduraes@gmail.com>, 2014
77
msgid ""

debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Fábio <bnafta@gmail.com>, 2013-2014
77
# Percy Pérez-Pinedo, 2009

debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Alex Nordlund <deep.alexander@gmail.com>, 2012-2013
77
# Alex Nordlund <deep.alexander@gmail.com>, 2012

debug_toolbar/locale/uk/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# Sergey Lysach <sergikoff88@gmail.com>, 2013
77
msgid ""

debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22
# This file is distributed under the same license as the PACKAGE package.
3-
#
4-
#
3+
#
4+
#
55
# Translators:
66
# mozillazg <opensource.mozillazg@gmail.com>, 2013-2014
77
msgid ""

debug_toolbar/management/commands/debugsqlshell.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import django
44
import sqlparse
5-
from django.core.management.commands.shell import Command # noqa
5+
from django.core.management.commands.shell import Command
66
from django.db import connection
77

88
if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0):
@@ -13,6 +13,11 @@
1313
# 'debugsqlshell' is the same as the 'shell'.
1414

1515

16+
# Command is required to exist to be loaded via
17+
# django.core.managementload_command_class
18+
__all__ = ["Command", "PrintQueryWrapper"]
19+
20+
1621
class PrintQueryWrapper(base_module.CursorDebugWrapper):
1722
def execute(self, sql, params=()):
1823
start_time = time()

debug_toolbar/panels/cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def clear(self, *args, **kwargs):
109109
def has_key(self, *args, **kwargs):
110110
# Ignore flake8 rules for has_key since we need to support caches
111111
# that may be using has_key.
112-
return self.cache.has_key(*args, **kwargs) # noqa
112+
return self.cache.has_key(*args, **kwargs) # noqa: W601
113113

114114
@send_signal
115115
def incr(self, *args, **kwargs):
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from debug_toolbar.panels.history.panel import HistoryPanel # noqa
1+
from debug_toolbar.panels.history.panel import HistoryPanel
2+
3+
__all__ = ["HistoryPanel"]

debug_toolbar/panels/sql/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from debug_toolbar.panels.sql.panel import SQLPanel # noqa
1+
from debug_toolbar.panels.sql.panel import SQLPanel
2+
3+
__all__ = ["SQLPanel"]
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from debug_toolbar.panels.templates.panel import TemplatesPanel # noqa
1+
from debug_toolbar.panels.templates.panel import TemplatesPanel
2+
3+
__all__ = ["TemplatesPanel"]

docs/changes.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ This version is compatible with Django 1.9 and requires Django 1.7 or later.
371371
New features
372372
~~~~~~~~~~~~
373373

374-
* New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows panels
375-
to only record stats when the toolbar is going to be inserted into the
376-
response.
374+
* New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows
375+
panels to only record stats when the toolbar is going to be inserted into
376+
the response.
377377

378378
Bug fixes
379379
~~~~~~~~~

docs/configuration.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ Panel options
201201

202202
**Without grouping**::
203203

204-
SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name"
204+
SELECT
205+
"auth_user"."id", "auth_user"."password", "auth_user"."last_login",
206+
"auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name",
207+
"auth_user"."last_name"
205208
FROM "auth_user"
206209
WHERE "auth_user"."username" = '''test_username'''
207210
LIMIT 21

docs/contributing.rst

+11-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ or by setting the ``DJANGO_SELENIUM_TESTS`` environment variable::
7979
$ DJANGO_SELENIUM_TESTS=true make coverage
8080
$ DJANGO_SELENIUM_TESTS=true tox
8181

82-
To test via `tox` against other databases, you'll need to create the user,
83-
database and assign the proper permissions. For PostgreSQL in a `psql`
82+
To test via ``tox`` against other databases, you'll need to create the user,
83+
database and assign the proper permissions. For PostgreSQL in a ``psql``
8484
shell (note this allows the debug_toolbar user the permission to create
8585
databases)::
8686

@@ -89,7 +89,7 @@ databases)::
8989
psql> CREATE DATABASE debug_toolbar;
9090
psql> GRANT ALL PRIVILEGES ON DATABASE debug_toolbar to debug_toolbar;
9191

92-
For MySQL/MariaDB in a `mysql` shell::
92+
For MySQL/MariaDB in a ``mysql`` shell::
9393

9494
mysql> CREATE DATABASE debug_toolbar;
9595
mysql> CREATE USER 'debug_toolbar'@'localhost' IDENTIFIED BY 'debug_toolbar';
@@ -101,8 +101,14 @@ Style
101101
-----
102102

103103
The Django Debug Toolbar uses `black <https://github.com/psf/black>`__ to
104-
format code and additionally uses flake8 and isort. You can reformat the code
105-
using::
104+
format code and additionally uses flake8 and isort. The toolbar uses
105+
`pre-commit <https://pre-commit>`__ to automatically apply our style guidelines
106+
when a commit is made. If necessary this can be bypassed using::
107+
108+
$ git commit --no-verify
109+
110+
111+
To reformat the code manually use::
106112

107113
$ make style
108114

docs/panels.rst

+13-7
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ Memcache
220220

221221
URL: https://github.com/ross/memcache-debug-panel
222222

223-
Path: ``memcache_toolbar.panels.memcache.MemcachePanel`` or ``memcache_toolbar.panels.pylibmc.PylibmcPanel``
223+
Path: ``memcache_toolbar.panels.memcache.MemcachePanel`` or
224+
``memcache_toolbar.panels.pylibmc.PylibmcPanel``
224225

225226
This panel tracks memcached usage. It currently supports both the pylibmc and
226227
memcache libraries.
@@ -241,7 +242,8 @@ URL: https://github.com/robinedwards/django-debug-toolbar-neo4j-panel
241242

242243
Path: ``neo4j_panel.Neo4jPanel``
243244

244-
Trace neo4j rest API calls in your Django application, this also works for neo4django and neo4jrestclient, support for py2neo is on its way.
245+
Trace neo4j rest API calls in your Django application, this also works for
246+
neo4django and neo4jrestclient, support for py2neo is on its way.
245247

246248
Pympler
247249
~~~~~~~
@@ -250,7 +252,8 @@ URL: https://pythonhosted.org/Pympler/django.html
250252

251253
Path: ``pympler.panels.MemoryPanel``
252254

253-
Shows process memory information (virtual size, resident set size) and model instances for the current request.
255+
Shows process memory information (virtual size, resident set size) and model
256+
instances for the current request.
254257

255258
Request History
256259
~~~~~~~~~~~~~~~
@@ -259,7 +262,8 @@ URL: https://github.com/djsutho/django-debug-toolbar-request-history
259262

260263
Path: ``ddt_request_history.panels.request_history.RequestHistoryPanel``
261264

262-
Switch between requests to view their stats. Also adds support for viewing stats for AJAX requests.
265+
Switch between requests to view their stats. Also adds support for viewing
266+
stats for AJAX requests.
263267

264268
Requests
265269
~~~~~~~~
@@ -289,8 +293,9 @@ URL: https://github.com/node13h/django-debug-toolbar-template-profiler
289293

290294
Path: ``template_profiler_panel.panels.template.TemplateProfilerPanel``
291295

292-
Shows template render call duration and distribution on the timeline. Lightweight.
293-
Compatible with WSGI servers which reuse threads for multiple requests (Werkzeug).
296+
Shows template render call duration and distribution on the timeline.
297+
Lightweight. Compatible with WSGI servers which reuse threads for multiple
298+
requests (Werkzeug).
294299

295300
Template Timings
296301
~~~~~~~~~~~~~~~~
@@ -317,7 +322,8 @@ URL: https://github.com/giginet/django-debug-toolbar-vcs-info
317322

318323
Path: ``vcs_info_panel.panels.GitInfoPanel``
319324

320-
Displays VCS status (revision, branch, latest commit log and more) of your Django application.
325+
Displays VCS status (revision, branch, latest commit log and more) of your
326+
Django application.
321327

322328
uWSGI Stats
323329
~~~~~~~~~~~

0 commit comments

Comments
 (0)