update docs and examples for pyproject
Before adoption: this commit came in with the history the project adopted, so no landing records it.
setup.py -> pyproject.toml venv -> .venv
authored by David Lord · committed by David Lord · parent 6d6d986 · Browse files · 24 files·+153 added−195 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
24 files+153 added−195 removed
- other:+153 added−195 removed
Provenance
- Commit
8f13f5b- Tree
44334c0- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
6d6d986
24 files changed+153 added−195 removed
modified:docs/deploying/eventlet.rst+2 added-2 removed
32 unmodified lines33 34 .. code-block:: text35 36 $ cd hello-app37- $ python -m venv venv38- $ . venv/bin/activate37+ $ python -m venv .venv38+ $ . .venv/bin/activate39 $ pip install . # install your application40 $ pip install eventlet41 42 38 unmodified linesmodified:docs/deploying/gevent.rst+2 added-2 removed
31 unmodified lines32 33 .. code-block:: text34 35 $ cd hello-app36- $ python -m venv venv37- $ . venv/bin/activate36+ $ python -m venv .venv37+ $ . .venv/bin/activate38 $ pip install . # install your application39 $ pip install gevent40 41 39 unmodified linesmodified:docs/deploying/gunicorn.rst+2 added-2 removed
28 unmodified lines29 30 .. code-block:: text31 32 $ cd hello-app33- $ python -m venv venv34- $ . venv/bin/activate33+ $ python -m venv .venv34+ $ . .venv/bin/activate35 $ pip install . # install your application36 $ pip install gunicorn37 38 92 unmodified linesmodified:docs/deploying/mod_wsgi.rst+3 added-3 removed
31 unmodified lines32 33 .. code-block:: text34 35 $ cd hello-app36- $ python -m venv venv37- $ . venv/bin/activate36+ $ python -m venv .venv37+ $ . .venv/bin/activate38 $ pip install . # install your application39 $ pip install mod_wsgi40 41 46 unmodified lines88 mod_wsgi to drop to that user after starting.89 90 .. code-block:: text91 92- $ sudo /home/hello/venv/bin/mod_wsgi-express start-server \92+ $ sudo /home/hello/.venv/bin/mod_wsgi-express start-server \93 /home/hello/wsgi.py \94 --user hello --group hello --port 80 --processes 4modified:docs/deploying/uwsgi.rst+2 added-2 removed
27 unmodified lines28 29 .. code-block:: text30 31 $ cd hello-app32- $ python -m venv venv33- $ . venv/bin/activate32+ $ python -m venv .venv33+ $ . .venv/bin/activate34 $ pip install . # install your application35 $ pip install pyuwsgi36 37 If you have a compiler available, you can install the ``uwsgi`` package108 unmodified linesmodified:docs/deploying/waitress.rst+2 added-2 removed
25 unmodified lines26 27 .. code-block:: text28 29 $ cd hello-app30- $ python -m venv venv31- $ . venv/bin/activate30+ $ python -m venv .venv31+ $ . .venv/bin/activate32 $ pip install . # install your application33 $ pip install waitress34 35 40 unmodified linesmodified:docs/patterns/packages.rst+13 added-12 removed
40 unmodified lines41 42 But how do you run your application now? The naive ``python43 yourapplication/__init__.py`` will not work. Let's just say that Python44 does not want modules in packages to be the startup file. But that is not45-a big problem, just add a new file called :file:`setup.py` next to the inner46-:file:`yourapplication` folder with the following contents::45+a big problem, just add a new file called :file:`pyproject.toml` next to the inner46+:file:`yourapplication` folder with the following contents:47 48- from setuptools import setup48+.. code-block:: toml49 50- setup(51- name='yourapplication',52- packages=['yourapplication'],53- include_package_data=True,54- install_requires=[55- 'flask',56- ],57- )50+ [project]51+ name = "yourapplication"52+ dependencies = [53+ "flask",54+ ]55 56+ [build-system]57+ requires = ["setuptools"]58+ build-backend = "setuptools.build_meta"59+60 Install your application so it is importable:61 62 .. code-block:: text63 34 unmodified lines98 99 You should then end up with something like that::100 101 /yourapplication101- setup.py102+ pyproject.toml103 /yourapplication104 __init__.py105 views.py106 /static25 unmodified linesmodified:docs/tutorial/deploy.rst+6 added-15 removed
12 unmodified lines13 14 Build and Install15 -----------------16 17-When you want to deploy your application elsewhere, you build a18-distribution file. The current standard for Python distribution is the19-*wheel* format, with the ``.whl`` extension. Make sure the wheel library20-is installed first:17+When you want to deploy your application elsewhere, you build a *wheel*18+(``.whl``) file. Install and use the ``build`` tool to do this.19 20 .. code-block:: none21 24- $ pip install wheel22+ $ pip install build23+ $ python -m build --wheel24 26-Running ``setup.py`` with Python gives you a command line tool to issue27-build-related commands. The ``bdist_wheel`` command will build a wheel28-distribution file.29-30-.. code-block:: none31-32- $ python setup.py bdist_wheel33-25 You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. The26 file name is in the format of {project name}-{version}-{python tag}27 -{abi tag}-{platform tag}.28 15 unmodified lines44 $ flask --app flaskr init-db45 46 When Flask detects that it's installed (not in editable mode), it uses47 a different directory for the instance folder. You can find it at57-``venv/var/flaskr-instance`` instead.48+``.venv/var/flaskr-instance`` instead.49 50 51 Configure the Secret Key52 ------------------------14 unmodified lines67 Create the ``config.py`` file in the instance folder, which the factory68 will read from if it exists. Copy the generated value into it.69 70 .. code-block:: python80- :caption: ``venv/var/flaskr-instance/config.py``71+ :caption: ``.venv/var/flaskr-instance/config.py``72 73 SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'74 75 You can also set any other necessary configuration here, although36 unmodified linesmodified:docs/tutorial/install.rst+24 added-32 removed
1 Make the Project Installable2 ============================3 4-Making your project installable means that you can build a5-*distribution* file and install that in another environment, just like6-you installed Flask in your project's environment. This makes deploying7-your project the same as installing any other library, so you're using8-all the standard Python tools to manage everything.4+Making your project installable means that you can build a *wheel* file and install that5+in another environment, just like you installed Flask in your project's environment.6+This makes deploying your project the same as installing any other library, so you're7+using all the standard Python tools to manage everything.8 9 Installing also comes with other benefits that might not be obvious from10 the tutorial or as a new Python user, including:11 14 unmodified lines26 27 Describe the Project28 --------------------29 31-The ``setup.py`` file describes your project and the files that belong32-to it.30+The ``pyproject.toml`` file describes your project and how to build it.31 34-.. code-block:: python35- :caption: ``setup.py``32+.. code-block:: toml33+ :caption: ``pyproject.toml``34 37- from setuptools import find_packages, setup35+ [project]36+ name = "flaskr"37+ version = "1.0.0"38+ dependencies = [39+ "flask",40+ ]41 39- setup(40- name='flaskr',41- version='1.0.0',42- packages=find_packages(),43- include_package_data=True,44- install_requires=[45- 'flask',46- ],47- )42+ [build-system]43+ requires = ["setuptools"]44+ build-backend = "setuptools.build_meta"45 46 50-``packages`` tells Python what package directories (and the Python files51-they contain) to include. ``find_packages()`` finds these directories52-automatically so you don't have to type them out. To include other53-files, such as the static and templates directories,54-``include_package_data`` is set. Python needs another file named55-``MANIFEST.in`` to tell what this other data is.47+The setuptools build backend needs another file named ``MANIFEST.in`` to tell it about48+non-Python files to include.49 50 .. code-block:: none51 :caption: ``MANIFEST.in``52 1 unmodified line54 graft flaskr/static55 graft flaskr/templates56 global-exclude *.pyc57 65-This tells Python to copy everything in the ``static`` and ``templates``66-directories, and the ``schema.sql`` file, but to exclude all bytecode67-files.58+This tells the build to copy everything in the ``static`` and ``templates`` directories,59+and the ``schema.sql`` file, but to exclude all bytecode files.60 61 See the official `Packaging tutorial <packaging tutorial_>`_ and62 `detailed guide <packaging guide_>`_ for more explanation of the files63 and options used.10 unmodified lines74 .. code-block:: none75 76 $ pip install -e .77 86-This tells pip to find ``setup.py`` in the current directory and install87-it in *editable* or *development* mode. Editable mode means that as you88-make changes to your local code, you'll only need to re-install if you89-change the metadata about the project, such as its dependencies.78+This tells pip to find ``pyproject.toml`` in the current directory and install the79+project in *editable* or *development* mode. Editable mode means that as you make80+changes to your local code, you'll only need to re-install if you change the metadata81+about the project, such as its dependencies.82 83 You can observe that the project is now installed with ``pip list``.84 85 .. code-block:: none22 unmodified linesmodified:docs/tutorial/layout.rst+4 added-4 removed
39 unmodified lines40 41 * ``flaskr/``, a Python package containing your application code and42 files.43 * ``tests/``, a directory containing test modules.44-* ``venv/``, a Python virtual environment where Flask and other44+* ``.venv/``, a Python virtual environment where Flask and other45 dependencies are installed.46 * Installation files telling Python how to install your project.47 * Version control config, such as `git`_. You should make a habit of48 using some type of version control for all your projects, no matter30 unmodified lines79 │ ├── test_factory.py80 │ ├── test_db.py81 │ ├── test_auth.py82 │ └── test_blog.py83- ├── venv/84- ├── setup.py83+ ├── .venv/84+ ├── pyproject.toml85 └── MANIFEST.in86 87 If you're using version control, the following files that are generated88 while running your project should be ignored. There may be other files2 unmodified lines91 92 .. code-block:: none93 :caption: ``.gitignore``94 95- venv/95+ .venv/96 97 *.pyc98 __pycache__/99 11 unmodified linesmodified:docs/tutorial/tests.rst+10 added-12 removed
488 unmodified lines489 490 Running the Tests491 -----------------492 493-Some extra configuration, which is not required but makes running494-tests with coverage less verbose, can be added to the project's495-``setup.cfg`` file.493+Some extra configuration, which is not required but makes running tests with coverage494+less verbose, can be added to the project's ``pyproject.toml`` file.495 497-.. code-block:: none498- :caption: ``setup.cfg``496+.. code-block:: toml497+ :caption: ``pyproject.toml``498 500- [tool:pytest]501- testpaths = tests499+ [tool.pytest.ini_options]500+ testpaths = ["tests"]501 503- [coverage:run]504- branch = True505- source =506- flaskr502+ [tool.coverage.run]503+ branch = true504+ source = ["flaskr"]505 506 To run the tests, use the ``pytest`` command. It will find and run all507 the test functions you've written.508 2 unmodified lines511 $ pytest512 513 ========================= test session starts ==========================514 platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0517- rootdir: /home/user/Projects/flask-tutorial, inifile: setup.cfg515+ rootdir: /home/user/Projects/flask-tutorial516 collected 23 items517 518 tests/test_auth.py ........ [ 34%]519 tests/test_blog.py ............ [ 86%]40 unmodified linesmodified:docs/cli.rst+13 added-28 removed
278 unmodified lines279 .. tabs::280 281 .. group-tab:: Bash282 283- Unix Bash, :file:`venv/bin/activate`::283+ Unix Bash, :file:`.venv/bin/activate`::284 285 $ export FLASK_APP=hello286 287 .. group-tab:: Fish288 289- Fish, :file:`venv/bin/activate.fish`::289+ Fish, :file:`.venv/bin/activate.fish`::290 291 $ set -x FLASK_APP hello292 293 .. group-tab:: CMD294 295- Windows CMD, :file:`venv\\Scripts\\activate.bat`::295+ Windows CMD, :file:`.venv\\Scripts\\activate.bat`::296 297 > set FLASK_APP=hello298 299 .. group-tab:: Powershell300 301- Windows Powershell, :file:`venv\\Scripts\\activate.ps1`::301+ Windows Powershell, :file:`.venv\\Scripts\\activate.ps1`::302 303 > $env:FLASK_APP = "hello"304 305 It is preferred to use dotenv support over this, since :file:`.flaskenv` can be131 unmodified lines437 -------438 439 Flask will automatically load commands specified in the ``flask.commands``440 `entry point`_. This is useful for extensions that want to add commands when441-they are installed. Entry points are specified in :file:`setup.py` ::441+they are installed. Entry points are specified in :file:`pyproject.toml`:442 443- from setuptools import setup443+.. code-block:: toml444 445- setup(446- name='flask-my-extension',447- ...,448- entry_points={449- 'flask.commands': [450- 'my-command=flask_my_extension.commands:cli'451- ],452- },453- )445+ [project.entry-points."flask.commands"]446+ my-command = "my_extension.commands:cli"447 455-448 .. _entry point: https://packaging.python.org/tutorials/packaging-projects/#entry-points449 458-Inside :file:`flask_my_extension/commands.py` you can then export a Click450+Inside :file:`my_extension/commands.py` you can then export a Click451 object::452 453 import click454 29 unmodified lines484 @click.group(cls=FlaskGroup, create_app=create_app)485 def cli():486 """Management script for the Wiki application."""487 496-Define the entry point in :file:`setup.py`::488+Define the entry point in :file:`pyproject.toml`:489 498- from setuptools import setup490+.. code-block:: toml491 500- setup(501- name='flask-my-extension',502- ...,503- entry_points={504- 'console_scripts': [505- 'wiki=wiki:cli'506- ],507- },508- )492+ [project.scripts]493+ wiki = "wiki:cli"494 495 Install the application in the virtualenv in editable mode and the custom496 script is available. Note that you don't need to set ``--app``. ::497 51 unmodified linesmodified:docs/installation.rst+5 added-5 removed
83 unmodified lines84 85 Create an environment86 ~~~~~~~~~~~~~~~~~~~~~87 88-Create a project folder and a :file:`venv` folder within:88+Create a project folder and a :file:`.venv` folder within:89 90 .. tabs::91 92 .. group-tab:: macOS/Linux1 unmodified line94 .. code-block:: text95 96 $ mkdir myproject97 $ cd myproject98- $ python3 -m venv venv98+ $ python3 -m venv .venv99 100 .. group-tab:: Windows101 102 .. code-block:: text103 104 > mkdir myproject105 > cd myproject106- > py -3 -m venv venv106+ > py -3 -m venv .venv107 108 109 .. _install-activate-env:110 7 unmodified lines118 .. group-tab:: macOS/Linux119 120 .. code-block:: text121 122- $ . venv/bin/activate122+ $ . .venv/bin/activate123 124 .. group-tab:: Windows125 126 .. code-block:: text127 128- > venv\Scripts\activate128+ > .venv\Scripts\activate129 130 Your shell prompt will change to show the name of the activated131 environment.132 13 unmodified linesmodified:examples/javascript/.gitignore+1 added-1 removed
1-venv/1+.venv/2 *.pyc3 __pycache__/4 instance/5 .cache/9 unmodified linesadded:examples/javascript/pyproject.toml+26 added
1+[project]2+name = "js_example"3+version = "1.1.0"4+description = "Demonstrates making AJAX requests to Flask."5+readme = "README.rst"6+license = {text = "BSD-3-Clause"}7+maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]8+dependencies = ["flask"]9+10+[project.urls]11+Documentation = "https://flask.palletsprojects.com/patterns/jquery/"12+13+[project.optional-dependencies]14+test = ["pytest", "blinker"]15+16+[build-system]17+requires = ["setuptools"]18+build-backend = "setuptools.build_meta"19+20+[tool.pytest.ini_options]21+testpaths = ["tests"]22+filterwarnings = ["error"]23+24+[tool.coverage.run]25+branch = true26+source = ["js_example", "tests"]modified:examples/javascript/README.rst+2 added-2 removed
21 unmodified lines22 -------23 24 .. code-block:: text25 26- $ python3 -m venv venv27- $ . venv/bin/activate26+ $ python3 -m venv .venv27+ $ . .venv/bin/activate28 $ pip install -e .29 30 31 Run17 unmodified linesdeleted:examples/javascript/setup.cfg-29 removed
1-[metadata]2-name = js_example3-version = 1.1.04-url = https://flask.palletsprojects.com/patterns/jquery/5-license = BSD-3-Clause6-maintainer = Pallets7-maintainer_email = contact@palletsprojects.com8-description = Demonstrates making AJAX requests to Flask.9-long_description = file: README.rst10-long_description_content_type = text/x-rst11-12-[options]13-packages = find:14-include_package_data = true15-install_requires =16- Flask17-18-[options.extras_require]19-test =20- pytest21- blinker22-23-[tool:pytest]24-testpaths = tests25-26-[coverage:run]27-branch = True28-source =29- js_exampledeleted:examples/javascript/setup.py-3 removed
1-from setuptools import setup2-3-setup()modified:examples/tutorial/.gitignore+1 added-1 removed
1-venv/1+.venv/2 *.pyc3 __pycache__/4 instance/5 .cache/9 unmodified linesadded:examples/tutorial/pyproject.toml+28 added
1+[project]2+name = "flaskr"3+version = "1.0.0"4+description = "The basic blog app built in the Flask tutorial."5+readme = "README.rst"6+license = {text = "BSD-3-Clause"}7+maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]8+dependencies = [9+ "flask",10+]11+12+[project.urls]13+Documentation = "https://flask.palletsprojects.com/tutorial/"14+15+[project.optional-dependencies]16+test = ["pytest"]17+18+[build-system]19+requires = ["setuptools"]20+build-backend = "setuptools.build_meta"21+22+[tool.pytest.ini_options]23+testpaths = ["tests"]24+filterwarnings = ["error"]25+26+[tool.coverage.run]27+branch = true28+source = ["flaskr", "tests"]modified:examples/tutorial/README.rst+4 added-4 removed
21 unmodified lines22 $ cd examples/tutorial23 24 Create a virtualenv and activate it::25 26- $ python3 -m venv venv27- $ . venv/bin/activate26+ $ python3 -m venv .venv27+ $ . .venv/bin/activate28 29 Or on Windows cmd::30 31- $ py -3 -m venv venv32- $ venv\Scripts\activate.bat31+ $ py -3 -m venv .venv32+ $ .venv\Scripts\activate.bat33 34 Install Flaskr::35 36 $ pip install -e .32 unmodified linesdeleted:examples/tutorial/setup.cfg-28 removed
1-[metadata]2-name = flaskr3-version = 1.0.04-url = https://flask.palletsprojects.com/tutorial/5-license = BSD-3-Clause6-maintainer = Pallets7-maintainer_email = contact@palletsprojects.com8-description = The basic blog app built in the Flask tutorial.9-long_description = file: README.rst10-long_description_content_type = text/x-rst11-12-[options]13-packages = find:14-include_package_data = true15-install_requires =16- Flask17-18-[options.extras_require]19-test =20- pytest21-22-[tool:pytest]23-testpaths = tests24-25-[coverage:run]26-branch = True27-source =28- flaskrdeleted:examples/tutorial/setup.py-3 removed
1-from setuptools import setup2-3-setup()modified:CONTRIBUTING.rst+3 added-3 removed
100 unmodified lines101 - Linux/macOS102 103 .. code-block:: text104 105- $ python3 -m venv env106- $ . env/bin/activate105+ $ python3 -m venv .venv106+ $ . .venv/bin/activate107 108 - Windows109 110 .. code-block:: text111 112- > py -3 -m venv env112+ > py -3 -m venv .venv113 > env\Scripts\activate114 115 - Upgrade pip and setuptools.116 111 unmodified lines