-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathversions.py
More file actions
32 lines (24 loc) · 908 Bytes
/
versions.py
File metadata and controls
32 lines (24 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations
from importlib import metadata
from fastapi import Request, Response, __version__
from debug_toolbar.panels import Panel
from debug_toolbar.types import Stats
class VersionsPanel(Panel):
title = "Versions"
template = "panels/versions.html"
@property
def nav_subtitle(self) -> str:
return f"FastAPI {__version__}"
@property
def scripts(self) -> list[str]:
scripts = super().scripts
scripts.append(self.url_for("debug_toolbar.static", path="js/versions.js"))
return scripts
async def generate_stats(self, request: Request, response: Response) -> Stats:
dists = {d.metadata.get("name", None): d for d in
metadata.distributions()}
packages = sorted(
dists,
key=lambda dist: dist.lower() if dist else "",
)
return {"packages": packages}