Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/studio/static/doc/flask-docs/patterns/distribute.html
blob: 8987a187cfbf14ce9f008f8bcf400ddb5779af2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Deploying with Distribute &mdash; Flask 0.8 documentation</title>
    
    <link rel="stylesheet" href="../_static/flasky.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.8',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="Flask 0.8 documentation" href="../index.html" />
    <link rel="up" title="Patterns for Flask" href="index.html" />
    <link rel="next" title="Deploying with Fabric" href="fabric.html" />
    <link rel="prev" title="Using URL Processors" href="urlprocessors.html" />
   
  
  <link rel="apple-touch-icon" href="../_static/touch-icon.png" />
  
  <link media="only screen and (max-device-width: 480px)" href="../_static/small_flask.css" type= "text/css" rel="stylesheet" />

  </head>
  <body>
    <div class="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="fabric.html" title="Deploying with Fabric"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="urlprocessors.html" title="Using URL Processors"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">Flask 0.8 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Patterns for Flask</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="deploying-with-distribute">
<span id="distribute-deployment"></span><h1>Deploying with Distribute<a class="headerlink" href="#deploying-with-distribute" title="Permalink to this headline">¶</a></h1>
<p><a class="reference external" href="http://pypi.python.org/pypi/distribute">distribute</a>, formerly setuptools, is an extension library that is
commonly used to (like the name says) distribute Python libraries and
extensions.  It extends distutils, a basic module installation system
shipped with Python to also support various more complex constructs that
make larger applications easier to distribute:</p>
<ul class="simple">
<li><strong>support for dependencies</strong>: a library or application can declare a
list of other libraries it depends on which will be installed
automatically for you.</li>
<li><strong>package registry</strong>: setuptools registers your package with your
Python installation.  This makes it possible to query information
provided by one package from another package.  The best known feature of
this system is the entry point support which allows one package to
declare an &#8220;entry point&#8221; another package can hook into to extend the
other package.</li>
<li><strong>installation manager</strong>: <cite>easy_install</cite>, which comes with distribute
can install other libraries for you.  You can also use <a class="reference external" href="http://pypi.python.org/pypi/pip">pip</a> which
sooner or later will replace <cite>easy_install</cite> which does more than just
installing packages for you.</li>
</ul>
<p>Flask itself, and all the libraries you can find on the cheeseshop
are distributed with either distribute, the older setuptools or distutils.</p>
<p>In this case we assume your application is called
<cite>yourapplication.py</cite> and you are not using a module, but a <a class="reference internal" href="packages.html#larger-applications"><em>package</em></a>.  Distributing resources with standard modules is
not supported by <a class="reference external" href="http://pypi.python.org/pypi/distribute">distribute</a> so we will not bother with it.  If you have
not yet converted your application into a package, head over to the
<a class="reference internal" href="packages.html#larger-applications"><em>Larger Applications</em></a> pattern to see how this can be done.</p>
<p>A working deployment with distribute is the first step into more complex
and more automated deployment scenarios.  If you want to fully automate
the process, also read the <a class="reference internal" href="fabric.html#fabric-deployment"><em>Deploying with Fabric</em></a> chapter.</p>
<div class="section" id="basic-setup-script">
<h2>Basic Setup Script<a class="headerlink" href="#basic-setup-script" title="Permalink to this headline">¶</a></h2>
<p>Because you have Flask running, you either have setuptools or distribute
available on your system anyways.  If you do not, fear not, there is a
script to install it for you: <a class="reference external" href="http://python-distribute.org/distribute_setup.py">distribute_setup.py</a>.  Just download and
run with your Python interpreter.</p>
<p>Standard disclaimer applies: <a class="reference internal" href="../installation.html#virtualenv"><em>you better use a virtualenv</em></a>.</p>
<p>Your setup code always goes into a file named <cite>setup.py</cite> next to your
application.  The name of the file is only convention, but because
everybody will look for a file with that name, you better not change it.</p>
<p>Yes, even if you are using <cite>distribute</cite>, you are importing from a package
called <cite>setuptools</cite>.  <cite>distribute</cite> is fully backwards compatible with
<cite>setuptools</cite>, so it also uses the same import name.</p>
<p>A basic <cite>setup.py</cite> file for a Flask application looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">setuptools</span> <span class="kn">import</span> <span class="n">setup</span>

