Skip to content

Commit

Permalink
Merge pull request #43 from mongkok/fix/minor-issues
Browse files Browse the repository at this point in the history
v0.6.0
  • Loading branch information
mongkok authored Feb 12, 2024
2 parents c87586b + 8f52371 commit e50937a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 2 additions & 3 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@


def show_toolbar(request: Request, settings: DebugToolbarSettings) -> bool:
if settings.ALLOWED_IPS is not None:
remote_addr, _ = request["client"]
return request.app.debug and remote_addr in settings.ALLOWED_IPS
if request.client is not None and settings.ALLOWED_HOSTS is not None:
return request.app.debug and request.client.host in settings.ALLOWED_HOSTS
return request.app.debug


Expand Down
3 changes: 2 additions & 1 deletion debug_toolbar/panels/sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typing as t
from contextlib import AsyncExitStack
from time import perf_counter

from fastapi import Request, Response
from fastapi.concurrency import AsyncExitStack
from fastapi.dependencies.utils import solve_dependencies
from sqlalchemy import event
from sqlalchemy.engine import Connection, Engine, ExecutionContext
Expand Down Expand Up @@ -52,6 +52,7 @@ async def add_engines(self, request: Request):
request=request,
dependant=route.dependant,
dependency_overrides_provider=route.dependency_overrides_provider,
async_exit_stack=AsyncExitStack(),
)
for value in solved_result[0].values():
if isinstance(value, Session):
Expand Down
14 changes: 5 additions & 9 deletions debug_toolbar/panels/versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing as t
from importlib import metadata

from fastapi import Request, Response, __version__

Expand All @@ -21,13 +22,8 @@ def scripts(self) -> t.List[str]:
return scripts

async def generate_stats(self, request: Request, response: Response) -> Stats:
try:
import pkg_resources
except ImportError:
packages = []
else:
packages = sorted(
pkg_resources.working_set,
key=lambda pkg: pkg.project_name.lower(),
)
packages = sorted(
metadata.distributions(),
key=lambda dist: dist.metadata["name"].lower(),
)
return {"packages": packages}
6 changes: 3 additions & 3 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from jinja2 import BaseLoader, ChoiceLoader, Environment, PackageLoader
from jinja2.ext import Extension
from pydantic import Field, IPvAnyAddress, model_validator
from pydantic import Field, model_validator
from pydantic_extra_types.color import Color
from pydantic_settings import BaseSettings, SettingsConfigDict

Expand Down Expand Up @@ -45,11 +45,11 @@ class DebugToolbarSettings(BaseSettings):
"want disabled (but still displayed) by default."
),
)
ALLOWED_IPS: t.Optional[t.Sequence[IPvAnyAddress]] = Field(
ALLOWED_HOSTS: t.Optional[t.Sequence[str]] = Field(
None,
description=(
"If it's set, the Debug Toolbar is shown only "
"if your IP address is listed."
"if the request host is listed."
),
)
JINJA_ENV: Environment = Field(
Expand Down
4 changes: 2 additions & 2 deletions debug_toolbar/templates/panels/versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
{% for package in packages %}
<tr>
<td>
<a href="https://pypi.org/project/{{ package.project_name }}/" target="_blank">
{{ package.project_name }}
<a href="https://pypi.org/project/{{ package.metadata.name }}/" target="_blank">
{{ package.metadata.name }}
</a>
</td>
<td><code>{{ package.version }}</code></td>
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "fastapi-debug-toolbar"
description = "A debug toolbar for FastAPI."
readme = "README.md"
license = "BSD-3-Clause"
requires-python = ">=3.7"
requires-python = ">=3.8"
dynamic = ["version"]
authors = [
{ name = "Dani", email = "dani@domake.io" }
Expand All @@ -26,11 +26,11 @@ classifiers = [
"Typing :: Typed",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development",
"Topic :: Software Development :: Debuggers",
"Topic :: Software Development :: Libraries",
Expand All @@ -42,7 +42,7 @@ classifiers = [
]

dependencies = [
"fastapi >=0.70.0",
"fastapi >=0.106.0",
"anyio >=3.0.0",
"Jinja2 >=2.9",
"pydantic >=2.0",
Expand Down
11 changes: 1 addition & 10 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import status

from .mark import override_panels, override_settings
from .mark import override_panels
from .testclient import TestClient


Expand All @@ -19,12 +19,3 @@ def test_invalid_store_id(client: TestClient) -> None:

assert response.status_code == status.HTTP_200_OK
assert not response.json()["scripts"]


@override_settings(
panels=["debug_toolbar.panels.timer.TimerPanel"],
allowed_ips=[],
)
def test_not_allowed(client: TestClient) -> None:
response = client.render_panel(store_id="", panel_id="TimerPanel")
assert response.status_code == status.HTTP_404_NOT_FOUND

0 comments on commit e50937a

Please sign in to comment.