diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f63084aa..25445e84 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,211 @@ +Version 21.3.0 +-------------- + +`Release Notes `_ + +Features +******** + + * + `#1876 `_ + Unified streaming server + + * + `#2005 `_ + New ``Request.id`` property + + * + `#2008 `_ + Allow Pathlib Path objects to be passed to ``app.static()`` helper + + * + `#2010 `_, `#2031 `_ + New startup-optimized router + + * + `#2018 `_ + `#2064 `_ + Listeners for main server process + + * + `#2032 `_ + Add raw header info to request object + + * + `#2042 `_ + `#2060 `_ + `#2061 `_ + Introduce Signals API + + * + `#2043 `_ + Add ``__str__`` and ``__repr__`` to Sanic and Blueprint + + * + `#2047 `_ + Enable versioning and strict slash on BlueprintGroup + + * + `#2053 `_ + Make ``get_app`` name argument optional + + * + `#2055 `_ + JSON encoder change via app + + * + `#2063 `_ + App and connection level context objects + +Bugfixes and issues resolved +**************************** + + * Resolve `#1420 `_ + ``url_for`` where ``strict_slashes`` are on for a path ending in ``/`` + * Resolve `#1525 `_ + Routing is incorrect with some special characters + * Resolve `#1653 `_ + ASGI headers in body + * Resolve `#1722 `_ + Using curl in chunk mode + * Resolve `#1730 `_ + Extra content in ASGI streaming response + * Resolve `#1749 `_ + Restore broken middleware edge cases + * Resolve `#1785 `_ + `#1804 `_ + Synchronous error handlers + * Resolve `#1790 `_ + Protocol errors did not support async error handlers #1790 + * Resolve `#1824 `_ + Timeout on specific methods + * Resolve `#1875 `_ + Response timeout error from all routes after returning several timeouts from a specific route + * Resolve `#1988 `_ + Handling of safe methods with body + + * + `#2001 `_ + Raise ValueError when cookie max-age is not an integer + +Deprecations and Removals +************************* + + * + `#2007 `_ + * Config using ``from_envvar`` + * Config using ``from_pyfile`` + * Config using ``from_object`` + * + `#2009 `_ + Remove Sanic test client to its own package + + * + `#2036 `_, + `#2037 `_ + Drop Python 3.6 support + + * ``Request.endpoint`` deprecated in favor of ``Request.name`` + * handler type name prefixes removed (static, websocket, etc) + +Developer infrastructure +************************ + + * + `#1995 `_ + Create FUNDING.yml + + * + `#2013 `_ + Add codeql to CI pipeline + + * + `#2038 `_ + Codecov configuration updates + + * + `#2049 `_ + Updated setup.py to use ``find_packages`` + +Improved Documentation +********************** + + * + `#1218 `_ + Documentation for sanic.log.* is missing + + * + `#1608 `_ + Add documentation on calver and LTS + + * + `#1731 `_ + Support mounting application elsewhere than at root path + + * + `#2006 `_ + Upgraded type annotations and improved docstrings and API documentation + + * + `#2052 `_ + Fix some examples and docs + +Miscellaneous +************* + + * ``Request.route`` property + * Better websocket subprotocols support + * Resolve bug with middleware in Blueprint Group when passed callable + * Moves common logic between Blueprint and Sanic into mixins + * Route naming changed to be more consistent + * request endpoint is the route name + * route names are fully namespaced + * Some new convenience decorators: + * ``@app.main_process_start`` + * ``@app.main_process_stop`` + * ``@app.before_server_start`` + * ``@app.after_server_start`` + * ``@app.before_server_stop`` + * ``@app.after_server_stop`` + * ``@app.on_request`` + * ``@app.on_response`` + * Fixes ``Allow`` header that did not include ``HEAD`` + * Using "name" keyword in ``url_for`` for a "static" route where name does not exist + * Cannot have multiple ``app.static()`` without using the named param + * Using "filename" keyword in ``url_for`` on a file route + * ``unquote`` in route def (not automatic) + * ``routes_all`` is tuples + * Handler arguments are kwarg only + * ``request.match_info`` is now a cached (and not computed) property + * Unknown static file mimetype is sent as ``application/octet-stream`` + * ``_host`` keyword in ``url_for`` + * Add charset default to ``utf-8`` for text and js content types if not specified + * Version for a route can be str, float, or int + * Route has ctx property + * App has ``routes_static``, ``routes_dynamic``, ``routes_regex`` + + * + `#2044 `_ + Code cleanup and refactoring + * + `#2072 `_ + Remove ``BaseSanic`` metaclass + * + `#2074 `_ + Performance adjustments in ``handle_request_`` + +Version 20.12.3 +--------------- + +Bugfixes +******** + + * + `#2021 `_ + Remove prefix from websocket handler name + Version 20.12.2 -=============== +--------------- Dependencies ************ @@ -13,7 +219,7 @@ Dependencies Remove old chardet requirement, add in hard multidict requirement Version 19.12.5 -=============== +--------------- Dependencies ************ @@ -27,7 +233,7 @@ Dependencies Remove old chardet requirement, add in hard multidict requirement Version 20.12.0 -=============== +--------------- Features ******** @@ -37,7 +243,7 @@ Features Add disable app registry Version 20.12.0 -=============== +--------------- Features ******** @@ -124,7 +330,7 @@ Improved Documentation Version 20.9.1 -=============== +--------------- Bugfixes ******** @@ -138,7 +344,7 @@ Bugfixes Version 19.12.3 -=============== +--------------- Bugfixes ******** @@ -149,7 +355,7 @@ Bugfixes Version 20.9.0 -=============== +--------------- Features @@ -219,7 +425,7 @@ Improved Documentation Version 20.6.3 -=============== +--------------- Bugfixes ******** @@ -230,7 +436,7 @@ Bugfixes Version 20.6.2 -=============== +--------------- Features ******** @@ -241,7 +447,7 @@ Features Version 20.6.1 -=============== +--------------- Features ******** @@ -317,13 +523,13 @@ Improved Documentation Version 20.6.0 -=============== +--------------- *Released, but unintentionally ommitting PR #1880, so was replaced by 20.6.1* Version 20.3.0 -=============== +--------------- Features ******** @@ -454,7 +660,7 @@ Improved Documentation Version 19.12.0 -=============== +--------------- Bugfixes ******** @@ -489,7 +695,7 @@ Improved Documentation Version 19.6.3 -============== +-------------- Features ******** @@ -512,7 +718,7 @@ Improved Documentation Version 19.6.2 -============== +-------------- Features ******** @@ -573,7 +779,7 @@ Deprecations and Removals Version 19.3 -============ +------------ Features ******** @@ -711,7 +917,7 @@ Improved Documentation Note: 19.3.0 was skipped for packagement purposes and not released on PyPI Version 18.12 -============= +------------- 18.12.0 ******* @@ -756,7 +962,7 @@ Version 18.12 * Fix document for logging Version 0.8 -=========== +----------- 0.8.3 ***** @@ -843,7 +1049,7 @@ Version 0.8 Note: Changelog was unmaintained between 0.1 and 0.7 Version 0.1 -=========== +----------- 0.1.7 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b08a60db..4d8263b8 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -1,20 +1,17 @@ - -Contributing -============ - Thank you for your interest! Sanic is always looking for contributors. If you -don't feel comfortable contributing code, adding docstrings to the source files -is very appreciated. +don't feel comfortable contributing code, adding docstrings to the source files, +or helping with the `Sanic User Guide `_ +by providing documentation or implementation examples would be appreciated! We are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, disability, ethnicity, religion, or similar personal characteristic. -Our `code of conduct <./CONDUCT.md>`_ sets the standards for behavior. +Our `code of conduct `_ sets the standards for behavior. Installation ------------ -To develop on sanic (and mainly to just run the tests) it is highly recommend to +To develop on Sanic (and mainly to just run the tests) it is highly recommend to install from sources. So assume you have already cloned the repo and are in the working directory with @@ -89,6 +86,17 @@ Permform ``flake8``\ , ``black`` and ``isort`` checks. tox -e lint +Run type annotation checks +--------------- + +``tox`` environment -> ``[testenv:type-checking]`` + +Permform ``mypy`` checks. + +.. code-block:: bash + + tox -e type-checking + Run other checks ---------------- @@ -161,6 +169,12 @@ flake8 ``isort``\ , ``black`` and ``flake8`` checks are performed during ``tox`` lint checks. +The **easiest** way to make your code conform is to run the following before committing. + +.. code-block:: bash + + make pretty + Refer `tox `_ documentation for more details. Pull requests @@ -168,12 +182,13 @@ Pull requests So the pull request approval rules are pretty simple: -#. All pull requests must have a changelog details associated with it. #. All pull requests must pass unit tests. -#. All pull requests must be reviewed and approved by at least one current collaborator on the project. +#. All pull requests must be reviewed and approved by at least one current member of the Core Developer team. #. All pull requests must pass flake8 checks. +#. All pull requests must match ``isort`` and ``black`` requirements. +#. All pull requests must be **PROPERLY** type annotated, unless exemption is given. #. All pull requests must be consistent with the existing code. -#. If you decide to remove/change anything from any common interface a deprecation message should accompany it. +#. If you decide to remove/change anything from any common interface a deprecation message should accompany it in accordance with our `deprecation policy `_. #. If you implement a new feature you should have at least one unit test to accompany it. #. An example must be one of the following: @@ -182,56 +197,14 @@ So the pull request approval rules are pretty simple: * Example of how to use Sanic and asynchronous library -Changelog ---------- - -It is mandatory to add documentation for Change log as part of your Pull request when you fix/contribute something -to the ``sanic`` community. This will enable us in generating better and well defined change logs during the -release which can aid community users in a great way. - -.. note:: - - Single line explaining the details of the PR in brief - - Detailed description of what the PR is about and what changes or enhancements are being done. - No need to include examples or any other details here. But it is important that you provide - enough context here to let user understand what this change is all about and why it is being - introduced into the ``sanic`` codebase. - - Make sure you leave an line space after the first line to make sure the document rendering is clean - - -.. list-table:: - :header-rows: 1 - - * - Contribution Type - - Changelog file name format - - Changelog file location - * - Features - - .feature.rst - - ``changelogs`` - * - Bugfixes - - .bugfix.rst - - ``changelogs`` - * - Improved Documentation - - .doc.rst - - ``changelogs`` - * - Deprecations and Removals - - .removal.rst - - ``changelogs`` - * - Miscellaneous internal changes - - .misc.rst - - ``changelogs`` - - Documentation ------------- -Sanic's documentation is built -using `sphinx `_. Guides are written in -Markdown and can be found in the ``docs`` folder, while the module reference is +Sanic's API documentation is built using `sphinx `_ with module references automatically generated using ``sphinx-apidoc``. +The User Guide is in the `sanic-guide `_ repository. + To generate the documentation from scratch: .. code-block:: bash @@ -245,6 +218,14 @@ To generate the documentation from scratch: The HTML documentation will be created in the ``docs/_build`` folder. +You can run the following to have a live development server with the API documents + +.. code-block:: bash + + make docs-serve + +Refer to the User Guide repo for documentation on how to contribute there. + .. warning:: One of the main goals of Sanic is speed. Code that lowers the performance of Sanic without significant gains in usability, security, or features may not be diff --git a/README.rst b/README.rst index 96f5b217..8e7087eb 100644 --- a/README.rst +++ b/README.rst @@ -66,7 +66,7 @@ Sanic is a **Python 3.7+** web server and web framework that's written to go fas Sanic is also ASGI compliant, so you can deploy it with an `alternative ASGI webserver `_. -`Source code on GitHub `_ | `Help and discussion board `_ | `User Guide `_ +`Source code on GitHub `_ | `Help and discussion board `_ | `User Guide `_ | `Chat on Discord `_ The project is maintained by the community, for the community. **Contributions are welcome!** @@ -125,13 +125,13 @@ Hello World Example return json({'hello': 'world'}) if __name__ == '__main__': - app.run(host='0.0.0.0', port=8000) + app.run() Sanic can now be easily run using ``sanic hello.app``. .. code:: - [2018-12-30 11:37:41 +0200] [13564] [INFO] Goin' Fast @ http://0.0.0.0:8000 + [2018-12-30 11:37:41 +0200] [13564] [INFO] Goin' Fast @ http://127.0.0.1:8000 [2018-12-30 11:37:41 +0200] [13564] [INFO] Starting worker [13564] And, we can verify it is working: ``curl localhost:8000 -i`` @@ -153,18 +153,18 @@ Minimum Python version is 3.7. If you need Python 3.6 support, please use v20.12 Documentation ------------- -`User Guide `_ and `API Documentation `_. +`User Guide `__ and `API Documentation `__. Changelog --------- -`Release Changelogs `_. +`Release Changelogs `__. Questions and Discussion ------------------------ -`Ask a question or join the conversation `_. +`Ask a question or join the conversation `__. Contribution ------------ diff --git a/docs/index.rst b/docs/index.rst index a3ec5cae..34e0e006 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,18 +3,21 @@ User Guide ========== -To learn about using Sanic, checkout the `User Guide `_. +To learn about using Sanic, checkout the `User Guide `__. API -====== +=== .. toctree:: - :maxdepth: 4 + :maxdepth: 2 👥 User Guide sanic/api_reference 💻 Source code + sanic/changelog + sanic/contributing ❓ Support + 💬 Chat Module Documentation diff --git a/docs/sanic/changelog.rst b/docs/sanic/changelog.rst new file mode 100644 index 00000000..fb389e05 --- /dev/null +++ b/docs/sanic/changelog.rst @@ -0,0 +1,4 @@ +📜 Changelog +============ + +.. include:: ../../CHANGELOG.rst diff --git a/docs/sanic/contributing.rst b/docs/sanic/contributing.rst new file mode 100644 index 00000000..5d21caa2 --- /dev/null +++ b/docs/sanic/contributing.rst @@ -0,0 +1,4 @@ +♥️ Contributing +=============== + +.. include:: ../../CONTRIBUTING.rst diff --git a/examples/http_redirect.py b/examples/http_redirect.py new file mode 100644 index 00000000..2e38eb92 --- /dev/null +++ b/examples/http_redirect.py @@ -0,0 +1,51 @@ +from sanic import Sanic, response, text + + +HTTP_PORT = 9999 +HTTPS_PORT = 8888 + +http = Sanic("http") +http.config.SERVER_NAME = f"localhost:{HTTP_PORT}" +https = Sanic("https") +https.config.SERVER_NAME = f"localhost:{HTTPS_PORT}" + + +@https.get("/foo") +def foo(request): + return text("foo") + + +@https.get("/bar") +def bar(request): + return text("bar") + + +@http.get("/") +def proxy(request, path): + url = request.app.url_for( + "proxy", + path=path, + _server=https.config.SERVER_NAME, + _external=True, + _scheme="http", + ) + return response.redirect(url) + + +@https.listener("main_process_start") +async def start(app, _): + global http + app.http_server = await http.create_server( + port=HTTP_PORT, return_asyncio_server=True + ) + app.http_server.after_start() + + +@https.listener("main_process_stop") +async def stop(app, _): + app.http_server.before_stop() + await app.http_server.close() + app.http_server.after_stop() + + +https.run(port=HTTPS_PORT, debug=True) diff --git a/sanic/__version__.py b/sanic/__version__.py index b173ca0c..7cd09f62 100644 --- a/sanic/__version__.py +++ b/sanic/__version__.py @@ -1 +1 @@ -__version__ = "21.3.0a1" +__version__ = "21.3.0"