diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e451190d4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,46 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending +- repo: https://github.com/pycqa/flake8 + rev: 3.9.2 + hooks: + - id: flake8 +- repo: https://github.com/pycqa/doc8 + rev: 0.9.0 + hooks: + - id: doc8 +- repo: https://github.com/pycqa/isort + rev: 5.9.3 + hooks: + - id: isort +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.9.0 + hooks: + - id: python-check-blanket-noqa + - id: python-check-mock-methods + - id: python-no-eval + - id: python-no-log-warn + - id: rst-backticks + - id: rst-directive-colons +- repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.3.2 + hooks: + - id: prettier + types_or: [javascript, css] +- repo: https://github.com/pre-commit/mirrors-eslint + rev: v8.0.0-beta.0 + hooks: + - id: eslint + files: \.js?$ + types: [file] +- repo: https://github.com/psf/black + rev: 21.7b0 + hooks: + - id: black + language_version: python3 + entry: black --target-version=py36 diff --git a/.tx/config b/.tx/config index bdbb9bf43..5c9ecc129 100644 --- a/.tx/config +++ b/.tx/config @@ -6,4 +6,3 @@ lang_map = sr@latin:sr_Latn file_filter = debug_toolbar/locale//LC_MESSAGES/django.po source_file = debug_toolbar/locale/en/LC_MESSAGES/django.po source_lang = en - diff --git a/LICENSE b/LICENSE index 15d830926..221d73313 100644 --- a/LICENSE +++ b/LICENSE @@ -4,10 +4,10 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. diff --git a/debug_toolbar/locale/ca/LC_MESSAGES/django.po b/debug_toolbar/locale/ca/LC_MESSAGES/django.po index 5de03a115..34e4007da 100644 --- a/debug_toolbar/locale/ca/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/ca/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Libre El Chaval , 2013 msgid "" diff --git a/debug_toolbar/locale/cs/LC_MESSAGES/django.po b/debug_toolbar/locale/cs/LC_MESSAGES/django.po index 26b6cdbdc..abb6a7c22 100644 --- a/debug_toolbar/locale/cs/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/cs/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Vlada Macek , 2013 msgid "" diff --git a/debug_toolbar/locale/de/LC_MESSAGES/django.po b/debug_toolbar/locale/de/LC_MESSAGES/django.po index 6ba6974f3..083a15785 100644 --- a/debug_toolbar/locale/de/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/de/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Jannis Leidel , 2012-2013 msgid "" diff --git a/debug_toolbar/locale/en/LC_MESSAGES/django.po b/debug_toolbar/locale/en/LC_MESSAGES/django.po index b4d0ff233..031208852 100644 --- a/debug_toolbar/locale/en/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/en/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Django Debug Toolbar\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-08-14 10:25-0500\n" +"POT-Creation-Date: 2021-08-23 19:54-0500\n" "PO-Revision-Date: 2012-03-31 20:10+0000\n" "Last-Translator: \n" "Language-Team: \n" diff --git a/debug_toolbar/locale/es/LC_MESSAGES/django.po b/debug_toolbar/locale/es/LC_MESSAGES/django.po index f7d763e1e..d348645e4 100644 --- a/debug_toolbar/locale/es/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/es/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # jcatalan , 2014 # Leonardo J. Caballero G. , 2013-2014 diff --git a/debug_toolbar/locale/fi/LC_MESSAGES/django.po b/debug_toolbar/locale/fi/LC_MESSAGES/django.po index 7e27b07d4..97d8bdcbd 100644 --- a/debug_toolbar/locale/fi/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/fi/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # nanook , 2012 msgid "" diff --git a/debug_toolbar/locale/fr/LC_MESSAGES/django.po b/debug_toolbar/locale/fr/LC_MESSAGES/django.po index 586811144..4ce0574f3 100644 --- a/debug_toolbar/locale/fr/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/fr/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Pingax , 2013 # claudep , 2013 diff --git a/debug_toolbar/locale/he/LC_MESSAGES/django.po b/debug_toolbar/locale/he/LC_MESSAGES/django.po index 66f13742f..2afad7e72 100644 --- a/debug_toolbar/locale/he/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/he/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # shaib , 2012 msgid "" diff --git a/debug_toolbar/locale/id/LC_MESSAGES/django.po b/debug_toolbar/locale/id/LC_MESSAGES/django.po index 8589fb5f6..386fda1ee 100644 --- a/debug_toolbar/locale/id/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/id/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Muhammad Panji , 2012 msgid "" diff --git a/debug_toolbar/locale/nl/LC_MESSAGES/django.po b/debug_toolbar/locale/nl/LC_MESSAGES/django.po index 07b95546b..ccbb4c318 100644 --- a/debug_toolbar/locale/nl/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/nl/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Ingo Berben , 2012-2013 msgid "" diff --git a/debug_toolbar/locale/pl/LC_MESSAGES/django.po b/debug_toolbar/locale/pl/LC_MESSAGES/django.po index 0d674f1aa..2e9942a15 100644 --- a/debug_toolbar/locale/pl/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/pl/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Konrad Mosoń , 2013 msgid "" diff --git a/debug_toolbar/locale/pt/LC_MESSAGES/django.po b/debug_toolbar/locale/pt/LC_MESSAGES/django.po index 038fdec7b..58a793ad0 100644 --- a/debug_toolbar/locale/pt/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/pt/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # joseduraes , 2014 msgid "" diff --git a/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po b/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po index ed25331b6..705dd7fa7 100644 --- a/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Fábio , 2013-2014 # Percy Pérez-Pinedo, 2009 diff --git a/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po b/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po index 0c8b2e897..a29096e6f 100644 --- a/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Alex Nordlund , 2012-2013 # Alex Nordlund , 2012 diff --git a/debug_toolbar/locale/uk/LC_MESSAGES/django.po b/debug_toolbar/locale/uk/LC_MESSAGES/django.po index 9a642f694..11bdf68ff 100644 --- a/debug_toolbar/locale/uk/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/uk/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # Sergey Lysach , 2013 msgid "" diff --git a/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po b/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po index 521d57761..44993f554 100644 --- a/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po +++ b/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po @@ -1,7 +1,7 @@ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. -# -# +# +# # Translators: # mozillazg , 2013-2014 msgid "" diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py index 78e09e27d..ba0f32463 100644 --- a/debug_toolbar/management/commands/debugsqlshell.py +++ b/debug_toolbar/management/commands/debugsqlshell.py @@ -2,7 +2,7 @@ import django import sqlparse -from django.core.management.commands.shell import Command # noqa +from django.core.management.commands.shell import Command from django.db import connection if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0): @@ -13,6 +13,11 @@ # 'debugsqlshell' is the same as the 'shell'. +# Command is required to exist to be loaded via +# django.core.managementload_command_class +__all__ = ["Command", "PrintQueryWrapper"] + + class PrintQueryWrapper(base_module.CursorDebugWrapper): def execute(self, sql, params=()): start_time = time() diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py index 0e8e190e9..0b2af6ee4 100644 --- a/debug_toolbar/panels/cache.py +++ b/debug_toolbar/panels/cache.py @@ -109,7 +109,7 @@ def clear(self, *args, **kwargs): def has_key(self, *args, **kwargs): # Ignore flake8 rules for has_key since we need to support caches # that may be using has_key. - return self.cache.has_key(*args, **kwargs) # noqa + return self.cache.has_key(*args, **kwargs) # noqa: W601 @send_signal def incr(self, *args, **kwargs): diff --git a/debug_toolbar/panels/history/__init__.py b/debug_toolbar/panels/history/__init__.py index 78c876b81..52ceb7984 100644 --- a/debug_toolbar/panels/history/__init__.py +++ b/debug_toolbar/panels/history/__init__.py @@ -1 +1,3 @@ -from debug_toolbar.panels.history.panel import HistoryPanel # noqa +from debug_toolbar.panels.history.panel import HistoryPanel + +__all__ = ["HistoryPanel"] diff --git a/debug_toolbar/panels/sql/__init__.py b/debug_toolbar/panels/sql/__init__.py index a4f9cd4bf..46c68a3c6 100644 --- a/debug_toolbar/panels/sql/__init__.py +++ b/debug_toolbar/panels/sql/__init__.py @@ -1 +1,3 @@ -from debug_toolbar.panels.sql.panel import SQLPanel # noqa +from debug_toolbar.panels.sql.panel import SQLPanel + +__all__ = ["SQLPanel"] diff --git a/debug_toolbar/panels/templates/__init__.py b/debug_toolbar/panels/templates/__init__.py index 1f768f57b..a1d509b9e 100644 --- a/debug_toolbar/panels/templates/__init__.py +++ b/debug_toolbar/panels/templates/__init__.py @@ -1 +1,3 @@ -from debug_toolbar.panels.templates.panel import TemplatesPanel # noqa +from debug_toolbar.panels.templates.panel import TemplatesPanel + +__all__ = ["TemplatesPanel"] diff --git a/docs/changes.rst b/docs/changes.rst index 1a322752e..7dd52713c 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -371,9 +371,9 @@ This version is compatible with Django 1.9 and requires Django 1.7 or later. New features ~~~~~~~~~~~~ -* New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows panels - to only record stats when the toolbar is going to be inserted into the - response. +* New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows + panels to only record stats when the toolbar is going to be inserted into + the response. Bug fixes ~~~~~~~~~ diff --git a/docs/configuration.rst b/docs/configuration.rst index 0d7cd87c4..96758d89c 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -201,7 +201,10 @@ Panel options **Without grouping**:: - 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" + 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" FROM "auth_user" WHERE "auth_user"."username" = '''test_username''' LIMIT 21 diff --git a/docs/contributing.rst b/docs/contributing.rst index 245159a52..cbb147002 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -79,8 +79,8 @@ or by setting the ``DJANGO_SELENIUM_TESTS`` environment variable:: $ DJANGO_SELENIUM_TESTS=true make coverage $ DJANGO_SELENIUM_TESTS=true tox -To test via `tox` against other databases, you'll need to create the user, -database and assign the proper permissions. For PostgreSQL in a `psql` +To test via ``tox`` against other databases, you'll need to create the user, +database and assign the proper permissions. For PostgreSQL in a ``psql`` shell (note this allows the debug_toolbar user the permission to create databases):: @@ -89,7 +89,7 @@ databases):: psql> CREATE DATABASE debug_toolbar; psql> GRANT ALL PRIVILEGES ON DATABASE debug_toolbar to debug_toolbar; -For MySQL/MariaDB in a `mysql` shell:: +For MySQL/MariaDB in a ``mysql`` shell:: mysql> CREATE DATABASE debug_toolbar; mysql> CREATE USER 'debug_toolbar'@'localhost' IDENTIFIED BY 'debug_toolbar'; @@ -101,8 +101,14 @@ Style ----- The Django Debug Toolbar uses `black `__ to -format code and additionally uses flake8 and isort. You can reformat the code -using:: +format code and additionally uses flake8 and isort. The toolbar uses +`pre-commit `__ to automatically apply our style guidelines +when a commit is made. If necessary this can be bypassed using:: + + $ git commit --no-verify + + +To reformat the code manually use:: $ make style diff --git a/docs/panels.rst b/docs/panels.rst index a836054ed..b555b92d5 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -220,7 +220,8 @@ Memcache URL: https://github.com/ross/memcache-debug-panel -Path: ``memcache_toolbar.panels.memcache.MemcachePanel`` or ``memcache_toolbar.panels.pylibmc.PylibmcPanel`` +Path: ``memcache_toolbar.panels.memcache.MemcachePanel`` or +``memcache_toolbar.panels.pylibmc.PylibmcPanel`` This panel tracks memcached usage. It currently supports both the pylibmc and memcache libraries. @@ -241,7 +242,8 @@ URL: https://github.com/robinedwards/django-debug-toolbar-neo4j-panel Path: ``neo4j_panel.Neo4jPanel`` -Trace neo4j rest API calls in your Django application, this also works for neo4django and neo4jrestclient, support for py2neo is on its way. +Trace neo4j rest API calls in your Django application, this also works for +neo4django and neo4jrestclient, support for py2neo is on its way. Pympler ~~~~~~~ @@ -250,7 +252,8 @@ URL: https://pythonhosted.org/Pympler/django.html Path: ``pympler.panels.MemoryPanel`` -Shows process memory information (virtual size, resident set size) and model instances for the current request. +Shows process memory information (virtual size, resident set size) and model +instances for the current request. Request History ~~~~~~~~~~~~~~~ @@ -259,7 +262,8 @@ URL: https://github.com/djsutho/django-debug-toolbar-request-history Path: ``ddt_request_history.panels.request_history.RequestHistoryPanel`` -Switch between requests to view their stats. Also adds support for viewing stats for AJAX requests. +Switch between requests to view their stats. Also adds support for viewing +stats for AJAX requests. Requests ~~~~~~~~ @@ -289,8 +293,9 @@ URL: https://github.com/node13h/django-debug-toolbar-template-profiler Path: ``template_profiler_panel.panels.template.TemplateProfilerPanel`` -Shows template render call duration and distribution on the timeline. Lightweight. -Compatible with WSGI servers which reuse threads for multiple requests (Werkzeug). +Shows template render call duration and distribution on the timeline. +Lightweight. Compatible with WSGI servers which reuse threads for multiple +requests (Werkzeug). Template Timings ~~~~~~~~~~~~~~~~ @@ -317,7 +322,8 @@ URL: https://github.com/giginet/django-debug-toolbar-vcs-info Path: ``vcs_info_panel.panels.GitInfoPanel`` -Displays VCS status (revision, branch, latest commit log and more) of your Django application. +Displays VCS status (revision, branch, latest commit log and more) of your +Django application. uWSGI Stats ~~~~~~~~~~~ diff --git a/docs/tips.rst b/docs/tips.rst index f7a31e927..e6957b0c6 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -51,8 +51,9 @@ development. The cache panel is very similar to the SQL panel, except it isn't always a bad practice to make many cache queries in a view. -The template panel becomes slow if your views or context processors return large -contexts and your templates have complex inheritance or inclusion schemes. +The template panel becomes slow if your views or context processors return +large contexts and your templates have complex inheritance or inclusion +schemes. Solutions ~~~~~~~~~ diff --git a/requirements_dev.txt b/requirements_dev.txt index 6010ea4f7..fd82925d9 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -21,5 +21,6 @@ sphinxcontrib-spelling # Other tools +pre-commit transifex-client wheel diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index 08535a79e..6ca241f41 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -273,7 +273,7 @@ def test_insert_locals(self): """ Test that the panel inserts locals() content. """ - local_var = "" # noqa + local_var = "" # noqa: F841 list(User.objects.filter(username="café".encode("utf-8"))) response = self.panel.process_request(self.request) self.panel.generate_stats(self.request, response)