Skip to content
Myr

install.rst

This file

Path

docs/tutorial/install.rst

107 lines · 3.3 KiB

Last changed by

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

History of this file

Take it

The walk stopped after 200 commits: lines older than 0ae0f59 point at it.

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 1–3why, one step back
1Make the Project Installable
2============================3

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 4–7why, one step back
4Making your project installable means that you can build a *wheel* file and install that
5in another environment, just like you installed Flask in your project's environment.6This makes deploying your project the same as installing any other library, so you're7using all the standard Python tools to manage everything.

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 8–29why, one step back
8
9Installing also comes with other benefits that might not be obvious from10the tutorial or as a new Python user, including:1112* Currently, Python and Flask understand how to use the ``flaskr``13 package only because you're running from your project's directory.14 Installing means you can import it no matter where you run from.1516* You can manage your project's dependencies just like other packages17 do, so ``pip install yourproject.whl`` installs them.1819* Test tools can isolate your test environment from your development20 environment.2122.. note::23 This is being introduced late in the tutorial, but in your future24 projects you should always start with this.252627Describe the Project28--------------------29

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

line 30why, one step back
30The ``pyproject.toml`` file describes your project and how to build it.

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 31why, one step back
31

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 32–33why, one step back
32.. code-block:: toml
33 :caption: ``pyproject.toml``

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 34why, one step back
34

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 35–40why, one step back
35 [project]
36 name = "flaskr"37 version = "1.0.0"38 dependencies = [39 "flask",40 ]

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 41why, one step back
41

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 42–44why, one step back
42 [build-system]
43 requires = ["setuptools"]44 build-backend = "setuptools.build_meta"

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 45–46why, one step back
45
46

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 47–48why, one step back
47The setuptools build backend needs another file named ``MANIFEST.in`` to tell it about
48non-Python files to include.

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 49–57why, one step back
49
50.. code-block:: none51 :caption: ``MANIFEST.in``5253 include flaskr/schema.sql54 graft flaskr/static55 graft flaskr/templates56 global-exclude *.pyc57

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 58–59why, one step back
58This tells the build to copy everything in the ``static`` and ``templates`` directories,
59and the ``schema.sql`` file, but to exclude all bytecode files.

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 60why, one step back
60

Merge branch '2.1.x'David Lordbefore adoption9e2e1de

lines 61–62why, one step back
61See the official `Packaging tutorial <packaging tutorial_>`_ and
62`detailed guide <packaging guide_>`_ for more explanation of the files

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 63–64why, one step back
63and options used.
64

Merge branch '2.1.x'David Lordbefore adoption9e2e1de

lines 65–66why, one step back
65.. _packaging tutorial: https://packaging.python.org/tutorials/packaging-projects/
66.. _packaging guide: https://packaging.python.org/guides/distributing-packages-using-setuptools/

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 67–77why, one step back
67
6869Install the Project70-------------------7172Use ``pip`` to install your project in the virtual environment.7374.. code-block:: none7576 $ pip install -e .77

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 78–81why, one step back
78This tells pip to find ``pyproject.toml`` in the current directory and install the
79project in *editable* or *development* mode. Editable mode means that as you make80changes to your local code, you'll only need to re-install if you change the metadata81about the project, such as its dependencies.

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 82–102why, one step back
82
83You can observe that the project is now installed with ``pip list``.8485.. code-block:: none8687 $ pip list8889 Package Version Location90 -------------- --------- ----------------------------------91 click 6.792 Flask 1.093 flaskr 1.0.0 /home/user/Projects/flask-tutorial94 itsdangerous 0.2495 Jinja2 2.1096 MarkupSafe 1.097 pip 9.0.398 setuptools 39.0.199 Werkzeug 0.14.1100 wheel 0.30.0101102Nothing changes from how you've been running your project so far.

Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727

line 103why, one step back
103``--app`` is still set to ``flaskr`` and ``flask run`` still runs

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

lines 104–107why, one step back
104the application, but you can call it from anywhere, not just the
105``flask-tutorial`` directory.106107Continue to :doc:`tests`.