Merge pull request #4335 from pallets/drop-python-3.6
Before adoption: this commit came in with the history the project adopted, so no landing records it.
drop Python 3.6
authored by David Lord · committed by GitHub · parents 3c36d04, df806c8 · Browse files · 15 files·+178 added−82 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
15 files+178 added−82 removed
- tests:+0 added−13 removed
- other:+178 added−69 removed
Provenance
- Commit
ea93a52- Tree
d007f94- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
3c36d04- Parent 2
df806c8
15 files changed+178 added−82 removed
modified:.github/workflows/tests.yaml-1 removed
29 unmodified lines30313233343435363718 unmodified lines29 unmodified lines - {name: '3.11-dev', python: '3.11-dev', os: ubuntu-latest, tox: py311} - {name: '3.9', python: '3.9', os: ubuntu-latest, tox: py39} - {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38} - {name: '3.7', python: '3.7', os: ubuntu-latest, tox: py37} - {name: '3.6', python: '3.6', os: ubuntu-latest, tox: py36} - {name: 'PyPy', python: 'pypy-3.7', os: ubuntu-latest, tox: pypy37} - {name: Typing, python: '3.10', os: ubuntu-latest, tox: typing} steps: - uses: actions/checkout@v218 unmodified linesmodified:docs/deploying/wsgi-standalone.rst+145 added-36 removed
1-Standalone WSGI Containers2-==========================1+Standalone WSGI Servers2+=======================3 4-There are popular servers written in Python that contain WSGI applications and5-serve HTTP. These servers stand alone when they run; you can proxy to them6-from your web server. Note the section on :ref:`deploying-proxy-setups` if you7-run into issues.4+Most WSGI servers also provide HTTP servers, so they can run a WSGI5+application and make it available externally.6 7+It may still be a good idea to run the server behind a dedicated HTTP8+server such as Apache or Nginx. See :ref:`deploying-proxy-setups` if you9+run into issues with that.10+11+12 Gunicorn13 --------14 12-`Gunicorn`_ 'Green Unicorn' is a WSGI HTTP Server for UNIX. It's a pre-fork13-worker model ported from Ruby's Unicorn project. It supports both `eventlet`_14-and `greenlet`_. Running a Flask application on this server is quite simple::15+`Gunicorn`_ is a WSGI and HTTP server for UNIX. To run a Flask16+application, tell Gunicorn how to import your Flask app object.17 16- $ gunicorn myproject:app18+.. code-block:: text19 18-`Gunicorn`_ provides many command-line options -- see ``gunicorn -h``.19-For example, to run a Flask application with 4 worker processes (``-w20-4``) binding to localhost port 4000 (``-b 127.0.0.1:4000``)::20+ $ gunicorn -w 4 -b 0.0.0.0:5000 your_project:app21 22- $ gunicorn -w 4 -b 127.0.0.1:4000 myproject:app22+The ``-w 4`` option uses 4 workers to handle 4 requests at once. The23+``-b 0.0.0.0:5000`` serves the application on all interfaces on port24+5000.25 24-The ``gunicorn`` command expects the names of your application module or25-package and the application instance within the module. If you use the26-application factory pattern, you can pass a call to that::26+Gunicorn provides many options for configuring the server, either27+through a configuration file or with command line options. Use28+``gunicorn --help`` or see the docs for more information.29 28- $ gunicorn "myproject:create_app()"30+The command expects the name of your module or package to import and31+the application instance within the module. If you use the application32+factory pattern, you can pass a call to that.33 34+.. code-block:: text35+36+ $ gunicorn -w 4 -b 0.0.0.0:5000 "myproject:create_app()"37+38+39+Async with Gevent or Eventlet40+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~41+42+The default sync worker is appropriate for many use cases. If you need43+asynchronous support, Gunicorn provides workers using either `gevent`_44+or `eventlet`_. This is not the same as Python's ``async/await``, or the45+ASGI server spec.46+47+When using either gevent or eventlet, greenlet>=1.0 is required,48+otherwise context locals such as ``request`` will not work as expected.49+When using PyPy, PyPy>=7.3.7 is required.50+51+To use gevent:52+53+.. code-block:: text54+55+ $ gunicorn -k gevent -b 0.0.0.0:5000 your_project:app56+57+To use eventlet:58+59+.. code-block:: text60+61+ $ gunicorn -k eventlet -b 0.0.0.0:5000 your_project:app62+63+64 .. _Gunicorn: https://gunicorn.org/65+.. _gevent: http://www.gevent.org/66 .. _eventlet: https://eventlet.net/67+.. _greenlet: https://greenlet.readthedocs.io/en/latest/68 69 70 uWSGI35---------71+-----72 37-`uWSGI`_ is a fast application server written in C. It is very configurable38-which makes it more complicated to setup than gunicorn.73+`uWSGI`_ is a fast application server written in C. It is very74+configurable, which makes it more complicated to setup than Gunicorn.75+It also provides many other utilities for writing robust web76+applications. To run a Flask application, tell Gunicorn how to import77+your Flask app object.78 40-Running `uWSGI HTTP Router`_::79+.. code-block:: text80 42- $ uwsgi --http 127.0.0.1:5000 --module myproject:app81+ $ uwsgi --master -p 4 --http 0.0.0.0:5000 -w your_project:app82 44-For a more optimized setup, see :doc:`configuring uWSGI and NGINX <uwsgi>`.83+The ``-p 4`` option uses 4 workers to handle 4 requests at once. The84+``--http 0.0.0.0:5000`` serves the application on all interfaces on port85+5000.86 87+uWSGI has optimized integration with Nginx and Apache instead of using88+a standard HTTP proxy. See :doc:`configuring uWSGI and Nginx <uwsgi>`.89+90+91+Async with Gevent92+~~~~~~~~~~~~~~~~~93+94+The default sync worker is appropriate for many use cases. If you need95+asynchronous support, uWSGI provides workers using `gevent`_. It also96+supports other async modes, see the docs for more information. This is97+not the same as Python's ``async/await``, or the ASGI server spec.98+99+When using gevent, greenlet>=1.0 is required, otherwise context locals100+such as ``request`` will not work as expected. When using PyPy,101+PyPy>=7.3.7 is required.102+103+.. code-block:: text104+105+ $ uwsgi --master --gevent 100 --http 0.0.0.0:5000 -w your_project:app106+107 .. _uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/47-.. _uWSGI HTTP Router: https://uwsgi-docs.readthedocs.io/en/latest/HTTP.html#the-uwsgi-http-https-router108 109+110 Gevent50--------111+------112 52-`Gevent`_ is a coroutine-based Python networking library that uses53-`greenlet`_ to provide a high-level synchronous API on top of `libev`_54-event loop::113+Prefer using `Gunicorn`_ with Gevent workers rather than using Gevent114+directly. Gunicorn provides a much more configurable and115+production-tested server. See the section on Gunicorn above.116 117+`Gevent`_ allows writing asynchronous, coroutine-based code that looks118+like standard synchronous Python. It uses `greenlet`_ to enable task119+switching without writing ``async/await`` or using ``asyncio``.120+121+It provides a WSGI server that can handle many connections at once122+instead of one per worker process.123+124+`Eventlet`_, described below, is another library that does the same125+thing. Certain dependencies you have, or other consideration, may affect126+which of the two you choose to use127+128+To use gevent to serve your application, import its ``WSGIServer`` and129+use it to run your ``app``.130+131+.. code-block:: python132+133 from gevent.pywsgi import WSGIServer57- from yourapplication import app134+ from your_project import app135 59- http_server = WSGIServer(('', 5000), app)136+ http_server = WSGIServer(("", 5000), app)137 http_server.serve_forever()138 62-.. _Gevent: http://www.gevent.org/63-.. _greenlet: https://greenlet.readthedocs.io/en/latest/64-.. _libev: http://software.schmorp.de/pkg/libev.html139 140+Eventlet141+--------142+143+Prefer using `Gunicorn`_ with Eventlet workers rather than using144+Eventlet directly. Gunicorn provides a much more configurable and145+production-tested server. See the section on Gunicorn above.146+147+`Eventlet`_ allows writing asynchronous, coroutine-based code that looks148+like standard synchronous Python. It uses `greenlet`_ to enable task149+switching without writing ``async/await`` or using ``asyncio``.150+151+It provides a WSGI server that can handle many connections at once152+instead of one per worker process.153+154+`Gevent`_, described above, is another library that does the same155+thing. Certain dependencies you have, or other consideration, may affect156+which of the two you choose to use157+158+To use eventlet to serve your application, import its ``wsgi.server``159+and use it to run your ``app``.160+161+.. code-block:: python162+163+ import eventlet164+ from eventlet import wsgi165+ from your_project import app166+167+ wsgi.server(eventlet.listen(("", 5000), app)168+169+170 Twisted Web171 -----------172 173 `Twisted Web`_ is the web server shipped with `Twisted`_, a mature,174 non-blocking event-driven networking library. Twisted Web comes with a175 standard WSGI container which can be controlled from the command line using72-the ``twistd`` utility::176+the ``twistd`` utility:177 178+.. code-block:: text179+180 $ twistd web --wsgi myproject.app181 182 This example will run a Flask application called ``app`` from a module named183 ``myproject``.184 185 Twisted Web supports many flags and options, and the ``twistd`` utility does186 as well; see ``twistd -h`` and ``twistd web -h`` for more information. For187 example, to run a Twisted Web server in the foreground, on port 8080, with an82-application from ``myproject``::188+application from ``myproject``:189 190+.. code-block:: text191+192 $ twistd -n web --port tcp:8080 --wsgi myproject.app193 194 .. _Twisted: https://twistedmatrix.com/trac/195 .. _Twisted Web: https://twistedmatrix.com/trac/wiki/TwistedWeb196 197+198 .. _deploying-proxy-setups:199 200 Proxy Setups201 ------------61 unmodified linesmodified:docs/async-await.rst+7 added-2 removed
5 unmodified lines6 .. versionadded:: 2.07 8 Routes, error handlers, before request, after request, and teardown9 functions can all be coroutine functions if Flask is installed with the10-``async`` extra (``pip install flask[async]``). It requires Python 3.7+11-where ``contextvars.ContextVar`` is available. This allows views to be10+``async`` extra (``pip install flask[async]``). This allows views to be11 defined with ``async def`` and use ``await``.12 13 .. code-block:: python14 13 unmodified lines28 Python 3.8 has a bug related to asyncio on Windows. If you encounter29 something like ``ValueError: set_wakeup_fd only works in main thread``,30 please upgrade to Python 3.9.31 32+.. admonition:: Using ``async`` with greenlet33 34+ When using gevent or eventlet to serve an application or patch the35+ runtime, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is36+ required.37+38+39 Performance40 -----------41 42 Async functions require an event loop to run. Flask, as a WSGI89 unmodified linesmodified:docs/cli.rst+3 added-4 removed
110 unmodified lines111 shell with the :func:`shell <cli.shell_command>` command. An application112 context will be active, and the app instance will be imported. ::113 114 $ flask shell115- Python 3.6.2 (default, Jul 20 2017, 03:52:27)116- [GCC 7.1.1 20170630] on linux117- App: example118- Instance: /home/user/Projects/hello/instance115+ Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux116+ App: example [production]117+ Instance: /home/david/Projects/pallets/flask/instance118 >>>119 120 Use :meth:`~Flask.shell_context_processor` to add other automatic imports.121 532 unmodified linesmodified:docs/extensiondev.rst+3 added-3 removed
320 unmodified lines321 6. The documentation must use the ``flask`` theme from the322 `Official Pallets Themes`_. A link to the documentation or project323 website must be in the PyPI metadata or the readme.324 7. For maximum compatibility, the extension should support the same325- versions of Python that Flask supports. 3.6+ is recommended as of326- 2020. Use ``python_requires=">= 3.6"`` in ``setup.py`` to indicate327- supported versions.325+ versions of Python that Flask supports. 3.7+ is recommended as of326+ December 2021. Use ``python_requires=">= 3.7"`` in ``setup.py`` to327+ indicate supported versions.328 329 .. _PyPI: https://pypi.org/search/?c=Framework+%3A%3A+Flask330 .. _mailinglist: https://mail.python.org/mailman/listinfo/flask331 .. _Discord server: https://discord.gg/pallets1 unmodified linemodified:docs/installation.rst+13 added-3 removed
4 unmodified lines5 Python Version6 --------------7 8 We recommend using the latest version of Python. Flask supports Python9-3.6 and newer.9+3.7 and newer.10 11-``async`` support in Flask requires Python 3.7+ for ``contextvars.ContextVar``.11 13-12 Dependencies13 ------------14 15 These distributions will be installed automatically when installing Flask.32 unmodified lines48 .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme49 .. _watchdog: https://pythonhosted.org/watchdog/50 51 52+greenlet53+~~~~~~~~54+55+You may choose to use gevent or eventlet with your application. In this56+case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is57+required.58+59+These are not minimum supported versions, they only indicate the first60+versions that added necessary features. You should use the latest61+versions of each.62+63+64 Virtual environments65 --------------------66 67 Use a virtual environment to manage the dependencies for your project, both in78 unmodified linesmodified:requirements/dev.txt+1 added-1 removed
36 unmodified lines37 filelock==3.3.238 # via39 # tox40 # virtualenv41-greenlet==1.1.241+greenlet==1.1.2 ; python_version < "3.11"42 # via -r requirements/tests.in43 identify==2.3.344 # via pre-commit45 idna==3.3118 unmodified linesmodified:requirements/tests.in+1 added-1 removed
1 pytest2 asgiref3 blinker4-greenlet4+greenlet ; python_version < "3.11"5 python-dotenvmodified:requirements/tests.txt+1 added-1 removed
8 unmodified lines9 attrs==21.2.010 # via pytest11 blinker==1.412 # via -r requirements/tests.in13-greenlet==1.1.213+greenlet==1.1.2 ; python_version < "3.11"14 # via -r requirements/tests.in15 iniconfig==1.1.116 # via pytest17 packaging==21.213 unmodified linesmodified:src/flask/json/__init__.py+1 added-6 removed
1+import dataclasses2 import decimal3 import io4 import json as _json5 import typing as t10 unmodified lines16 if t.TYPE_CHECKING:17 from ..app import Flask18 from ..wrappers import Response19 19-try:20- import dataclasses21-except ImportError:22- # Python < 3.723- dataclasses = None # type: ignore20 25-21 class JSONEncoder(_json.JSONEncoder):22 """The default JSON encoder. Handles extra types compared to the23 built-in :class:`json.JSONEncoder`.24 328 unmodified linesmodified:src/flask/app.py-8 removed
14 unmodified lines15 from werkzeug.exceptions import BadRequest16 from werkzeug.exceptions import BadRequestKeyError17 from werkzeug.exceptions import HTTPException18 from werkzeug.exceptions import InternalServerError19-from werkzeug.local import ContextVar19 from werkzeug.routing import BuildError20 from werkzeug.routing import Map21 from werkzeug.routing import MapAdapter22 from werkzeug.routing import RequestRedirect1596 unmodified lines1619 raise RuntimeError(1620 "Install Flask with the 'async' extra in order to use async views."1621 ) from None1622 1624- # Check that Werkzeug isn't using its fallback ContextVar class.1625- if ContextVar.__module__ == "werkzeug.local":1626- raise RuntimeError(1627- "Async cannot be used with this combination of Python "1628- "and Greenlet versions."1629- )1630-1623 return asgiref_async_to_sync(func)1624 1625 def make_response(self, rv: ResponseReturnValue) -> Response:1626 """Convert the return value from a view function to an instance of457 unmodified linesmodified:tests/test_async.py-11 removed
1 import asyncio2-import sys2 3 import pytest4 5 from flask import Blueprint71 unmodified lines77 78 return app79 80 82-@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")81 @pytest.mark.parametrize("path", ["/", "/home", "/bp/", "/view", "/methodview"])82 def test_async_route(path, async_app):83 test_client = async_app.test_client()84 response = test_client.get(path)1 unmodified line86 response = test_client.post(path)87 assert b"POST" in response.get_data()88 89 92-@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")90 @pytest.mark.parametrize("path", ["/error", "/bp/error"])91 def test_async_error_handler(path, async_app):92 test_client = async_app.test_client()93 response = test_client.get(path)94 assert response.status_code == 41295 96 100-@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")97 def test_async_before_after_request():98 app_first_called = False99 app_before_called = False100 app_after_called = False48 unmodified lines149 assert app_after_called150 test_client.get("/bp/")151 assert bp_before_called152 assert bp_after_called157-158-159-@pytest.mark.skipif(sys.version_info >= (3, 7), reason="should only raise Python < 3.7")160-def test_async_runtime_error():161- app = Flask(__name__)162- with pytest.raises(RuntimeError):163- app.async_to_sync(None)modified:tests/test_basic.py-2 removed
1 import gc2 import re3-import sys3 import time4 import uuid5 import weakref6 from datetime import datetime1314 unmodified lines1321 rv = flask.make_response(flask.jsonify(msg), 200)1322 assert rv.mimetype == "application/vnd.api+json"1323 1324 1326-@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python >= 3.7")1325 def test_json_dump_dataclass(app, req_ctx):1326 from dataclasses import make_dataclass1327 1328 Data = make_dataclass("Data", [("name", str)])698 unmodified linesmodified:setup.cfg+2 added-2 removed
33 unmodified lines34 [options]35 packages = find:36 package_dir = = src37 include_package_data = true38-python_requires = >= 3.638+python_requires = >= 3.739 # Dependencies are in setup.py for GitHub's dependency graph.40 41 [options.packages.find]42 where = src44 unmodified lines87 src/flask/__init__.py: F40188 89 [mypy]90 files = src/flask91-python_version = 3.691+python_version = 3.792 allow_redefinition = True93 disallow_subclassing_any = True94 # disallow_untyped_calls = True95 # disallow_untyped_defs = True22 unmodified linesmodified:tox.ini+1 added-1 removed
1 [tox]2 envlist =3- py3{11,10,9,8,7,6},pypy373+ py3{11,10,9,8,7},pypy3{8,7}4 py39-click75 style6 typing7 docs24 unmodified lines