forked from orbit-oss/flask
Merge pull request #4947 from pallets/pyproject
switch to pyproject.toml
This commit is contained in:
commit
78b42b9ac2
32 changed files with 282 additions and 341 deletions
27
.flake8
Normal file
27
.flake8
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
[flake8]
|
||||||
|
extend-select =
|
||||||
|
# bugbear
|
||||||
|
B
|
||||||
|
# bugbear opinions
|
||||||
|
B9
|
||||||
|
# implicit str concat
|
||||||
|
ISC
|
||||||
|
extend-ignore =
|
||||||
|
# slice notation whitespace, invalid
|
||||||
|
E203
|
||||||
|
# import at top, too many circular import fixes
|
||||||
|
E402
|
||||||
|
# line length, handled by bugbear B950
|
||||||
|
E501
|
||||||
|
# bare except, handled by bugbear B001
|
||||||
|
E722
|
||||||
|
# zip with strict=, requires python >= 3.10
|
||||||
|
B905
|
||||||
|
# string formatting opinion, B028 renamed to B907
|
||||||
|
B028
|
||||||
|
B907
|
||||||
|
# up to 88 allowed by bugbear B950
|
||||||
|
max-line-length = 80
|
||||||
|
per-file-ignores =
|
||||||
|
# __init__ exports names
|
||||||
|
src/flask/__init__.py: F401
|
||||||
2
.github/workflows/tests.yaml
vendored
2
.github/workflows/tests.yaml
vendored
|
|
@ -52,7 +52,7 @@ jobs:
|
||||||
uses: actions/cache@v3.2.2
|
uses: actions/cache@v3.2.2
|
||||||
with:
|
with:
|
||||||
path: ./.mypy_cache
|
path: ./.mypy_cache
|
||||||
key: mypy|${{ matrix.python }}|${{ hashFiles('setup.cfg') }}
|
key: mypy|${{ matrix.python }}|${{ hashFiles('pyproject.toml') }}
|
||||||
if: matrix.tox == 'typing'
|
if: matrix.tox == 'typing'
|
||||||
- run: pip install tox
|
- run: pip install tox
|
||||||
- run: tox run -e ${{ matrix.tox }}
|
- run: tox run -e ${{ matrix.tox }}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ Version 2.3.0
|
||||||
|
|
||||||
Unreleased
|
Unreleased
|
||||||
|
|
||||||
|
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
|
||||||
|
:pr:`4947`
|
||||||
- Ensure subdomains are applied with nested blueprints. :issue:`4834`
|
- Ensure subdomains are applied with nested blueprints. :issue:`4834`
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,14 +102,14 @@ First time setup
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ python3 -m venv env
|
$ python3 -m venv .venv
|
||||||
$ . env/bin/activate
|
$ . .venv/bin/activate
|
||||||
|
|
||||||
- Windows
|
- Windows
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
> py -3 -m venv env
|
> py -3 -m venv .venv
|
||||||
> env\Scripts\activate
|
> env\Scripts\activate
|
||||||
|
|
||||||
- Upgrade pip and setuptools.
|
- Upgrade pip and setuptools.
|
||||||
|
|
|
||||||
41
docs/cli.rst
41
docs/cli.rst
|
|
@ -280,25 +280,25 @@ script. Activating the virtualenv will set the variables.
|
||||||
|
|
||||||
.. group-tab:: Bash
|
.. group-tab:: Bash
|
||||||
|
|
||||||
Unix Bash, :file:`venv/bin/activate`::
|
Unix Bash, :file:`.venv/bin/activate`::
|
||||||
|
|
||||||
$ export FLASK_APP=hello
|
$ export FLASK_APP=hello
|
||||||
|
|
||||||
.. group-tab:: Fish
|
.. group-tab:: Fish
|
||||||
|
|
||||||
Fish, :file:`venv/bin/activate.fish`::
|
Fish, :file:`.venv/bin/activate.fish`::
|
||||||
|
|
||||||
$ set -x FLASK_APP hello
|
$ set -x FLASK_APP hello
|
||||||
|
|
||||||
.. group-tab:: CMD
|
.. group-tab:: CMD
|
||||||
|
|
||||||
Windows CMD, :file:`venv\\Scripts\\activate.bat`::
|
Windows CMD, :file:`.venv\\Scripts\\activate.bat`::
|
||||||
|
|
||||||
> set FLASK_APP=hello
|
> set FLASK_APP=hello
|
||||||
|
|
||||||
.. group-tab:: Powershell
|
.. group-tab:: Powershell
|
||||||
|
|
||||||
Windows Powershell, :file:`venv\\Scripts\\activate.ps1`::
|
Windows Powershell, :file:`.venv\\Scripts\\activate.ps1`::
|
||||||
|
|
||||||
> $env:FLASK_APP = "hello"
|
> $env:FLASK_APP = "hello"
|
||||||
|
|
||||||
|
|
@ -438,24 +438,16 @@ Plugins
|
||||||
|
|
||||||
Flask will automatically load commands specified in the ``flask.commands``
|
Flask will automatically load commands specified in the ``flask.commands``
|
||||||
`entry point`_. This is useful for extensions that want to add commands when
|
`entry point`_. This is useful for extensions that want to add commands when
|
||||||
they are installed. Entry points are specified in :file:`setup.py` ::
|
they are installed. Entry points are specified in :file:`pyproject.toml`:
|
||||||
|
|
||||||
from setuptools import setup
|
.. code-block:: toml
|
||||||
|
|
||||||
setup(
|
|
||||||
name='flask-my-extension',
|
|
||||||
...,
|
|
||||||
entry_points={
|
|
||||||
'flask.commands': [
|
|
||||||
'my-command=flask_my_extension.commands:cli'
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
[project.entry-points."flask.commands"]
|
||||||
|
my-command = "my_extension.commands:cli"
|
||||||
|
|
||||||
.. _entry point: https://packaging.python.org/tutorials/packaging-projects/#entry-points
|
.. _entry point: https://packaging.python.org/tutorials/packaging-projects/#entry-points
|
||||||
|
|
||||||
Inside :file:`flask_my_extension/commands.py` you can then export a Click
|
Inside :file:`my_extension/commands.py` you can then export a Click
|
||||||
object::
|
object::
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
@ -493,19 +485,12 @@ Create an instance of :class:`~cli.FlaskGroup` and pass it the factory::
|
||||||
def cli():
|
def cli():
|
||||||
"""Management script for the Wiki application."""
|
"""Management script for the Wiki application."""
|
||||||
|
|
||||||
Define the entry point in :file:`setup.py`::
|
Define the entry point in :file:`pyproject.toml`:
|
||||||
|
|
||||||
from setuptools import setup
|
.. code-block:: toml
|
||||||
|
|
||||||
setup(
|
[project.scripts]
|
||||||
name='flask-my-extension',
|
wiki = "wiki:cli"
|
||||||
...,
|
|
||||||
entry_points={
|
|
||||||
'console_scripts': [
|
|
||||||
'wiki=wiki:cli'
|
|
||||||
],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
Install the application in the virtualenv in editable mode and the custom
|
Install the application in the virtualenv in editable mode and the custom
|
||||||
script is available. Note that you don't need to set ``--app``. ::
|
script is available. Note that you don't need to set ``--app``. ::
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ Create a virtualenv, install your application, then install
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ cd hello-app
|
$ cd hello-app
|
||||||
$ python -m venv venv
|
$ python -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install . # install your application
|
$ pip install . # install your application
|
||||||
$ pip install eventlet
|
$ pip install eventlet
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ Create a virtualenv, install your application, then install ``gevent``.
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ cd hello-app
|
$ cd hello-app
|
||||||
$ python -m venv venv
|
$ python -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install . # install your application
|
$ pip install . # install your application
|
||||||
$ pip install gevent
|
$ pip install gevent
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ Create a virtualenv, install your application, then install
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ cd hello-app
|
$ cd hello-app
|
||||||
$ python -m venv venv
|
$ python -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install . # install your application
|
$ pip install . # install your application
|
||||||
$ pip install gunicorn
|
$ pip install gunicorn
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ Create a virtualenv, install your application, then install
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ cd hello-app
|
$ cd hello-app
|
||||||
$ python -m venv venv
|
$ python -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install . # install your application
|
$ pip install . # install your application
|
||||||
$ pip install mod_wsgi
|
$ pip install mod_wsgi
|
||||||
|
|
||||||
|
|
@ -89,6 +89,6 @@ mod_wsgi to drop to that user after starting.
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ sudo /home/hello/venv/bin/mod_wsgi-express start-server \
|
$ sudo /home/hello/.venv/bin/mod_wsgi-express start-server \
|
||||||
/home/hello/wsgi.py \
|
/home/hello/wsgi.py \
|
||||||
--user hello --group hello --port 80 --processes 4
|
--user hello --group hello --port 80 --processes 4
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ Create a virtualenv, install your application, then install ``pyuwsgi``.
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ cd hello-app
|
$ cd hello-app
|
||||||
$ python -m venv venv
|
$ python -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install . # install your application
|
$ pip install . # install your application
|
||||||
$ pip install pyuwsgi
|
$ pip install pyuwsgi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ Create a virtualenv, install your application, then install
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ cd hello-app
|
$ cd hello-app
|
||||||
$ python -m venv venv
|
$ python -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install . # install your application
|
$ pip install . # install your application
|
||||||
$ pip install waitress
|
$ pip install waitress
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ environments.
|
||||||
Create an environment
|
Create an environment
|
||||||
~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Create a project folder and a :file:`venv` folder within:
|
Create a project folder and a :file:`.venv` folder within:
|
||||||
|
|
||||||
.. tabs::
|
.. tabs::
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ Create a project folder and a :file:`venv` folder within:
|
||||||
|
|
||||||
$ mkdir myproject
|
$ mkdir myproject
|
||||||
$ cd myproject
|
$ cd myproject
|
||||||
$ python3 -m venv venv
|
$ python3 -m venv .venv
|
||||||
|
|
||||||
.. group-tab:: Windows
|
.. group-tab:: Windows
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ Create a project folder and a :file:`venv` folder within:
|
||||||
|
|
||||||
> mkdir myproject
|
> mkdir myproject
|
||||||
> cd myproject
|
> cd myproject
|
||||||
> py -3 -m venv venv
|
> py -3 -m venv .venv
|
||||||
|
|
||||||
|
|
||||||
.. _install-activate-env:
|
.. _install-activate-env:
|
||||||
|
|
@ -119,13 +119,13 @@ Before you work on your project, activate the corresponding environment:
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
|
|
||||||
.. group-tab:: Windows
|
.. group-tab:: Windows
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
> venv\Scripts\activate
|
> .venv\Scripts\activate
|
||||||
|
|
||||||
Your shell prompt will change to show the name of the activated
|
Your shell prompt will change to show the name of the activated
|
||||||
environment.
|
environment.
|
||||||
|
|
|
||||||
|
|
@ -42,19 +42,20 @@ You should then end up with something like that::
|
||||||
But how do you run your application now? The naive ``python
|
But how do you run your application now? The naive ``python
|
||||||
yourapplication/__init__.py`` will not work. Let's just say that Python
|
yourapplication/__init__.py`` will not work. Let's just say that Python
|
||||||
does not want modules in packages to be the startup file. But that is not
|
does not want modules in packages to be the startup file. But that is not
|
||||||
a big problem, just add a new file called :file:`setup.py` next to the inner
|
a big problem, just add a new file called :file:`pyproject.toml` next to the inner
|
||||||
:file:`yourapplication` folder with the following contents::
|
:file:`yourapplication` folder with the following contents:
|
||||||
|
|
||||||
from setuptools import setup
|
.. code-block:: toml
|
||||||
|
|
||||||
setup(
|
[project]
|
||||||
name='yourapplication',
|
name = "yourapplication"
|
||||||
packages=['yourapplication'],
|
dependencies = [
|
||||||
include_package_data=True,
|
"flask",
|
||||||
install_requires=[
|
]
|
||||||
'flask',
|
|
||||||
],
|
[build-system]
|
||||||
)
|
requires = ["setuptools"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
Install your application so it is importable:
|
Install your application so it is importable:
|
||||||
|
|
||||||
|
|
@ -98,7 +99,7 @@ And this is what :file:`views.py` would look like::
|
||||||
You should then end up with something like that::
|
You should then end up with something like that::
|
||||||
|
|
||||||
/yourapplication
|
/yourapplication
|
||||||
setup.py
|
pyproject.toml
|
||||||
/yourapplication
|
/yourapplication
|
||||||
__init__.py
|
__init__.py
|
||||||
views.py
|
views.py
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,13 @@ application.
|
||||||
Build and Install
|
Build and Install
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
When you want to deploy your application elsewhere, you build a
|
When you want to deploy your application elsewhere, you build a *wheel*
|
||||||
distribution file. The current standard for Python distribution is the
|
(``.whl``) file. Install and use the ``build`` tool to do this.
|
||||||
*wheel* format, with the ``.whl`` extension. Make sure the wheel library
|
|
||||||
is installed first:
|
|
||||||
|
|
||||||
.. code-block:: none
|
.. code-block:: none
|
||||||
|
|
||||||
$ pip install wheel
|
$ pip install build
|
||||||
|
$ python -m build --wheel
|
||||||
Running ``setup.py`` with Python gives you a command line tool to issue
|
|
||||||
build-related commands. The ``bdist_wheel`` command will build a wheel
|
|
||||||
distribution file.
|
|
||||||
|
|
||||||
.. code-block:: none
|
|
||||||
|
|
||||||
$ python setup.py bdist_wheel
|
|
||||||
|
|
||||||
You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. The
|
You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. The
|
||||||
file name is in the format of {project name}-{version}-{python tag}
|
file name is in the format of {project name}-{version}-{python tag}
|
||||||
|
|
@ -54,7 +45,7 @@ create the database in the instance folder.
|
||||||
|
|
||||||
When Flask detects that it's installed (not in editable mode), it uses
|
When Flask detects that it's installed (not in editable mode), it uses
|
||||||
a different directory for the instance folder. You can find it at
|
a different directory for the instance folder. You can find it at
|
||||||
``venv/var/flaskr-instance`` instead.
|
``.venv/var/flaskr-instance`` instead.
|
||||||
|
|
||||||
|
|
||||||
Configure the Secret Key
|
Configure the Secret Key
|
||||||
|
|
@ -77,7 +68,7 @@ Create the ``config.py`` file in the instance folder, which the factory
|
||||||
will read from if it exists. Copy the generated value into it.
|
will read from if it exists. Copy the generated value into it.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:caption: ``venv/var/flaskr-instance/config.py``
|
:caption: ``.venv/var/flaskr-instance/config.py``
|
||||||
|
|
||||||
SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'
|
SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
Make the Project Installable
|
Make the Project Installable
|
||||||
============================
|
============================
|
||||||
|
|
||||||
Making your project installable means that you can build a
|
Making your project installable means that you can build a *wheel* file and install that
|
||||||
*distribution* file and install that in another environment, just like
|
in another environment, just like you installed Flask in your project's environment.
|
||||||
you installed Flask in your project's environment. This makes deploying
|
This makes deploying your project the same as installing any other library, so you're
|
||||||
your project the same as installing any other library, so you're using
|
using all the standard Python tools to manage everything.
|
||||||
all the standard Python tools to manage everything.
|
|
||||||
|
|
||||||
Installing also comes with other benefits that might not be obvious from
|
Installing also comes with other benefits that might not be obvious from
|
||||||
the tutorial or as a new Python user, including:
|
the tutorial or as a new Python user, including:
|
||||||
|
|
@ -28,31 +27,25 @@ the tutorial or as a new Python user, including:
|
||||||
Describe the Project
|
Describe the Project
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
The ``setup.py`` file describes your project and the files that belong
|
The ``pyproject.toml`` file describes your project and how to build it.
|
||||||
to it.
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: toml
|
||||||
:caption: ``setup.py``
|
:caption: ``pyproject.toml``
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
[project]
|
||||||
|
name = "flaskr"
|
||||||
|
version = "1.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"flask",
|
||||||
|
]
|
||||||
|
|
||||||
setup(
|
[build-system]
|
||||||
name='flaskr',
|
requires = ["setuptools"]
|
||||||
version='1.0.0',
|
build-backend = "setuptools.build_meta"
|
||||||
packages=find_packages(),
|
|
||||||
include_package_data=True,
|
|
||||||
install_requires=[
|
|
||||||
'flask',
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
``packages`` tells Python what package directories (and the Python files
|
The setuptools build backend needs another file named ``MANIFEST.in`` to tell it about
|
||||||
they contain) to include. ``find_packages()`` finds these directories
|
non-Python files to include.
|
||||||
automatically so you don't have to type them out. To include other
|
|
||||||
files, such as the static and templates directories,
|
|
||||||
``include_package_data`` is set. Python needs another file named
|
|
||||||
``MANIFEST.in`` to tell what this other data is.
|
|
||||||
|
|
||||||
.. code-block:: none
|
.. code-block:: none
|
||||||
:caption: ``MANIFEST.in``
|
:caption: ``MANIFEST.in``
|
||||||
|
|
@ -62,9 +55,8 @@ files, such as the static and templates directories,
|
||||||
graft flaskr/templates
|
graft flaskr/templates
|
||||||
global-exclude *.pyc
|
global-exclude *.pyc
|
||||||
|
|
||||||
This tells Python to copy everything in the ``static`` and ``templates``
|
This tells the build to copy everything in the ``static`` and ``templates`` directories,
|
||||||
directories, and the ``schema.sql`` file, but to exclude all bytecode
|
and the ``schema.sql`` file, but to exclude all bytecode files.
|
||||||
files.
|
|
||||||
|
|
||||||
See the official `Packaging tutorial <packaging tutorial_>`_ and
|
See the official `Packaging tutorial <packaging tutorial_>`_ and
|
||||||
`detailed guide <packaging guide_>`_ for more explanation of the files
|
`detailed guide <packaging guide_>`_ for more explanation of the files
|
||||||
|
|
@ -83,10 +75,10 @@ Use ``pip`` to install your project in the virtual environment.
|
||||||
|
|
||||||
$ pip install -e .
|
$ pip install -e .
|
||||||
|
|
||||||
This tells pip to find ``setup.py`` in the current directory and install
|
This tells pip to find ``pyproject.toml`` in the current directory and install the
|
||||||
it in *editable* or *development* mode. Editable mode means that as you
|
project in *editable* or *development* mode. Editable mode means that as you make
|
||||||
make changes to your local code, you'll only need to re-install if you
|
changes to your local code, you'll only need to re-install if you change the metadata
|
||||||
change the metadata about the project, such as its dependencies.
|
about the project, such as its dependencies.
|
||||||
|
|
||||||
You can observe that the project is now installed with ``pip list``.
|
You can observe that the project is now installed with ``pip list``.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ The project directory will contain:
|
||||||
* ``flaskr/``, a Python package containing your application code and
|
* ``flaskr/``, a Python package containing your application code and
|
||||||
files.
|
files.
|
||||||
* ``tests/``, a directory containing test modules.
|
* ``tests/``, a directory containing test modules.
|
||||||
* ``venv/``, a Python virtual environment where Flask and other
|
* ``.venv/``, a Python virtual environment where Flask and other
|
||||||
dependencies are installed.
|
dependencies are installed.
|
||||||
* Installation files telling Python how to install your project.
|
* Installation files telling Python how to install your project.
|
||||||
* Version control config, such as `git`_. You should make a habit of
|
* Version control config, such as `git`_. You should make a habit of
|
||||||
|
|
@ -80,8 +80,8 @@ By the end, your project layout will look like this:
|
||||||
│ ├── test_db.py
|
│ ├── test_db.py
|
||||||
│ ├── test_auth.py
|
│ ├── test_auth.py
|
||||||
│ └── test_blog.py
|
│ └── test_blog.py
|
||||||
├── venv/
|
├── .venv/
|
||||||
├── setup.py
|
├── pyproject.toml
|
||||||
└── MANIFEST.in
|
└── MANIFEST.in
|
||||||
|
|
||||||
If you're using version control, the following files that are generated
|
If you're using version control, the following files that are generated
|
||||||
|
|
@ -92,7 +92,7 @@ write. For example, with git:
|
||||||
.. code-block:: none
|
.. code-block:: none
|
||||||
:caption: ``.gitignore``
|
:caption: ``.gitignore``
|
||||||
|
|
||||||
venv/
|
.venv/
|
||||||
|
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
|
||||||
|
|
@ -490,20 +490,18 @@ no longer exist in the database.
|
||||||
Running the Tests
|
Running the Tests
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Some extra configuration, which is not required but makes running
|
Some extra configuration, which is not required but makes running tests with coverage
|
||||||
tests with coverage less verbose, can be added to the project's
|
less verbose, can be added to the project's ``pyproject.toml`` file.
|
||||||
``setup.cfg`` file.
|
|
||||||
|
|
||||||
.. code-block:: none
|
.. code-block:: toml
|
||||||
:caption: ``setup.cfg``
|
:caption: ``pyproject.toml``
|
||||||
|
|
||||||
[tool:pytest]
|
[tool.pytest.ini_options]
|
||||||
testpaths = tests
|
testpaths = ["tests"]
|
||||||
|
|
||||||
[coverage:run]
|
[tool.coverage.run]
|
||||||
branch = True
|
branch = true
|
||||||
source =
|
source = ["flaskr"]
|
||||||
flaskr
|
|
||||||
|
|
||||||
To run the tests, use the ``pytest`` command. It will find and run all
|
To run the tests, use the ``pytest`` command. It will find and run all
|
||||||
the test functions you've written.
|
the test functions you've written.
|
||||||
|
|
@ -514,7 +512,7 @@ the test functions you've written.
|
||||||
|
|
||||||
========================= test session starts ==========================
|
========================= test session starts ==========================
|
||||||
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
|
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
|
||||||
rootdir: /home/user/Projects/flask-tutorial, inifile: setup.cfg
|
rootdir: /home/user/Projects/flask-tutorial
|
||||||
collected 23 items
|
collected 23 items
|
||||||
|
|
||||||
tests/test_auth.py ........ [ 34%]
|
tests/test_auth.py ........ [ 34%]
|
||||||
|
|
|
||||||
2
examples/javascript/.gitignore
vendored
2
examples/javascript/.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
venv/
|
.venv/
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
instance/
|
instance/
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ Install
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ python3 -m venv venv
|
$ python3 -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
$ pip install -e .
|
$ pip install -e .
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
26
examples/javascript/pyproject.toml
Normal file
26
examples/javascript/pyproject.toml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
[project]
|
||||||
|
name = "js_example"
|
||||||
|
version = "1.1.0"
|
||||||
|
description = "Demonstrates making AJAX requests to Flask."
|
||||||
|
readme = "README.rst"
|
||||||
|
license = {text = "BSD-3-Clause"}
|
||||||
|
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
||||||
|
dependencies = ["flask"]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Documentation = "https://flask.palletsprojects.com/patterns/jquery/"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
test = ["pytest", "blinker"]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
filterwarnings = ["error"]
|
||||||
|
|
||||||
|
[tool.coverage.run]
|
||||||
|
branch = true
|
||||||
|
source = ["js_example", "tests"]
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
[metadata]
|
|
||||||
name = js_example
|
|
||||||
version = 1.1.0
|
|
||||||
url = https://flask.palletsprojects.com/patterns/jquery/
|
|
||||||
license = BSD-3-Clause
|
|
||||||
maintainer = Pallets
|
|
||||||
maintainer_email = contact@palletsprojects.com
|
|
||||||
description = Demonstrates making AJAX requests to Flask.
|
|
||||||
long_description = file: README.rst
|
|
||||||
long_description_content_type = text/x-rst
|
|
||||||
|
|
||||||
[options]
|
|
||||||
packages = find:
|
|
||||||
include_package_data = true
|
|
||||||
install_requires =
|
|
||||||
Flask
|
|
||||||
|
|
||||||
[options.extras_require]
|
|
||||||
test =
|
|
||||||
pytest
|
|
||||||
blinker
|
|
||||||
|
|
||||||
[tool:pytest]
|
|
||||||
testpaths = tests
|
|
||||||
|
|
||||||
[coverage:run]
|
|
||||||
branch = True
|
|
||||||
source =
|
|
||||||
js_example
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
setup()
|
|
||||||
2
examples/tutorial/.gitignore
vendored
2
examples/tutorial/.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
venv/
|
.venv/
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
instance/
|
instance/
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ default Git version is the main branch. ::
|
||||||
|
|
||||||
Create a virtualenv and activate it::
|
Create a virtualenv and activate it::
|
||||||
|
|
||||||
$ python3 -m venv venv
|
$ python3 -m venv .venv
|
||||||
$ . venv/bin/activate
|
$ . .venv/bin/activate
|
||||||
|
|
||||||
Or on Windows cmd::
|
Or on Windows cmd::
|
||||||
|
|
||||||
$ py -3 -m venv venv
|
$ py -3 -m venv .venv
|
||||||
$ venv\Scripts\activate.bat
|
$ .venv\Scripts\activate.bat
|
||||||
|
|
||||||
Install Flaskr::
|
Install Flaskr::
|
||||||
|
|
||||||
|
|
|
||||||
28
examples/tutorial/pyproject.toml
Normal file
28
examples/tutorial/pyproject.toml
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
[project]
|
||||||
|
name = "flaskr"
|
||||||
|
version = "1.0.0"
|
||||||
|
description = "The basic blog app built in the Flask tutorial."
|
||||||
|
readme = "README.rst"
|
||||||
|
license = {text = "BSD-3-Clause"}
|
||||||
|
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
||||||
|
dependencies = [
|
||||||
|
"flask",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Documentation = "https://flask.palletsprojects.com/tutorial/"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
test = ["pytest"]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
filterwarnings = ["error"]
|
||||||
|
|
||||||
|
[tool.coverage.run]
|
||||||
|
branch = true
|
||||||
|
source = ["flaskr", "tests"]
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
[metadata]
|
|
||||||
name = flaskr
|
|
||||||
version = 1.0.0
|
|
||||||
url = https://flask.palletsprojects.com/tutorial/
|
|
||||||
license = BSD-3-Clause
|
|
||||||
maintainer = Pallets
|
|
||||||
maintainer_email = contact@palletsprojects.com
|
|
||||||
description = The basic blog app built in the Flask tutorial.
|
|
||||||
long_description = file: README.rst
|
|
||||||
long_description_content_type = text/x-rst
|
|
||||||
|
|
||||||
[options]
|
|
||||||
packages = find:
|
|
||||||
include_package_data = true
|
|
||||||
install_requires =
|
|
||||||
Flask
|
|
||||||
|
|
||||||
[options.extras_require]
|
|
||||||
test =
|
|
||||||
pytest
|
|
||||||
|
|
||||||
[tool:pytest]
|
|
||||||
testpaths = tests
|
|
||||||
|
|
||||||
[coverage:run]
|
|
||||||
branch = True
|
|
||||||
source =
|
|
||||||
flaskr
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
setup()
|
|
||||||
94
pyproject.toml
Normal file
94
pyproject.toml
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
[project]
|
||||||
|
name = "Flask"
|
||||||
|
description = "A simple framework for building complex web applications."
|
||||||
|
readme = "README.rst"
|
||||||
|
license = {text = "BSD-3-Clause"}
|
||||||
|
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
||||||
|
authors = [{name = "Armin Ronacher", email = "armin.ronacher@active-4.com"}]
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"Environment :: Web Environment",
|
||||||
|
"Framework :: Flask",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"License :: OSI Approved :: BSD License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
|
||||||
|
"Topic :: Internet :: WWW/HTTP :: WSGI",
|
||||||
|
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
|
||||||
|
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
||||||
|
]
|
||||||
|
requires-python = ">=3.7"
|
||||||
|
dependencies = [
|
||||||
|
"Werkzeug>=2.2.2",
|
||||||
|
"Jinja2>=3.0",
|
||||||
|
"itsdangerous>=2.0",
|
||||||
|
"click>=8.0",
|
||||||
|
"importlib-metadata>=3.6.0; python_version < '3.10'",
|
||||||
|
]
|
||||||
|
dynamic = ["version"]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Donate = "https://palletsprojects.com/donate"
|
||||||
|
Documentation = "https://flask.palletsprojects.com/"
|
||||||
|
Changes = "https://flask.palletsprojects.com/changes/"
|
||||||
|
"Source Code" = "https://github.com/pallets/flask/"
|
||||||
|
"Issue Tracker" = "https://github.com/pallets/flask/issues/"
|
||||||
|
Twitter = "https://twitter.com/PalletsTeam"
|
||||||
|
Chat = "https://discord.gg/pallets"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
async = ["asgiref>=3.2"]
|
||||||
|
dotenv = ["python-dotenv"]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
flask = "flask.cli:main"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
version = {attr = "flask.__version__"}
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
filterwarnings = ["error"]
|
||||||
|
|
||||||
|
[tool.coverage.run]
|
||||||
|
branch = true
|
||||||
|
source = ["flask", "tests"]
|
||||||
|
|
||||||
|
[tool.coverage.paths]
|
||||||
|
source = ["src", "*/site-packages"]
|
||||||
|
|
||||||
|
[tool.mypy]
|
||||||
|
python_version = "3.7"
|
||||||
|
files = ["src/flask"]
|
||||||
|
show_error_codes = true
|
||||||
|
pretty = true
|
||||||
|
#strict = true
|
||||||
|
allow_redefinition = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
#disallow_untyped_calls = true
|
||||||
|
#disallow_untyped_defs = true
|
||||||
|
#disallow_incomplete_defs = true
|
||||||
|
no_implicit_optional = true
|
||||||
|
local_partial_types = true
|
||||||
|
#no_implicit_reexport = true
|
||||||
|
strict_equality = true
|
||||||
|
warn_redundant_casts = true
|
||||||
|
warn_unused_configs = true
|
||||||
|
warn_unused_ignores = true
|
||||||
|
#warn_return_any = true
|
||||||
|
#warn_unreachable = true
|
||||||
|
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = [
|
||||||
|
"asgiref.*",
|
||||||
|
"blinker.*",
|
||||||
|
"dotenv.*",
|
||||||
|
"cryptography.*",
|
||||||
|
"importlib_metadata",
|
||||||
|
]
|
||||||
|
ignore_missing_imports = true
|
||||||
123
setup.cfg
123
setup.cfg
|
|
@ -1,123 +0,0 @@
|
||||||
[metadata]
|
|
||||||
name = Flask
|
|
||||||
version = attr: flask.__version__
|
|
||||||
url = https://palletsprojects.com/p/flask
|
|
||||||
project_urls =
|
|
||||||
Donate = https://palletsprojects.com/donate
|
|
||||||
Documentation = https://flask.palletsprojects.com/
|
|
||||||
Changes = https://flask.palletsprojects.com/changes/
|
|
||||||
Source Code = https://github.com/pallets/flask/
|
|
||||||
Issue Tracker = https://github.com/pallets/flask/issues/
|
|
||||||
Twitter = https://twitter.com/PalletsTeam
|
|
||||||
Chat = https://discord.gg/pallets
|
|
||||||
license = BSD-3-Clause
|
|
||||||
author = Armin Ronacher
|
|
||||||
author_email = armin.ronacher@active-4.com
|
|
||||||
maintainer = Pallets
|
|
||||||
maintainer_email = contact@palletsprojects.com
|
|
||||||
description = A simple framework for building complex web applications.
|
|
||||||
long_description = file: README.rst
|
|
||||||
long_description_content_type = text/x-rst
|
|
||||||
classifiers =
|
|
||||||
Development Status :: 5 - Production/Stable
|
|
||||||
Environment :: Web Environment
|
|
||||||
Framework :: Flask
|
|
||||||
Intended Audience :: Developers
|
|
||||||
License :: OSI Approved :: BSD License
|
|
||||||
Operating System :: OS Independent
|
|
||||||
Programming Language :: Python
|
|
||||||
Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
||||||
Topic :: Internet :: WWW/HTTP :: WSGI
|
|
||||||
Topic :: Internet :: WWW/HTTP :: WSGI :: Application
|
|
||||||
Topic :: Software Development :: Libraries :: Application Frameworks
|
|
||||||
|
|
||||||
[options]
|
|
||||||
packages = find:
|
|
||||||
package_dir = = src
|
|
||||||
include_package_data = True
|
|
||||||
python_requires = >= 3.7
|
|
||||||
# Dependencies are in setup.py for GitHub's dependency graph.
|
|
||||||
|
|
||||||
[options.packages.find]
|
|
||||||
where = src
|
|
||||||
|
|
||||||
[options.entry_points]
|
|
||||||
console_scripts =
|
|
||||||
flask = flask.cli:main
|
|
||||||
|
|
||||||
[tool:pytest]
|
|
||||||
testpaths = tests
|
|
||||||
filterwarnings =
|
|
||||||
error
|
|
||||||
|
|
||||||
[coverage:run]
|
|
||||||
branch = True
|
|
||||||
source =
|
|
||||||
flask
|
|
||||||
tests
|
|
||||||
|
|
||||||
[coverage:paths]
|
|
||||||
source =
|
|
||||||
src
|
|
||||||
*/site-packages
|
|
||||||
|
|
||||||
[flake8]
|
|
||||||
# B = bugbear
|
|
||||||
# E = pycodestyle errors
|
|
||||||
# F = flake8 pyflakes
|
|
||||||
# W = pycodestyle warnings
|
|
||||||
# B9 = bugbear opinions
|
|
||||||
# ISC = implicit str concat
|
|
||||||
select = B, E, F, W, B9, ISC
|
|
||||||
ignore =
|
|
||||||
# slice notation whitespace, invalid
|
|
||||||
E203
|
|
||||||
# import at top, too many circular import fixes
|
|
||||||
E402
|
|
||||||
# line length, handled by bugbear B950
|
|
||||||
E501
|
|
||||||
# bare except, handled by bugbear B001
|
|
||||||
E722
|
|
||||||
# bin op line break, invalid
|
|
||||||
W503
|
|
||||||
# requires Python 3.10
|
|
||||||
B905
|
|
||||||
# up to 88 allowed by bugbear B950
|
|
||||||
max-line-length = 80
|
|
||||||
per-file-ignores =
|
|
||||||
# __init__ exports names
|
|
||||||
src/flask/__init__.py: F401
|
|
||||||
|
|
||||||
[mypy]
|
|
||||||
files = src/flask, tests/typing
|
|
||||||
python_version = 3.7
|
|
||||||
show_error_codes = True
|
|
||||||
allow_redefinition = True
|
|
||||||
disallow_subclassing_any = True
|
|
||||||
# disallow_untyped_calls = True
|
|
||||||
# disallow_untyped_defs = True
|
|
||||||
# disallow_incomplete_defs = True
|
|
||||||
no_implicit_optional = True
|
|
||||||
local_partial_types = True
|
|
||||||
# no_implicit_reexport = True
|
|
||||||
strict_equality = True
|
|
||||||
warn_redundant_casts = True
|
|
||||||
warn_unused_configs = True
|
|
||||||
warn_unused_ignores = True
|
|
||||||
# warn_return_any = True
|
|
||||||
# warn_unreachable = True
|
|
||||||
|
|
||||||
[mypy-asgiref.*]
|
|
||||||
ignore_missing_imports = True
|
|
||||||
|
|
||||||
[mypy-blinker.*]
|
|
||||||
ignore_missing_imports = True
|
|
||||||
|
|
||||||
[mypy-dotenv.*]
|
|
||||||
ignore_missing_imports = True
|
|
||||||
|
|
||||||
[mypy-cryptography.*]
|
|
||||||
ignore_missing_imports = True
|
|
||||||
|
|
||||||
[mypy-importlib_metadata]
|
|
||||||
ignore_missing_imports = True
|
|
||||||
17
setup.py
17
setup.py
|
|
@ -1,17 +0,0 @@
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
# Metadata goes in setup.cfg. These are here for GitHub's dependency graph.
|
|
||||||
setup(
|
|
||||||
name="Flask",
|
|
||||||
install_requires=[
|
|
||||||
"Werkzeug >= 2.2.2",
|
|
||||||
"Jinja2 >= 3.0",
|
|
||||||
"itsdangerous >= 2.0",
|
|
||||||
"click >= 8.0",
|
|
||||||
"importlib-metadata >= 3.6.0; python_version < '3.10'",
|
|
||||||
],
|
|
||||||
extras_require={
|
|
||||||
"async": ["asgiref >= 3.2"],
|
|
||||||
"dotenv": ["python-dotenv"],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
@ -120,14 +120,14 @@ def test_app_tearing_down_with_unhandled_exception(app, client):
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
raise Exception("dummy")
|
raise ValueError("dummy")
|
||||||
|
|
||||||
with pytest.raises(Exception, match="dummy"):
|
with pytest.raises(ValueError, match="dummy"):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
client.get("/")
|
client.get("/")
|
||||||
|
|
||||||
assert len(cleanup_stuff) == 1
|
assert len(cleanup_stuff) == 1
|
||||||
assert isinstance(cleanup_stuff[0], Exception)
|
assert isinstance(cleanup_stuff[0], ValueError)
|
||||||
assert str(cleanup_stuff[0]) == "dummy"
|
assert str(cleanup_stuff[0]) == "dummy"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1472,11 +1472,11 @@ def test_static_route_with_host_matching():
|
||||||
rv = flask.url_for("static", filename="index.html", _external=True)
|
rv = flask.url_for("static", filename="index.html", _external=True)
|
||||||
assert rv == "http://example.com/static/index.html"
|
assert rv == "http://example.com/static/index.html"
|
||||||
# Providing static_host without host_matching=True should error.
|
# Providing static_host without host_matching=True should error.
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(AssertionError):
|
||||||
flask.Flask(__name__, static_host="example.com")
|
flask.Flask(__name__, static_host="example.com")
|
||||||
# Providing host_matching=True with static_folder
|
# Providing host_matching=True with static_folder
|
||||||
# but without static_host should error.
|
# but without static_host should error.
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(AssertionError):
|
||||||
flask.Flask(__name__, host_matching=True)
|
flask.Flask(__name__, host_matching=True)
|
||||||
# Providing host_matching=True without static_host
|
# Providing host_matching=True without static_host
|
||||||
# but with static_folder=None should not error.
|
# but with static_folder=None should not error.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue