Skip to content

Commit

Permalink
Add shortcut for monkey patch function
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Dec 11, 2023
1 parent 861419b commit 3041f8c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion fastapi_cdn_host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

from .client import monkey_patch_for_docs_ui

monkey_patch = monkey_patch_for_docs_ui
__version__ = importlib.metadata.version(Path(__file__).parent.name)
__all__ = ("__version__", "monkey_patch_for_docs_ui")
__all__ = ("__version__", "monkey_patch", "monkey_patch_for_docs_ui")
8 changes: 5 additions & 3 deletions fastapi_cdn_host/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from fastapi.responses import HTMLResponse
from fastapi.routing import APIRoute, Mount
from fastapi.staticfiles import StaticFiles
from typing_extensions import Annotated # type: ignore [attr-defined]
from typing_extensions import Annotated # type: ignore[attr-defined]

logger = logging.getLogger("fastapi-cdn-host")

Expand Down Expand Up @@ -217,12 +217,14 @@ def _maybe(
return self._next_it(gs, mount, app, static_root, favicon)
return None

def get_latest_one(self, gs: List[Path]) -> Path:
@staticmethod
def get_latest_one(gs: List[Path]) -> Path:
if len(gs) > 1:
gs = sorted(gs, key=lambda x: x.stat().st_mtime, reverse=True)
return gs[0]

def file_to_uri(self, p: Path, static_root: Path, uri_path: str) -> str:
@staticmethod
def file_to_uri(p: Path, static_root: Path, uri_path: str) -> str:
return uri_path.rstrip("/") + "/" + p.relative_to(static_root).as_posix()

def _next_it(
Expand Down
21 changes: 20 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-cdn-host"
version = "0.2.2"
version = "0.3.0"
description = ""
authors = ["Waket Zheng <[email protected]>"]
readme = "README.md"
Expand All @@ -14,6 +14,11 @@ httpx = {version = ">=0.23"}
[tool.poetry.group.dev.dependencies]
fast-tort-cli = {extras = ["all"], version="*", python=">=3.11"}
uvicorn = {extras = ["standard"], version = "*"}
isort = "*"
black = "*"
ruff = "*"
mypy = "*"
pytest = "*"
bandit = "^1.7.5"

[build-system]
Expand Down

0 comments on commit 3041f8c

Please sign in to comment.