From 8391469f4d826b802bdfbe2e7f41491ebd75e46e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 17:31:19 +0000 Subject: [PATCH 1/7] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/adamchainz/django-upgrade: 1.16.0 → 1.17.0](https://github.com/adamchainz/django-upgrade/compare/1.16.0...1.17.0) - [github.com/pre-commit/mirrors-eslint: v9.0.0 → v9.3.0](https://github.com/pre-commit/mirrors-eslint/compare/v9.0.0...v9.3.0) - [github.com/astral-sh/ruff-pre-commit: v0.3.7 → v0.4.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.7...v0.4.4) - [github.com/tox-dev/pyproject-fmt: 1.7.0 → 2.1.1](https://github.com/tox-dev/pyproject-fmt/compare/1.7.0...2.1.1) - [github.com/abravalheri/validate-pyproject: v0.16 → v0.18](https://github.com/abravalheri/validate-pyproject/compare/v0.16...v0.18) --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1eb0a7df1..0845df6e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: hooks: - id: doc8 - repo: https://github.com/adamchainz/django-upgrade - rev: 1.16.0 + rev: 1.17.0 hooks: - id: django-upgrade args: [--target-version, "4.2"] @@ -32,7 +32,7 @@ repos: args: - --trailing-comma=es5 - repo: https://github.com/pre-commit/mirrors-eslint - rev: v9.0.0 + rev: v9.3.0 hooks: - id: eslint additional_dependencies: @@ -44,16 +44,16 @@ repos: args: - --fix - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.3.7' + rev: 'v0.4.4' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.7.0 + rev: 2.1.1 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.16 + rev: v0.18 hooks: - id: validate-pyproject From 2990290d43618df5eab357f2a36363186d51d5a8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 17:31:35 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- debug_toolbar/panels/templates/panel.py | 2 +- pyproject.toml | 49 ++++++++++++------------- tests/panels/test_sql.py | 2 +- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index c0c6246b2..81d7e5fad 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -158,7 +158,7 @@ def process_context_list(self, context_layers): f"<<{value.__class__.__name__.lower()} of {value.model._meta.label}>>" ) else: - token = allow_sql.set(False) # noqa: FBT003 + token = allow_sql.set(False) try: saferepr(value) # this MAY trigger a db query except SQLQueryTriggered: diff --git a/pyproject.toml b/pyproject.toml index 5e8a47516..e76d2ebf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,9 +8,9 @@ requires = [ name = "django-debug-toolbar" description = "A configurable set of panels that display various debug information about the current request/response." readme = "README.rst" -license = {text = "BSD-3-Clause"} +license = { text = "BSD-3-Clause" } authors = [ - { name = "Rob Hudson" }, + { name = "Rob Hudson" }, ] requires-python = ">=3.8" classifiers = [ @@ -35,26 +35,26 @@ dynamic = [ "version", ] dependencies = [ - "Django>=4.2.9", + "django>=4.2.9", "sqlparse>=0.2", ] -[project.urls] -Download = "https://pypi.org/project/django-debug-toolbar/" -Homepage = "https://github.com/jazzband/django-debug-toolbar" +urls.Download = "https://pypi.org/project/django-debug-toolbar/" +urls.Homepage = "https://github.com/jazzband/django-debug-toolbar" [tool.hatch.build.targets.wheel] -packages = ["debug_toolbar"] +packages = [ + "debug_toolbar", +] [tool.hatch.version] path = "debug_toolbar/__init__.py" [tool.ruff] -fix = true -show-fixes = true target-version = "py38" -[tool.ruff.lint] -extend-select = [ +fix = true +show-fixes = true +lint.extend-select = [ "ASYNC", # flake8-async "B", # flake8-bugbear "C4", # flake8-comprehensions @@ -73,23 +73,17 @@ extend-select = [ "UP", # pyupgrade "W", # pycodestyle warnings ] -extend-ignore = [ +lint.extend-ignore = [ "B905", # Allow zip() without strict= "E501", # Ignore line length violations "SIM108", # Use ternary operator instead of if-else-block ] - -[tool.ruff.lint.isort] -combine-as-imports = true - -[tool.ruff.lint.mccabe] -max-complexity = 16 - -[tool.ruff.lint.per-file-ignores] -"*/migrat*/*" = [ - "N806", # Allow using PascalCase model names in migrations - "N999", # Ignore the fact that migration files are invalid module names +lint.per-file-ignores."*/migrat*/*" = [ + "N806", # Allow using PascalCase model names in migrations + "N999", # Ignore the fact that migration files are invalid module names ] +lint.isort.combine-as-imports = true +lint.mccabe.max-complexity = 16 [tool.coverage.html] skip_covered = true @@ -98,10 +92,15 @@ skip_empty = true [tool.coverage.run] branch = true parallel = true -source = ["debug_toolbar"] +source = [ + "debug_toolbar", +] [tool.coverage.paths] -source = ["src", ".tox/*/site-packages"] +source = [ + "src", + ".tox/*/site-packages", +] [tool.coverage.report] # Update coverage badge link in README.rst when fail_under changes diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index 932a0dd92..48c9e3845 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -126,7 +126,7 @@ async def test_cursor_wrapper_asyncio_ctx(self, mock_patch_cursor_wrapper): await sync_to_async(sql_call)() async def task(): - sql_tracking.allow_sql.set(False) # noqa: FBT003 + sql_tracking.allow_sql.set(False) # By disabling sql_tracking.allow_sql, we are indicating that any # future SQL queries should be stopped. If SQL query occurs, # it raises an exception. From e7541abe7a48d8a033f244e490e3d1ad9167fa74 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 10:59:54 +0200 Subject: [PATCH 3/7] Ignore UP031 for now --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index f8c732d7d..6060a055f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,6 +83,7 @@ lint.extend-ignore = [ "B905", # Allow zip() without strict= "E501", # Ignore line length violations "SIM108", # Use ternary operator instead of if-else-block + "UP031", # It's not always wrong to use percent-formatting ] lint.per-file-ignores."*/migrat*/*" = [ "N806", # Allow using PascalCase model names in migrations From 4808addf66281e9af47bbb898f6ba8107fbef77f Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 12:47:08 +0200 Subject: [PATCH 4/7] Avoid setting color-scheme on :root, we're only a guest on pages (#1923) Fixes #1922. --- debug_toolbar/static/debug_toolbar/css/toolbar.css | 3 --- docs/changes.rst | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/css/toolbar.css b/debug_toolbar/static/debug_toolbar/css/toolbar.css index 170cc3d5f..e028a67b7 100644 --- a/debug_toolbar/static/debug_toolbar/css/toolbar.css +++ b/debug_toolbar/static/debug_toolbar/css/toolbar.css @@ -11,7 +11,6 @@ monospace, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; - color-scheme: light; --djdt-font-color: black; --djdt-background-color: white; --djdt-panel-content-background-color: #eee; @@ -35,7 +34,6 @@ @media (prefers-color-scheme: dark) { :root { - color-scheme: dark; --djdt-font-color: #8393a7; --djdt-background-color: #1e293bff; --djdt-panel-content-background-color: #0f1729ff; @@ -58,7 +56,6 @@ } #djDebug[data-theme="dark"] { - color-scheme: dark; --djdt-font-color: #8393a7; --djdt-background-color: #1e293bff; --djdt-panel-content-background-color: #0f1729ff; diff --git a/docs/changes.rst b/docs/changes.rst index 84821c56b..1d66d1323 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,8 @@ Change log Pending ------- +* Removed some CSS which wasn't carefully limited to the toolbar's elements. + 4.4.1 (2024-05-26) ------------------ From 782bdd9b0f24d3d71f6d68a20b12d5c51c6d370e Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 12:48:14 +0200 Subject: [PATCH 5/7] INTERNAL_IPS may not be a list --- debug_toolbar/middleware.py | 2 +- docs/changes.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 38cf92884..0513e2379 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -20,7 +20,7 @@ def show_toolbar(request): """ Default function to determine whether to show the toolbar on a given page. """ - internal_ips = settings.INTERNAL_IPS.copy() + internal_ips = list(settings.INTERNAL_IPS) try: # This is a hack for docker installations. It attempts to look diff --git a/docs/changes.rst b/docs/changes.rst index 1d66d1323..0bac18c20 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -5,6 +5,7 @@ Pending ------- * Removed some CSS which wasn't carefully limited to the toolbar's elements. +* Stopped assuming that ``INTERNAL_IPS`` is a list. 4.4.1 (2024-05-26) From f7e83b16698e19322a7d855bfc1b47830d16666e Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 12:50:47 +0200 Subject: [PATCH 6/7] Add a section to the installation docs about running tests (#1921) I thought about including the relevant documentation in the earlier steps, but I'd have to explain DEBUG, INTERNAL_IPS and TESTING all at once instead of introducing everything step by step. So even though it may be annoying to go back and modify code the user just added it still reads better to me, especially since it only applies to users running tests in their project. (I would hope a lot of them do, but still.) --- docs/changes.rst | 2 ++ docs/configuration.rst | 2 ++ docs/installation.rst | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/docs/changes.rst b/docs/changes.rst index 0bac18c20..3a96e3058 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -6,6 +6,8 @@ Pending * Removed some CSS which wasn't carefully limited to the toolbar's elements. * Stopped assuming that ``INTERNAL_IPS`` is a list. +* Added a section to the installation docs about running tests in projects + where the toolbar is being used. 4.4.1 (2024-05-26) diff --git a/docs/configuration.rst b/docs/configuration.rst index 7db7ad41e..04694aceb 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -72,6 +72,8 @@ Toolbar options The toolbar searches for this string in the HTML and inserts itself just before. +.. _IS_RUNNING_TESTS: + * ``IS_RUNNING_TESTS`` Default: ``"test" in sys.argv`` diff --git a/docs/installation.rst b/docs/installation.rst index 3644bdd5c..657450fac 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -156,6 +156,39 @@ option. able to get the toolbar to work with your docker installation, review the code in ``debug_toolbar.middleware.show_toolbar``. +7. Disable the toolbar when running tests (optional) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If you're running tests in your project you shouldn't activate the toolbar. You +can do this by adding another setting: + +.. code-block:: python + + TESTING = "test" in sys.argv + + if not TESTING: + INSTALLED_APPS = [ + *INSTALLED_APPS, + "debug_toolbar", + ] + MIDDLEWARE = [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + *MIDDLEWARE, + ] + +You should also modify your URLconf file: + +.. code-block:: python + + if not settings.TESTING: + urlpatterns = [ + *urlpatterns, + path("__debug__/", include("debug_toolbar.urls")), + ] + +Alternatively, you can check out the :ref:`IS_RUNNING_TESTS ` +option. + Troubleshooting --------------- From d4811824f971eb79a72091b26119439915647949 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 12:51:57 +0200 Subject: [PATCH 7/7] Version 4.4.2 --- README.rst | 2 +- debug_toolbar/__init__.py | 2 +- docs/changes.rst | 3 +++ docs/conf.py | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index c9a25ce1e..31c8a6f59 100644 --- a/README.rst +++ b/README.rst @@ -44,7 +44,7 @@ Here's a screenshot of the toolbar in action: In addition to the built-in panels, a number of third-party panels are contributed by the community. -The current stable version of the Debug Toolbar is 4.4.1. It works on +The current stable version of the Debug Toolbar is 4.4.2. It works on Django ≥ 4.2.0. The Debug Toolbar does not currently support `Django's asynchronous views diff --git a/debug_toolbar/__init__.py b/debug_toolbar/__init__.py index 45faf6d47..003f26cda 100644 --- a/debug_toolbar/__init__.py +++ b/debug_toolbar/__init__.py @@ -4,7 +4,7 @@ # Do not use pkg_resources to find the version but set it here directly! # see issue #1446 -VERSION = "4.4.1" +VERSION = "4.4.2" # Code that discovers files or modules in INSTALLED_APPS imports this module. urls = "debug_toolbar.urls", APP_NAME diff --git a/docs/changes.rst b/docs/changes.rst index 3a96e3058..a0215d09c 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,9 @@ Change log Pending ------- +4.4.2 (2024-05-27) +------------------ + * Removed some CSS which wasn't carefully limited to the toolbar's elements. * Stopped assuming that ``INTERNAL_IPS`` is a list. * Added a section to the installation docs about running tests in projects diff --git a/docs/conf.py b/docs/conf.py index 512455e39..2e3a527a1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ copyright = copyright.format(datetime.date.today().year) # The full version, including alpha/beta/rc tags -release = "4.4.1" +release = "4.4.2" # -- General configuration ---------------------------------------------------