178 lines
9.5 KiB
HTML
178 lines
9.5 KiB
HTML
<!DOCTYPE html>
|
||
|
||
<html lang="en" data-content_root="../">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Make the Project Installable — Flask Documentation (3.2.x)</title>
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=6625fa76" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/flask.css?v=b87c8d14" />
|
||
<script src="../_static/documentation_options.js?v=56528222"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
<script data-project="flask" data-version="3.2.x" src="../_static/describe_version.js?v=fa7f30d0"></script>
|
||
<link rel="icon" href="../_static/shortcut-icon.png"/>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="Test Coverage" href="tests.html" />
|
||
<link rel="prev" title="Blog Blueprint" href="blog.html" />
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="tests.html" title="Test Coverage"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="blog.html" title="Blog Blueprint"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Flask Documentation (3.2.x)</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Tutorial</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Make the Project Installable</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="make-the-project-installable">
|
||
<h1>Make the Project Installable<a class="headerlink" href="#make-the-project-installable" title="Link to this heading">¶</a></h1>
|
||
<p>Making your project installable means that you can build a <em>wheel</em> file and install that
|
||
in another environment, just like you installed Flask in your project’s environment.
|
||
This makes deploying your project the same as installing any other library, so you’re
|
||
using all the standard Python tools to manage everything.</p>
|
||
<p>Installing also comes with other benefits that might not be obvious from
|
||
the tutorial or as a new Python user, including:</p>
|
||
<ul class="simple">
|
||
<li><p>Currently, Python and Flask understand how to use the <code class="docutils literal notranslate"><span class="pre">flaskr</span></code>
|
||
package only because you’re running from your project’s directory.
|
||
Installing means you can import it no matter where you run from.</p></li>
|
||
<li><p>You can manage your project’s dependencies just like other packages
|
||
do, so <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">yourproject.whl</span></code> installs them.</p></li>
|
||
<li><p>Test tools can isolate your test environment from your development
|
||
environment.</p></li>
|
||
</ul>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This is being introduced late in the tutorial, but in your future
|
||
projects you should always start with this.</p>
|
||
</div>
|
||
<section id="describe-the-project">
|
||
<h2>Describe the Project<a class="headerlink" href="#describe-the-project" title="Link to this heading">¶</a></h2>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code> file describes your project and how to build it.</p>
|
||
<div class="literal-block-wrapper docutils container" id="id1">
|
||
<div class="code-block-caption"><span class="caption-text"><code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code></span><a class="headerlink" href="#id1" title="Link to this code">¶</a></div>
|
||
<div class="highlight-toml notranslate"><div class="highlight"><pre><span></span><span class="k">[project]</span>
|
||
<span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"flaskr"</span>
|
||
<span class="n">version</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"1.0.0"</span>
|
||
<span class="n">description</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"The basic blog app built in the Flask tutorial."</span>
|
||
<span class="n">dependencies</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span>
|
||
<span class="w"> </span><span class="s2">"flask"</span><span class="p">,</span>
|
||
<span class="p">]</span>
|
||
|
||
<span class="k">[build-system]</span>
|
||
<span class="n">requires</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="s2">"flit_core<4"</span><span class="p">]</span>
|
||
<span class="n">build-backend</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"flit_core.buildapi"</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<p>See the official <a class="reference external" href="https://packaging.python.org/tutorials/packaging-projects/">Packaging tutorial</a> for more
|
||
explanation of the files and options used.</p>
|
||
</section>
|
||
<section id="install-the-project">
|
||
<h2>Install the Project<a class="headerlink" href="#install-the-project" title="Link to this heading">¶</a></h2>
|
||
<p>Use <code class="docutils literal notranslate"><span class="pre">pip</span></code> to install your project in the virtual environment.</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$ pip install -e .
|
||
</pre></div>
|
||
</div>
|
||
<p>This tells pip to find <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code> in the current directory and install the
|
||
project in <em>editable</em> or <em>development</em> mode. Editable mode means that as you make
|
||
changes to your local code, you’ll only need to re-install if you change the metadata
|
||
about the project, such as its dependencies.</p>
|
||
<p>You can observe that the project is now installed with <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">list</span></code>.</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$ pip list
|
||
|
||
Package Version Location
|
||
-------------- --------- ----------------------------------
|
||
click 6.7
|
||
Flask 1.0
|
||
flaskr 1.0.0 /home/user/Projects/flask-tutorial
|
||
itsdangerous 0.24
|
||
Jinja2 2.10
|
||
MarkupSafe 1.0
|
||
pip 9.0.3
|
||
Werkzeug 0.14.1
|
||
</pre></div>
|
||
</div>
|
||
<p>Nothing changes from how you’ve been running your project so far.
|
||
<code class="docutils literal notranslate"><span class="pre">--app</span></code> is still set to <code class="docutils literal notranslate"><span class="pre">flaskr</span></code> and <code class="docutils literal notranslate"><span class="pre">flask</span> <span class="pre">run</span></code> still runs
|
||
the application, but you can call it from anywhere, not just the
|
||
<code class="docutils literal notranslate"><span class="pre">flask-tutorial</span></code> directory.</p>
|
||
<p>Continue to <a class="reference internal" href="tests.html"><span class="doc">Test Coverage</span></a>.</p>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<span id="sidebar-top"></span>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="Main">
|
||
<div class="sphinxsidebarwrapper">
|
||
|
||
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/flask-vertical.png" alt="Logo of Flask"/>
|
||
</a></p>
|
||
|
||
|
||
<h3>Contents</h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">Make the Project Installable</a><ul>
|
||
<li><a class="reference internal" href="#describe-the-project">Describe the Project</a></li>
|
||
<li><a class="reference internal" href="#install-the-project">Install the Project</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li><a href="../index.html">Overview</a>
|
||
<ul>
|
||
<li><a href="index.html">Tutorial</a>
|
||
<ul>
|
||
<li>Previous: <a href="blog.html" title="previous chapter">Blog Blueprint</a>
|
||
<li>Next: <a href="tests.html" title="next chapter">Test Coverage</a></ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<search id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</search>
|
||
<script>document.getElementById('searchbox').style.display = "block"</script><div id="ethical-ad-placement"></div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2010 Pallets.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
|
||
</div>
|
||
</body>
|
||
</html>
|