From 30572c972d7a65fb81d1bf83f85b12f786849185 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Sun, 27 Jun 2021 22:52:56 +0300 Subject: [PATCH] 21.6 Changelog, release version, and deprecations (#2172) * Changelog and version * Rearrange API docs for easier navigation * Version 21.6 docs * Change release workflow * Disable Windows tests --- .github/workflows/pr-windows.yml | 62 ++++++------ .github/workflows/publish-package.yml | 12 +-- CHANGELOG.rst | 92 +++++++++++++++++ CONTRIBUTING.rst | 2 +- Makefile | 3 +- docs/sanic/api/app.rst | 17 ++++ docs/sanic/api/blueprints.rst | 17 ++++ docs/sanic/api/core.rst | 47 +++++++++ docs/sanic/api/exceptions.rst | 16 +++ docs/sanic/api/router.rst | 18 ++++ docs/sanic/api/server.rst | 25 +++++ docs/sanic/api/utility.rst | 16 +++ docs/sanic/api_reference.rst | 137 ++------------------------ docs/sanic/contributing.rst | 2 +- sanic/__init__.py | 2 + sanic/__version__.py | 2 +- sanic/blueprints.py | 2 - sanic/response.py | 36 ++++--- tests/test_response.py | 7 +- 19 files changed, 318 insertions(+), 197 deletions(-) create mode 100644 docs/sanic/api/app.rst create mode 100644 docs/sanic/api/blueprints.rst create mode 100644 docs/sanic/api/core.rst create mode 100644 docs/sanic/api/exceptions.rst create mode 100644 docs/sanic/api/router.rst create mode 100644 docs/sanic/api/server.rst create mode 100644 docs/sanic/api/utility.rst diff --git a/.github/workflows/pr-windows.yml b/.github/workflows/pr-windows.yml index e3a32e5d..a47a5006 100644 --- a/.github/workflows/pr-windows.yml +++ b/.github/workflows/pr-windows.yml @@ -1,34 +1,34 @@ -name: Run Unit Tests on Windows -on: - pull_request: - branches: - - main +# name: Run Unit Tests on Windows +# on: +# pull_request: +# branches: +# - main -jobs: - testsOnWindows: - name: ut-${{ matrix.config.tox-env }} - runs-on: windows-latest - strategy: - fail-fast: false - matrix: - config: - - { python-version: 3.7, tox-env: py37-no-ext } - - { python-version: 3.8, tox-env: py38-no-ext } - - { python-version: 3.9, tox-env: py39-no-ext } - - { python-version: pypy-3.7, tox-env: pypy37-no-ext } +# jobs: +# testsOnWindows: +# name: ut-${{ matrix.config.tox-env }} +# runs-on: windows-latest +# strategy: +# fail-fast: false +# matrix: +# config: +# - { python-version: 3.7, tox-env: py37-no-ext } +# - { python-version: 3.8, tox-env: py38-no-ext } +# - { python-version: 3.9, tox-env: py39-no-ext } +# - { python-version: pypy-3.7, tox-env: pypy37-no-ext } - steps: - - name: Checkout Repository - uses: actions/checkout@v2 +# steps: +# - name: Checkout Repository +# uses: actions/checkout@v2 - - name: Run Unit Tests - uses: ahopkins/custom-actions@pip-extra-args - with: - python-version: ${{ matrix.config.python-version }} - test-infra-tool: tox - test-infra-version: latest - action: tests - test-additional-args: "-e=${{ matrix.config.tox-env }}" - experimental-ignore-error: "true" - command-timeout: "600000" - pip-extra-args: "--user" +# - name: Run Unit Tests +# uses: ahopkins/custom-actions@pip-extra-args +# with: +# python-version: ${{ matrix.config.python-version }} +# test-infra-tool: tox +# test-infra-version: latest +# action: tests +# test-additional-args: "-e=${{ matrix.config.tox-env }}" +# experimental-ignore-error: "true" +# command-timeout: "600000" +# pip-extra-args: "--user" diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index cbfbd3d8..faa3b7e6 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -1,8 +1,8 @@ name: Publish Artifacts on: - push: - tags: - - 'v*.*.*' + release: + types: [created] + jobs: publishPythonPackage: name: Publishing Sanic Release Artifacts @@ -21,8 +21,8 @@ jobs: uses: harshanarayana/custom-actions@main with: python-version: ${{ matrix.python-version }} - package-infra-name: 'twine' + package-infra-name: "twine" pypi-user: __token__ pypi-access-token: ${{ secrets.PYPI_ACCESS_TOKEN }} - action: 'package-publish' - pypi-verify-metadata: 'true' + action: "package-publish" + pypi-verify-metadata: "true" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fe6fcfbc..5e99452b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,95 @@ +Version 21.6.0 +-------------- + +Features +******** + + * `#2094 `_ + Add ``response.eof()`` method for closing a stream in a handler + * `#2097 `_ + Allow case-insensitive HTTP Upgrade header + * `#2104 `_ + Explicit usage of CIMultiDict getters + * `#2109 `_ + Consistent use of error loggers + * `#2114 `_ + New ``client_ip`` access of connection info instance + * `#2119 `_ + Alternatate classes on instantiation for ``Config`` and ``Sanic.ctx`` + * `#2133 `_ + Implement new version of AST router + + * Proper differentiation between ``alpha`` and ``string`` param types + * Adds a ``slug`` param type, example: ```` + * Deprecates ```` in favor of ```` + * Deprecates ```` in favor of ```` + * Adds a ``route.uri`` accessor + * `#2136 `_ + CLI improvements with new optional params + * `#2137 `_ + Add ``version_prefix`` to URL builders + * `#2140 `_ + Event autoregistration with ``EVENT_AUTOREGISTER`` + * `#2146 `_, `#2147 `_ + Require stricter names on ``Sanic()`` and ``Blueprint()`` + * `#2150 `_ + Infinitely reusable and nestable ``Blueprint`` and ``BlueprintGroup`` + * `#2154 `_ + Upgrade ``websockets`` dependency to min version + * `#2155 `_ + Allow for maximum header sizes to be increased: ``REQUEST_MAX_HEADER_SIZE`` + * `#2157 `_ + Allow app factory pattern in CLI + * `#2165 `_ + Change HTTP methods to enums + * `#2167 `_ + Allow auto-reloading on additional directories + * `#2168 `_ + Add simple HTTP server to CLI + * `#2170 `_ + Additional methods for attaching ``HTTPMethodView`` + +Bugfixes +******** + + * `#2091 `_ + Fix ``UserWarning`` in ASGI mode for missing ``__slots__`` + * `#2099 `_ + Fix static request handler logging exception on 404 + * `#2110 `_ + Fix request.args.pop removes parameters inconsistently + * `#2107 `_ + Fix type hinting for load_env + * `#2127 `_ + Make sure ASGI ws subprotocols is a list + * `#2128 `_ + Fix issue where Blueprint exception handlers do not consistently route to proper handler + + +Deprecations and Removals +************************* + + * `#2156 `_ + Remove config value ``REQUEST_BUFFER_QUEUE_SIZE`` + * `#2170 `_ + ``CompositionView`` deprecated and marked for removal in 21.12 + * `#2172 `_ + Deprecate StreamingHTTPResponse + +Developer infrastructure +************************ + + * `#2149 `_ + Remove Travis CI in favor of GitHub Actions + +Improved Documentation +********************** + + * `#2164 `_ + Fix typo in documentation + * `#2100 `_ + Remove documentation for non-existent arguments + Version 21.3.2 -------------- diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 4d8263b8..c87f2355 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -87,7 +87,7 @@ Permform ``flake8``\ , ``black`` and ``isort`` checks. tox -e lint Run type annotation checks ---------------- +-------------------------- ``tox`` environment -> ``[testenv:type-checking]`` diff --git a/Makefile b/Makefile index a005b842..aead2544 100644 --- a/Makefile +++ b/Makefile @@ -88,8 +88,7 @@ docs-test: docs-clean cd docs && make dummy docs-serve: - # python -m http.server --directory=./docs/_build/html 9999 - sphinx-autobuild docs docs/_build/html --port 9999 --watch ./sanic + sphinx-autobuild docs docs/_build/html --port 9999 --watch ./ changelog: python scripts/changelog.py diff --git a/docs/sanic/api/app.rst b/docs/sanic/api/app.rst new file mode 100644 index 00000000..4d3c97bc --- /dev/null +++ b/docs/sanic/api/app.rst @@ -0,0 +1,17 @@ +Application +=========== + +sanic.app +--------- + +.. automodule:: sanic.app + :members: + :show-inheritance: + :inherited-members: + +sanic.config +------------ + +.. automodule:: sanic.config + :members: + :show-inheritance: diff --git a/docs/sanic/api/blueprints.rst b/docs/sanic/api/blueprints.rst new file mode 100644 index 00000000..7fe3842f --- /dev/null +++ b/docs/sanic/api/blueprints.rst @@ -0,0 +1,17 @@ +Blueprints +========== + +sanic.blueprints +---------------- + +.. automodule:: sanic.blueprints + :members: + :show-inheritance: + :inherited-members: + +sanic.blueprint_group +--------------------- + +.. automodule:: sanic.blueprint_group + :members: + :special-members: diff --git a/docs/sanic/api/core.rst b/docs/sanic/api/core.rst new file mode 100644 index 00000000..1891c843 --- /dev/null +++ b/docs/sanic/api/core.rst @@ -0,0 +1,47 @@ +Core +==== + +sanic.cookies +------------- + +.. automodule:: sanic.cookies + :members: + :show-inheritance: + + +sanic.handlers +-------------- + +.. automodule:: sanic.handlers + :members: + :show-inheritance: + + +sanic.request +------------- + +.. automodule:: sanic.request + :members: + :show-inheritance: + +sanic.response +-------------- + +.. automodule:: sanic.response + :members: + :show-inheritance: + + +sanic.views +----------- + +.. automodule:: sanic.views + :members: + :show-inheritance: + +sanic.websocket +--------------- + +.. automodule:: sanic.websocket + :members: + :show-inheritance: diff --git a/docs/sanic/api/exceptions.rst b/docs/sanic/api/exceptions.rst new file mode 100644 index 00000000..1def3977 --- /dev/null +++ b/docs/sanic/api/exceptions.rst @@ -0,0 +1,16 @@ +Exceptions +========== + +sanic.errorpages +---------------- + +.. automodule:: sanic.errorpages + :members: + :show-inheritance: + +sanic.exceptions +---------------- + +.. automodule:: sanic.exceptions + :members: + :show-inheritance: diff --git a/docs/sanic/api/router.rst b/docs/sanic/api/router.rst new file mode 100644 index 00000000..2c45e951 --- /dev/null +++ b/docs/sanic/api/router.rst @@ -0,0 +1,18 @@ +Routing +======= + +sanic_routing models +-------------------- + +.. autoclass:: sanic_routing.route::Route + :members: + +.. autoclass:: sanic_routing.group::RouteGroup + :members: + +sanic.router +------------ + +.. automodule:: sanic.router + :members: + :show-inheritance: diff --git a/docs/sanic/api/server.rst b/docs/sanic/api/server.rst new file mode 100644 index 00000000..c84d93cb --- /dev/null +++ b/docs/sanic/api/server.rst @@ -0,0 +1,25 @@ +Sanic Server +============ + +sanic.http +---------- + +.. automodule:: sanic.http + :members: + :show-inheritance: + + +sanic.server +------------ + +.. automodule:: sanic.server + :members: + :show-inheritance: + + +sanic.worker +------------ + +.. automodule:: sanic.worker + :members: + :show-inheritance: diff --git a/docs/sanic/api/utility.rst b/docs/sanic/api/utility.rst new file mode 100644 index 00000000..72b412bc --- /dev/null +++ b/docs/sanic/api/utility.rst @@ -0,0 +1,16 @@ +Utility +======= + +sanic.compat +------------ + +.. automodule:: sanic.compat + :members: + :show-inheritance: + +sanic.log +--------- + +.. automodule:: sanic.log + :members: + :show-inheritance: diff --git a/docs/sanic/api_reference.rst b/docs/sanic/api_reference.rst index df369bc2..6e352cd6 100644 --- a/docs/sanic/api_reference.rst +++ b/docs/sanic/api_reference.rst @@ -1,132 +1,13 @@ 📑 API Reference ================ -sanic.app ---------- +.. toctree:: + :maxdepth: 2 -.. automodule:: sanic.app - :members: - :show-inheritance: - :inherited-members: - -sanic.blueprints ----------------- - -.. automodule:: sanic.blueprints - :members: - :show-inheritance: - :inherited-members: - -sanic.blueprint_group ---------------------- - -.. automodule:: sanic.blueprint_group - :members: - :special-members: - - -sanic.compat ------------- - -.. automodule:: sanic.compat - :members: - :show-inheritance: - -sanic.config ------------- - -.. automodule:: sanic.config - :members: - :show-inheritance: - -sanic.cookies -------------- - -.. automodule:: sanic.cookies - :members: - :show-inheritance: - -sanic.errorpages ----------------- - -.. automodule:: sanic.errorpages - :members: - :show-inheritance: - -sanic.exceptions ----------------- - -.. automodule:: sanic.exceptions - :members: - :show-inheritance: - -sanic.handlers --------------- - -.. automodule:: sanic.handlers - :members: - :show-inheritance: - -sanic.http ----------- - -.. automodule:: sanic.http - :members: - :show-inheritance: - -sanic.log ---------- - -.. automodule:: sanic.log - :members: - :show-inheritance: - -sanic.request -------------- - -.. automodule:: sanic.request - :members: - :show-inheritance: - -sanic.response --------------- - -.. automodule:: sanic.response - :members: - :show-inheritance: - -sanic.router ------------- - -.. automodule:: sanic.router - :members: - :show-inheritance: - -sanic.server ------------- - -.. automodule:: sanic.server - :members: - :show-inheritance: - - -sanic.views ------------ - -.. automodule:: sanic.views - :members: - :show-inheritance: - -sanic.websocket ---------------- - -.. automodule:: sanic.websocket - :members: - :show-inheritance: - -sanic.worker ------------- - -.. automodule:: sanic.worker - :members: - :show-inheritance: + api/app + api/blueprints + api/core + api/exceptions + api/router + api/server + api/utility diff --git a/docs/sanic/contributing.rst b/docs/sanic/contributing.rst index 5d21caa2..91cfd11e 100644 --- a/docs/sanic/contributing.rst +++ b/docs/sanic/contributing.rst @@ -1,4 +1,4 @@ ♥️ Contributing -=============== +============== .. include:: ../../CONTRIBUTING.rst diff --git a/sanic/__init__.py b/sanic/__init__.py index 8ba461fd..2b7e7792 100644 --- a/sanic/__init__.py +++ b/sanic/__init__.py @@ -1,6 +1,7 @@ from sanic.__version__ import __version__ from sanic.app import Sanic from sanic.blueprints import Blueprint +from sanic.constants import HTTPMethod from sanic.request import Request from sanic.response import HTTPResponse, html, json, text @@ -9,6 +10,7 @@ __all__ = ( "__version__", "Sanic", "Blueprint", + "HTTPMethod", "HTTPResponse", "Request", "html", diff --git a/sanic/__version__.py b/sanic/__version__.py index 345ed1a9..10703b4c 100644 --- a/sanic/__version__.py +++ b/sanic/__version__.py @@ -1 +1 @@ -__version__ = "21.3.2" +__version__ = "21.6.0" diff --git a/sanic/blueprints.py b/sanic/blueprints.py index 1fa24e88..2431f849 100644 --- a/sanic/blueprints.py +++ b/sanic/blueprints.py @@ -279,8 +279,6 @@ class Blueprint(BaseSanic): app._apply_signal(signal) self.routes = [route for route in routes if isinstance(route, Route)] - - # Deprecate these in 21.6 self.websocket_routes = [ route for route in self.routes if route.ctx.websocket ] diff --git a/sanic/response.py b/sanic/response.py index 9ab110f6..1f1d7fbe 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -143,7 +143,7 @@ class StreamingHTTPResponse(BaseHTTPResponse): .. warning:: - **Deprecated** and set for removal in v21.6. You can now achieve the + **Deprecated** and set for removal in v21.12. You can now achieve the same functionality without a callback. .. code-block:: python @@ -174,12 +174,16 @@ class StreamingHTTPResponse(BaseHTTPResponse): status: int = 200, headers: Optional[Union[Header, Dict[str, str]]] = None, content_type: str = "text/plain; charset=utf-8", - chunked="deprecated", + ignore_deprecation_notice: bool = False, ): - if chunked != "deprecated": + if not ignore_deprecation_notice: warn( - "The chunked argument has been deprecated and will be " - "removed in v21.6" + "Use of the StreamingHTTPResponse is deprecated in v21.6, and " + "will be removed in v21.12. Please upgrade your streaming " + "response implementation. You can learn more here: " + "https://sanicframework.org/en/guide/advanced/streaming.html" + "#response-streaming. If you use the builtin stream() or " + "file_stream() methods, this upgrade will be be done for you." ) super().__init__() @@ -241,6 +245,12 @@ class HTTPResponse(BaseHTTPResponse): async def eof(self): await self.send("", True) + async def __aenter__(self): + return self.send + + async def __aexit__(self, *_): + await self.eof() + def empty( status=204, headers: Optional[Dict[str, str]] = None @@ -402,7 +412,6 @@ async def file_stream( mime_type: Optional[str] = None, headers: Optional[Dict[str, str]] = None, filename: Optional[str] = None, - chunked="deprecated", _range: Optional[Range] = None, ) -> StreamingHTTPResponse: """Return a streaming response object with file data. @@ -415,12 +424,6 @@ async def file_stream( :param chunked: Deprecated :param _range: """ - if chunked != "deprecated": - warn( - "The chunked argument has been deprecated and will be " - "removed in v21.6" - ) - headers = headers or {} if filename: headers.setdefault( @@ -459,6 +462,7 @@ async def file_stream( status=status, headers=headers, content_type=mime_type, + ignore_deprecation_notice=True, ) @@ -467,7 +471,6 @@ def stream( status: int = 200, headers: Optional[Dict[str, str]] = None, content_type: str = "text/plain; charset=utf-8", - chunked="deprecated", ): """Accepts an coroutine `streaming_fn` which can be used to write chunks to a streaming response. Returns a `StreamingHTTPResponse`. @@ -488,17 +491,12 @@ def stream( :param headers: Custom Headers. :param chunked: Deprecated """ - if chunked != "deprecated": - warn( - "The chunked argument has been deprecated and will be " - "removed in v21.6" - ) - return StreamingHTTPResponse( streaming_fn, headers=headers, content_type=content_type, status=status, + ignore_deprecation_notice=True, ) diff --git a/tests/test_response.py b/tests/test_response.py index f9803a41..0676b885 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -224,7 +224,6 @@ def non_chunked_streaming_app(app): sample_streaming_fn, headers={"Content-Length": "7"}, content_type="text/csv", - chunked=False, ) return app @@ -251,11 +250,7 @@ async def test_chunked_streaming_returns_correct_content_asgi(streaming_app): def test_non_chunked_streaming_adds_correct_headers(non_chunked_streaming_app): - with pytest.warns(UserWarning) as record: - request, response = non_chunked_streaming_app.test_client.get("/") - - assert len(record) == 1 - assert "removed in v21.6" in record[0].message.args[0] + request, response = non_chunked_streaming_app.test_client.get("/") assert "Transfer-Encoding" not in response.headers assert response.headers["Content-Type"] == "text/csv"