diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e28bc8..34ced3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ default_install_hook_types: [pre-commit, commit-msg] repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: no-commit-to-branch - id: check-added-large-files @@ -22,13 +22,13 @@ repos: - id: trailing-whitespace # ruff must before black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.2 + rev: v0.14.13 hooks: - id: ruff alias: ruff # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml` args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.1.0 + rev: 26.1.0 hooks: - id: black alias: black # NOTE: don't change this alias, it's used in `ver_sync.py`, keep consistent with `pyproject.toml` @@ -40,7 +40,7 @@ repos: additional_dependencies: - tomli - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook - rev: v9.22.0 + rev: v9.24.0 hooks: - id: commitlint stages: [commit-msg] diff --git a/pyproject.toml b/pyproject.toml index 9bd2d00..d2264eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,8 +84,8 @@ dependencies = [ # NOTE: 👇 # The versions of `black`, `ruff`, `codespell`, must be consistent with the `.pre-commit-config.yaml`. # Don't edit them manually, use `pre-commit run ver_sync` instead. - "black==25.1.0", - "ruff==0.11.2", + "black==26.1.0", + "ruff==0.14.13", "codespell==2.4.1", # Don't write comments on these lines, because they will be removed by `pre-commit run ver_sync`. # NOTE: 👆 diff --git a/scripts/pre_commit_scripts/ver_sync.py b/scripts/pre_commit_scripts/ver_sync.py index 9e4cca6..a3b2670 100644 --- a/scripts/pre_commit_scripts/ver_sync.py +++ b/scripts/pre_commit_scripts/ver_sync.py @@ -2,7 +2,6 @@ """Maintain lint tools version consistency between `.pre-commit-config.yaml` and `pyproject.toml`.""" - # https://packaging.pypa.io/en/stable/requirements.html # https://yaml.readthedocs.io/en/latest/example/ # https://tomlkit.readthedocs.io/en/latest/quickstart/ diff --git a/src/fastapi_proxy_lib/core/_tool.py b/src/fastapi_proxy_lib/core/_tool.py index c3c72f6..f647cbf 100644 --- a/src/fastapi_proxy_lib/core/_tool.py +++ b/src/fastapi_proxy_lib/core/_tool.py @@ -204,39 +204,31 @@ def check_base_url(base_url: Union[httpx.URL, str], /) -> httpx.URL: ) if not base_url.scheme or not base_url.netloc: - raise BaseURLError( - dedent( - f"""\ + raise BaseURLError(dedent(f"""\ `base_url` must contain scheme and netloc, e.g. {example_url} got: {base_url}\ - """ - ) - ) + """)) # NOTE: 尽量用 URL.copy_with() 来修改URL,而不是 URL.join(),因为后者性能较差 if base_url.query or base_url.fragment: base_url = base_url.copy_with(query=None, fragment=None) warnings.warn( - dedent( - f"""\ + dedent(f"""\ `base_url` should not contain `query` or `fragment`, which will be ignored. The `base_url` will be treated as: {base_url}\ - """ - ), + """), stacklevel=2, ) # 我们在这里强制要求 base_url 以"/"结尾是有原因的: # 因为 RouterHelper 生成的路由是以"/"结尾的,在反向代理时 # "/" 之后后路径参数将会被拼接到这个 base_url 后面 if not str(base_url).endswith("/"): - msg = dedent( - f"""\ + msg = dedent(f"""\ `base_url` must ends with "/", may be you mean: {base_url}/\ - """ - ) + """) raise BaseURLError(msg) return base_url @@ -424,8 +416,7 @@ def warn_for_none_filter( Else will just return the original argument `proxy_filter`. """ if proxy_filter is None: - msg = dedent( - """\ + msg = dedent("""\ The `proxy_filter` is None, which means no filter will be used. It is not recommended, because it may cause security issues. @@ -433,8 +424,7 @@ def warn_for_none_filter( - if the host of url is ip address, and is not global ip address. More info: https://wsh032.github.io/fastapi-proxy-lib/Usage/Security/ - """ - ) + """) warnings.warn(msg, stacklevel=3) return default_proxy_filter else: diff --git a/src/fastapi_proxy_lib/fastapi/__init__.py b/src/fastapi_proxy_lib/fastapi/__init__.py index ffd872c..5ca1c2e 100644 --- a/src/fastapi_proxy_lib/fastapi/__init__.py +++ b/src/fastapi_proxy_lib/fastapi/__init__.py @@ -9,11 +9,9 @@ from textwrap import dedent if find_spec("fastapi") is None: # pragma: no cover # 无法测试 - msg: str = dedent( - """\ + msg: str = dedent("""\ `fastapi` is not installed. `fastapi_proxy_lib.fastapi` module requires installing `fastapi` first: pip install fastapi-proxy-lib[standard] - """ - ) + """) raise RuntimeError(msg) diff --git a/tests/conftest.py b/tests/conftest.py index 817bdad..8183552 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,4 @@ -# ruff: noqa: ANN201, ANN001 +# ruff: noqa: ANN201 # pyright: reportMissingParameterType=false # 返回值标注太麻烦,让pyright自己推断