Skip to content

Commit 5adad1a

Browse files
[pre-commit.ci] pre-commit autoupdate (#33)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.5.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.3.4 → v0.11.2](astral-sh/ruff-pre-commit@v0.3.4...v0.11.2) - [github.com/psf/black-pre-commit-mirror: 24.3.0 → 25.1.0](psf/black-pre-commit-mirror@24.3.0...25.1.0) - [github.com/codespell-project/codespell: v2.2.6 → v2.4.1](codespell-project/codespell@v2.2.6...v2.4.1) - [github.com/alessandrojcm/commitlint-pre-commit-hook: v9.13.0 → v9.22.0](alessandrojcm/commitlint-pre-commit-hook@v9.13.0...v9.22.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * style: fix lint --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: WSH032 <[email protected]>
1 parent ef72bc0 commit 5adad1a

14 files changed

+80
-61
lines changed

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ default_install_hook_types: [pre-commit, commit-msg]
99

1010
repos:
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v4.5.0
12+
rev: v5.0.0
1313
hooks:
1414
- id: no-commit-to-branch
1515
- id: check-added-large-files
@@ -22,25 +22,25 @@ repos:
2222
- id: trailing-whitespace
2323
# ruff must before black
2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.3.4
25+
rev: v0.11.2
2626
hooks:
2727
- id: ruff
2828
alias: ruff # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml`
2929
args: [--fix, --exit-non-zero-on-fix]
3030
- repo: https://github.com/psf/black-pre-commit-mirror
31-
rev: 24.3.0
31+
rev: 25.1.0
3232
hooks:
3333
- id: black
3434
alias: black # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml`
3535
- repo: https://github.com/codespell-project/codespell
36-
rev: v2.2.6
36+
rev: v2.4.1
3737
hooks:
3838
- id: codespell
3939
alias: codespell # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml`
4040
additional_dependencies:
4141
- tomli
4242
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
43-
rev: v9.13.0
43+
rev: v9.22.0
4444
hooks:
4545
- id: commitlint
4646
stages: [commit-msg]

docs_src/advanced/modify-request.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from typing import Any
33

44
import httpx
5-
from fastapi_proxy_lib.fastapi.app import reverse_http_app
65
from httpx import Request
76

7+
from fastapi_proxy_lib.fastapi.app import reverse_http_app
8+
89

910
class MyCustomAuth(httpx.Auth):
1011
# ref: https://www.python-httpx.org/advanced/#customizing-authentication

docs_src/advanced/modify-response-particular.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from contextlib import asynccontextmanager
33

44
from fastapi import FastAPI
5-
from fastapi_proxy_lib.core.http import ReverseHttpProxy
65
from starlette.requests import Request
76

7+
from fastapi_proxy_lib.core.http import ReverseHttpProxy
8+
89
proxy = ReverseHttpProxy(base_url="http://httpbin.org/")
910

1011

docs_src/advanced/modify-response.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from contextlib import asynccontextmanager
33

44
from fastapi import FastAPI
5-
from fastapi_proxy_lib.core.http import ReverseHttpProxy
65
from starlette.requests import Request
76
from starlette.responses import AsyncContentStream, StreamingResponse
87

8+
from fastapi_proxy_lib.core.http import ReverseHttpProxy
9+
910
proxy = ReverseHttpProxy(base_url="http://www.example.com/")
1011

1112

pyproject.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ dependencies = [
8484
# NOTE: 👇
8585
# The versions of `black`, `ruff`, `codespell`, must be consistent with the `.pre-commit-config.yaml`.
8686
# Don't edit them manually, use `pre-commit run ver_sync` instead.
87-
"black==24.3.0",
88-
"ruff==0.3.4",
89-
"codespell==2.2.6",
87+
"black==25.1.0",
88+
"ruff==0.11.2",
89+
"codespell==2.4.1",
9090
# Don't write comments on these lines, because they will be removed by `pre-commit run ver_sync`.
9191
# NOTE: 👆
9292

@@ -107,7 +107,7 @@ dependencies = [
107107
# xml for codecov, html for local review
108108
test = "pytest tests/ --cov --cov-report=xml --cov-report=html"
109109
# ruff must before black
110-
lint = ["- ruff --fix .", "- black .", "- pyright .", "- codespell . -i 3 -w"]
110+
lint = ["- ruff check --fix .", "- black .", "- pyright .", "- codespell . -i 3 -w"]
111111
lint-check = [
112112
"ruff check .",
113113
"black --check .",

src/fastapi_proxy_lib/core/_tool.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@
2929
from typing_extensions import deprecated, overload
3030

3131
__all__ = (
32-
"check_base_url",
33-
"return_err_msg_response",
34-
"check_http_version",
3532
"BaseURLError",
3633
"ErrMsg",
3734
"ErrRseponseJson",
3835
"ProxyFilterProto",
36+
"_RejectedProxyRequestError",
37+
"check_base_url",
38+
"check_http_version",
3939
"default_proxy_filter",
40-
"warn_for_none_filter",
4140
"lru_get_url",
4241
"reset_lru_get_url",
43-
"_RejectedProxyRequestError",
42+
"return_err_msg_response",
43+
"warn_for_none_filter",
4444
)
4545

4646
_logger = logging.getLogger(__name__)
@@ -100,7 +100,7 @@ class ErrMsg(TypedDict):
100100
class ErrRseponseJson(TypedDict):
101101
"""A json-like dict for return by `JSONResponse`.
102102
103-
Somethin like:
103+
Something like:
104104
```json
105105
{
106106
"detail": {

src/fastapi_proxy_lib/core/http.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
__all__ = (
3939
"BaseHttpProxy",
40-
"ReverseHttpProxy",
4140
"ForwardHttpProxy",
41+
"ReverseHttpProxy",
4242
)
4343

4444
_logger = logging.getLogger(__name__)

src/fastapi_proxy_lib/core/tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from ._tool import ProxyFilterProto, default_proxy_filter
44

5-
__all__ = ("default_proxy_filter", "ProxyFilterProto")
5+
__all__ = ("ProxyFilterProto", "default_proxy_filter")

src/fastapi_proxy_lib/core/websocket.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,12 @@ async def send_request_to_target( # pyright: ignore [reportIncompatibleMethodOv
490490

491491
# httpx.stream()
492492
# refer to: https://www.python-httpx.org/api/#helper-functions
493-
client_request_headers: "HeaderTypes" = _change_client_header(
493+
client_request_headers: HeaderTypes = _change_client_header(
494494
headers=websocket.headers, target_url=target_url
495495
)
496496
# TODO, FIXME: do not shallow clone (i.e, `tuple(...)`) the query_params,
497497
# see: <https://github.com/WSH032/fastapi-proxy-lib/pull/57#issuecomment-2750153934>
498-
client_request_params: "QueryParamTypes" = tuple(
498+
client_request_params: QueryParamTypes = tuple(
499499
websocket.query_params.multi_items()
500500
)
501501

tests/conftest.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
import pytest
2222
import uvicorn
2323
from asgi_lifespan import LifespanManager
24+
from typing_extensions import ParamSpec
25+
2426
from fastapi_proxy_lib.fastapi.app import (
2527
forward_http_app,
2628
reverse_http_app,
2729
reverse_ws_app,
2830
)
29-
from typing_extensions import ParamSpec
3031

3132
from .app.echo_http_app import get_app as get_http_test_app
3233
from .app.echo_ws_app import get_app as get_ws_test_app
@@ -68,13 +69,13 @@ def __call__( # noqa: D102
6869

6970

7071
# https://anyio.readthedocs.io/en/stable/testing.html#specifying-the-backends-to-run-on
71-
@pytest.fixture()
72+
@pytest.fixture
7273
def anyio_backend() -> Literal["asyncio"]:
7374
"""Specify the async backend for `pytest.mark.anyio`."""
7475
return "asyncio"
7576

7677

77-
@pytest.fixture()
78+
@pytest.fixture
7879
async def lifespan_manager() -> AsyncIterator[LifespanManagerFixture]:
7980
"""Fixture for asgi lifespan manager.
8081
@@ -103,7 +104,7 @@ async def _lifespan_manager(app: ASGIApp) -> ASGIApp:
103104
# 所以这里明确要求每个fixture的作用域都是"function",不要共享 TestAppDataclass
104105

105106

106-
@pytest.fixture()
107+
@pytest.fixture
107108
async def echo_http_test_model(
108109
lifespan_manager: LifespanManagerFixture,
109110
) -> LifeAppDataclass4Test:
@@ -119,7 +120,7 @@ def LifeAppDataclass4Test.request(): Get the latest original http request from t
119120
return LifeAppDataclass4Test(app=life_app, request_dict=app_dataclass.request_dict)
120121

121122

122-
@pytest.fixture()
123+
@pytest.fixture
123124
async def echo_ws_test_model(
124125
lifespan_manager: LifespanManagerFixture,
125126
) -> LifeAppDataclass4Test:
@@ -157,7 +158,7 @@ async def wappered_app_fct(*args: _P.args, **kwargs: _P.kwargs) -> ASGIApp:
157158
return wappered_app_fct
158159

159160

160-
@pytest.fixture()
161+
@pytest.fixture
161162
def forward_http_app_fct(
162163
lifespan_manager: LifespanManagerFixture,
163164
): # -> AppFactoryFixture
@@ -168,7 +169,7 @@ def forward_http_app_fct(
168169
return _app_fct_life_wapper(forward_http_app, lifespan_manager)
169170

170171

171-
@pytest.fixture()
172+
@pytest.fixture
172173
def reverse_http_app_fct(
173174
lifespan_manager: LifespanManagerFixture,
174175
): # -> AppFactoryFixture
@@ -179,7 +180,7 @@ def reverse_http_app_fct(
179180
return _app_fct_life_wapper(reverse_http_app, lifespan_manager)
180181

181182

182-
@pytest.fixture()
183+
@pytest.fixture
183184
def reverse_ws_app_fct(
184185
lifespan_manager: LifespanManagerFixture,
185186
): # -> AppFactoryFixture
@@ -190,7 +191,7 @@ def reverse_ws_app_fct(
190191
return _app_fct_life_wapper(reverse_ws_app, lifespan_manager)
191192

192193

193-
@pytest.fixture()
194+
@pytest.fixture
194195
async def uvicorn_server_fixture() -> AsyncIterator[UvicornServerFixture]:
195196
"""Fixture for UvicornServer.
196197

tests/test_core_lib.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import httpx
44
import pytest
55
from fastapi import APIRouter, FastAPI
6+
from httpx import ASGITransport
7+
from starlette.responses import JSONResponse
8+
69
from fastapi_proxy_lib.core._tool import (
710
BaseURLError,
811
ErrMsg,
@@ -13,8 +16,6 @@
1316
from fastapi_proxy_lib.core.http import ReverseHttpProxy
1417
from fastapi_proxy_lib.fastapi.app import forward_http_app, reverse_http_app
1518
from fastapi_proxy_lib.fastapi.router import RouterHelper
16-
from httpx import ASGITransport
17-
from starlette.responses import JSONResponse
1819

1920
from .tool import DEFAULT_URL
2021

@@ -43,7 +44,7 @@ def test_base_url_cheking_when_init() -> None:
4344
assert check_base_url("http://www.echo.com/?p=1#foo") == "http://www.echo.com/"
4445

4546

46-
@pytest.mark.anyio()
47+
@pytest.mark.anyio
4748
async def test_func_return_err_msg_response() -> None:
4849
"""Test `fastapi_proxy_lib.core._tool.return_err_msg_response()`."""
4950

tests/test_docs_examples.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ def test_forward_http_proxy() -> None:
77
from contextlib import asynccontextmanager
88

99
from fastapi import FastAPI
10-
from fastapi_proxy_lib.core.http import ForwardHttpProxy
11-
from fastapi_proxy_lib.core.tool import default_proxy_filter
1210
from httpx import AsyncClient
1311
from starlette.requests import Request
1412

13+
from fastapi_proxy_lib.core.http import ForwardHttpProxy
14+
from fastapi_proxy_lib.core.tool import default_proxy_filter
15+
1516
proxy = ForwardHttpProxy(AsyncClient(), proxy_filter=default_proxy_filter)
1617

1718
@asynccontextmanager
@@ -37,10 +38,11 @@ def test_reverse_http_proxy() -> None:
3738
from contextlib import asynccontextmanager
3839

3940
from fastapi import FastAPI
40-
from fastapi_proxy_lib.core.http import ReverseHttpProxy
4141
from httpx import AsyncClient
4242
from starlette.requests import Request
4343

44+
from fastapi_proxy_lib.core.http import ReverseHttpProxy
45+
4446
proxy = ReverseHttpProxy(AsyncClient(), base_url="http://www.example.com/")
4547

4648
@asynccontextmanager
@@ -75,10 +77,11 @@ def test_reverse_ws_proxy() -> None:
7577
from contextlib import asynccontextmanager
7678

7779
from fastapi import FastAPI
78-
from fastapi_proxy_lib.core.websocket import ReverseWebSocketProxy
7980
from httpx import AsyncClient
8081
from starlette.websockets import WebSocket
8182

83+
from fastapi_proxy_lib.core.websocket import ReverseWebSocketProxy
84+
8285
proxy = ReverseWebSocketProxy(AsyncClient(), base_url="ws://echo.websocket.events/")
8386

8487
@asynccontextmanager
@@ -101,6 +104,7 @@ async def _(websocket: WebSocket, path: str = ""):
101104
def test_router_helper() -> None:
102105
"""测试 RouterHelper 中的例子."""
103106
from fastapi import APIRouter, FastAPI
107+
104108
from fastapi_proxy_lib.core.http import ForwardHttpProxy, ReverseHttpProxy
105109
from fastapi_proxy_lib.core.tool import default_proxy_filter
106110
from fastapi_proxy_lib.core.websocket import ReverseWebSocketProxy

0 commit comments

Comments
 (0)