From 3041f8cc70eee7bcd482bfde68d739df5f0d814e Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 11 Dec 2023 19:16:58 +0800 Subject: [PATCH] Add shortcut for monkey patch function --- fastapi_cdn_host/__init__.py | 3 ++- fastapi_cdn_host/client.py | 8 +++++--- poetry.lock | 21 ++++++++++++++++++++- pyproject.toml | 7 ++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/fastapi_cdn_host/__init__.py b/fastapi_cdn_host/__init__.py index f8257bc..ec41886 100644 --- a/fastapi_cdn_host/__init__.py +++ b/fastapi_cdn_host/__init__.py @@ -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") diff --git a/fastapi_cdn_host/client.py b/fastapi_cdn_host/client.py index 4b7dc90..1e1c4e7 100644 --- a/fastapi_cdn_host/client.py +++ b/fastapi_cdn_host/client.py @@ -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") @@ -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( diff --git a/poetry.lock b/poetry.lock index a7685c2..9861927 100644 --- a/poetry.lock +++ b/poetry.lock @@ -91,6 +91,8 @@ mypy-extensions = ">=0.4.3" packaging = ">=22.0" pathspec = ">=0.9.0" platformdirs = ">=2" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} [package.extras] colorama = ["colorama (>=0.4.3)"] @@ -664,6 +666,7 @@ files = [ [package.dependencies] mypy-extensions = ">=1.0.0" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} typing-extensions = ">=4.1.0" [package.extras] @@ -727,6 +730,9 @@ files = [ {file = "pep517-0.13.1.tar.gz", hash = "sha256:1b2fa2ffd3938bb4beffe5d6146cbcb2bda996a5a4da9f31abffd8b24e07b317"}, ] +[package.dependencies] +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} + [[package]] name = "pip" version = "23.3.1" @@ -980,9 +986,11 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" packaging = "*" pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] @@ -1234,6 +1242,17 @@ files = [ [package.dependencies] pbr = ">=2.0.0,<2.1.0 || >2.1.0" +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + [[package]] name = "tomlkit" version = "0.12.3" @@ -1551,4 +1570,4 @@ requests = "*" [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "3aa7cfc4953aab6a086f0dc1136f6e28f505b3562985ffa3cc327acf709b7bb4" +content-hash = "736687f7f980d14dded133d52ca7402bc779920f8b4ea3a57686faa833a4be43" diff --git a/pyproject.toml b/pyproject.toml index 37d4e35..0c83752 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastapi-cdn-host" -version = "0.2.2" +version = "0.3.0" description = "" authors = ["Waket Zheng "] readme = "README.md" @@ -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]