<span class="n">setup</span><span class="p">(</span>
    <span class="n">name</span><span class="o">=</span><span class="s">&#39;Your Application&#39;</span><span class="p">,</span>
    <span class="n">version</span><span class="o">=</span><span class="s">&#39;1.0&#39;</span><span class="p">,</span>
    <span class="n">long_description</span><span class="o">=</span><span class="n">__doc__</span><span class="p">,</span>
    <span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;yourapplication&#39;</span><span class="p">],</span>
    <span class="n">include_package_data</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
    <span class="n">zip_safe</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
    <span class="n">install_requires</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;Flask&#39;</span><span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Please keep in mind that you have to list subpackages explicitly.  If you
want distribute to lookup the packages for you automatically, you can use
the <cite>find_packages</cite> function:</p>
<div class="highlight-python"><pre>from setuptools import setup, find_packages

setup(
    ...
    packages=find_packages()
)</pre>
</div>
<p>Most parameters to the <cite>setup</cite> function should be self explanatory,
<cite>include_package_data</cite> and <cite>zip_safe</cite> might not be.
<cite>include_package_data</cite> tells distribute to look for a <cite>MANIFEST.in</cite> file
and install all the entries that match as package data.  We will use this
to distribute the static files and templates along with the Python module
(see <a class="reference internal" href="#distributing-resources"><em>Distributing Resources</em></a>).  The <cite>zip_safe</cite> flag can be used to
force or prevent zip Archive creation.  In general you probably don&#8217;t want
your packages to be installed as zip files because some tools do not
support them and they make debugging a lot harder.</p>
</div>
<div class="section" id="distributing-resources">
<span id="id1"></span><h2>Distributing Resources<a class="headerlink" href="#distributing-resources" title="Permalink to this headline">¶</a></h2>
<p>If you try to install the package you just created, you will notice that
folders like <cite>static</cite> or <cite>templates</cite> are not installed for you.  The
reason for this is that distribute does not know which files to add for
you.  What you should do, is to create a <cite>MANIFEST.in</cite> file next to your
<cite>setup.py</cite> file.  This file lists all the files that should be added to
your tarball:</p>
<div class="highlight-python"><pre>recursive-include yourapplication/templates *
recursive-include yourapplication/static *</pre>
</div>
<p>Don&#8217;t forget that even if you enlist them in your <cite>MANIFEST.in</cite> file, they
won&#8217;t be installed for you unless you set the <cite>include_package_data</cite>
parameter of the <cite>setup</cite> function to <cite>True</cite>!</p>
</div>
<div class="section" id="declaring-dependencies">
<h2>Declaring Dependencies<a class="headerlink" href="#declaring-dependencies" title="Permalink to this headline">¶</a></h2>
<p>Dependencies are declared in the <cite>install_requires</cite> parameter as list.
Each item in that list is the name of a package that should be pulled from
PyPI on installation.  By default it will always use the most recent
version, but you can also provide minimum and maximum version
requirements.  Here some examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">install_requires</span><span class="o">=</span><span class="p">[</span>
    <span class="s">&#39;Flask&gt;=0.2&#39;</span><span class="p">,</span>
    <span class="s">&#39;SQLAlchemy&gt;=0.6&#39;</span><span class="p">,</span>
    <span class="s">&#39;BrokenPackage&gt;=0.7,&lt;=1.0&#39;</span>
<span class="p">]</span>
</pre></div>
</div>
<p>I mentioned earlier that dependencies are pulled from PyPI.  What if you
want to depend on a package that cannot be found on PyPI and won&#8217;t be
because it is an internal package you don&#8217;t want to share with anyone?
Just still do as if there was a PyPI entry for it and provide a list of
alternative locations where distribute should look for tarballs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">dependency_links</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;http://example.com/yourfiles&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>Make sure that page has a directory listing and the links on the page are
pointing to the actual tarballs with their correct filenames as this is
how distribute will find the files.  If you have an internal company
server that contains the packages, provide the URL to that server there.</p>
</div>
<div class="section" id="installing-developing">
<h2>Installing / Developing<a class="headerlink" href="#installing-developing" title="Permalink to this headline">¶</a></h2>
<p>To install your application (ideally into a virtualenv) just run the
<cite>setup.py</cite> script with the <cite>install</cite> parameter.  It will install your
application into the virtualenv&#8217;s site-packages folder and also download
and install all dependencies:</p>
<div class="highlight-python"><pre>$ python setup.py install</pre>
</div>
<p>If you are developing on the package and also want the requirements to be
installed, you can use the <cite>develop</cite> command instead:</p>
<div class="highlight-python"><pre>$ python setup.py develop</pre>
</div>
<p>This has the advantage of just installing a link to the site-packages
folder instead of copying the data over.  You can then continue to work on
the code without having to run <cite>install</cite> again after each change.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper"><p class="logo"><a href="../index.html">
  <img class="logo" src="../_static/flask.png" alt="Logo"/>
</a></p>
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Deploying with Distribute</a><ul>
<li><a class="reference internal" href="#basic-setup-script">Basic Setup Script</a></li>
<li><a class="reference internal" href="#distributing-resources">Distributing Resources</a></li>
<li><a class="reference internal" href="#declaring-dependencies">Declaring Dependencies</a></li>
<li><a class="reference internal" href="#installing-developing">Installing / Developing</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="index.html">Patterns for Flask</a><ul>
      <li>Previous: <a href="urlprocessors.html" title="previous chapter">Using URL Processors</a></li>
      <li>Next: <a href="fabric.html" title="next chapter">Deploying with Fabric</a></li>
  </ul></li>
  </ul></li>
</ul>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/patterns/distribute.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Armin Ronacher.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    </div>
  </body>
</html>