| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="dist.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="dist.html" title='Distributing Python Modules' /> |
| 8 | <link rel='index' href='genindex.html' title='Index' /> |
| 9 | <link rel='last' href='about.html' title='About this document...' /> |
| 10 | <link rel='help' href='about.html' title='About this document...' /> |
| 11 | <link rel="next" href="single-ext.html" /> |
| 12 | <link rel="prev" href="pure-mod.html" /> |
| 13 | <link rel="parent" href="examples.html" /> |
| 14 | <link rel="next" href="single-ext.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>7.2 Pure Python distribution (by package)</title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="7.1 Pure Python distribution" |
| 24 | href="pure-mod.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="7. Examples" |
| 27 | href="examples.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="7.3 Single extension module" |
| 30 | href="single-ext.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Distributing Python Modules</td> |
| 33 | <td class='online-navigation'><img src='../icons/blank.png' |
| 34 | border='0' height='32' alt='' width='32' /></td> |
| 35 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 36 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 37 | <td class='online-navigation'><a rel="index" title="Index" |
| 38 | href="genindex.html"><img src='../icons/index.png' |
| 39 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 40 | </tr></table> |
| 41 | <div class='online-navigation'> |
| 42 | <b class="navlabel">Previous:</b> |
| 43 | <a class="sectref" rel="prev" href="pure-mod.html">7.1 Pure Python distribution</A> |
| 44 | <b class="navlabel">Up:</b> |
| 45 | <a class="sectref" rel="parent" href="examples.html">7. Examples</A> |
| 46 | <b class="navlabel">Next:</b> |
| 47 | <a class="sectref" rel="next" href="single-ext.html">7.3 Single extension module</A> |
| 48 | </div> |
| 49 | <hr /></div> |
| 50 | </DIV> |
| 51 | <!--End of Navigation Panel--> |
| 52 | |
| 53 | <H1><A NAME="SECTION007200000000000000000"></A> |
| 54 | <A NAME="pure-pkg"></A> |
| 55 | <BR> |
| 56 | 7.2 Pure Python distribution (by package) |
| 57 | </H1> |
| 58 | |
| 59 | <P> |
| 60 | If you have more than a couple of modules to distribute, especially if |
| 61 | they are in multiple packages, it's probably easier to specify whole |
| 62 | packages rather than individual modules. This works even if your |
| 63 | modules are not in a package; you can just tell the Distutils to process |
| 64 | modules from the root package, and that works the same as any other |
| 65 | package (except that you don't have to have an <span class="file">__init__.py</span> |
| 66 | file). |
| 67 | |
| 68 | <P> |
| 69 | The setup script from the last example could also be written as |
| 70 | <div class="verbatim"><pre> |
| 71 | from distutils.core import setup |
| 72 | setup(name='foobar', |
| 73 | version='1.0', |
| 74 | packages=[''], |
| 75 | ) |
| 76 | </pre></div> |
| 77 | (The empty string stands for the root package.) |
| 78 | |
| 79 | <P> |
| 80 | If those two files are moved into a subdirectory, but remain in the root |
| 81 | package, e.g.: |
| 82 | <div class="verbatim"><pre> |
| 83 | <root>/ |
| 84 | setup.py |
| 85 | src/ foo.py |
| 86 | bar.py |
| 87 | </pre></div> |
| 88 | then you would still specify the root package, but you have to tell the |
| 89 | Distutils where source files in the root package live: |
| 90 | <div class="verbatim"><pre> |
| 91 | from distutils.core import setup |
| 92 | setup(name='foobar', |
| 93 | version='1.0', |
| 94 | package_dir={'': 'src'}, |
| 95 | packages=[''], |
| 96 | ) |
| 97 | </pre></div> |
| 98 | |
| 99 | <P> |
| 100 | More typically, though, you will want to distribute multiple modules in |
| 101 | the same package (or in sub-packages). For example, if the <tt class="module">foo</tt> |
| 102 | and <tt class="module">bar</tt> modules belong in package <tt class="module">foobar</tt>, one way to |
| 103 | layout your source tree is |
| 104 | <div class="verbatim"><pre> |
| 105 | <root>/ |
| 106 | setup.py |
| 107 | foobar/ |
| 108 | __init__.py |
| 109 | foo.py |
| 110 | bar.py |
| 111 | </pre></div> |
| 112 | This is in fact the default layout expected by the Distutils, and the |
| 113 | one that requires the least work to describe in your setup script: |
| 114 | <div class="verbatim"><pre> |
| 115 | from distutils.core import setup |
| 116 | setup(name='foobar', |
| 117 | version='1.0', |
| 118 | packages=['foobar'], |
| 119 | ) |
| 120 | </pre></div> |
| 121 | |
| 122 | <P> |
| 123 | If you want to put modules in directories not named for their package, |
| 124 | then you need to use the <span class="du-option">package_dir</span> option again. For |
| 125 | example, if the <span class="file">src</span> directory holds modules in the |
| 126 | <tt class="module">foobar</tt> package: |
| 127 | <div class="verbatim"><pre> |
| 128 | <root>/ |
| 129 | setup.py |
| 130 | src/ |
| 131 | __init__.py |
| 132 | foo.py |
| 133 | bar.py |
| 134 | </pre></div> |
| 135 | an appropriate setup script would be |
| 136 | <div class="verbatim"><pre> |
| 137 | from distutils.core import setup |
| 138 | setup(name='foobar', |
| 139 | version='1.0', |
| 140 | package_dir={'foobar': 'src'}, |
| 141 | packages=['foobar'], |
| 142 | ) |
| 143 | </pre></div> |
| 144 | |
| 145 | <P> |
| 146 | Or, you might put modules from your main package right in the |
| 147 | distribution root: |
| 148 | <div class="verbatim"><pre> |
| 149 | <root>/ |
| 150 | setup.py |
| 151 | __init__.py |
| 152 | foo.py |
| 153 | bar.py |
| 154 | </pre></div> |
| 155 | in which case your setup script would be |
| 156 | <div class="verbatim"><pre> |
| 157 | from distutils.core import setup |
| 158 | setup(name='foobar', |
| 159 | version='1.0', |
| 160 | package_dir={'foobar': ''}, |
| 161 | packages=['foobar'], |
| 162 | ) |
| 163 | </pre></div> |
| 164 | (The empty string also stands for the current directory.) |
| 165 | |
| 166 | <P> |
| 167 | If you have sub-packages, they must be explicitly listed in |
| 168 | <span class="du-option">packages</span>, but any entries in <span class="du-option">package_dir</span> |
| 169 | automatically extend to sub-packages. (In other words, the Distutils |
| 170 | does <em>not</em> scan your source tree, trying to figure out which |
| 171 | directories correspond to Python packages by looking for |
| 172 | <span class="file">__init__.py</span> files.) Thus, if the default layout grows a |
| 173 | sub-package: |
| 174 | <div class="verbatim"><pre> |
| 175 | <root>/ |
| 176 | setup.py |
| 177 | foobar/ |
| 178 | __init__.py |
| 179 | foo.py |
| 180 | bar.py |
| 181 | subfoo/ |
| 182 | __init__.py |
| 183 | blah.py |
| 184 | </pre></div> |
| 185 | then the corresponding setup script would be |
| 186 | <div class="verbatim"><pre> |
| 187 | from distutils.core import setup |
| 188 | setup(name='foobar', |
| 189 | version='1.0', |
| 190 | packages=['foobar', 'foobar.subfoo'], |
| 191 | ) |
| 192 | </pre></div> |
| 193 | (Again, the empty string in <span class="du-option">package_dir</span> stands for the current |
| 194 | directory.) |
| 195 | |
| 196 | <P> |
| 197 | |
| 198 | <DIV CLASS="navigation"> |
| 199 | <div class='online-navigation'> |
| 200 | <p></p><hr /> |
| 201 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 202 | <tr> |
| 203 | <td class='online-navigation'><a rel="prev" title="7.1 Pure Python distribution" |
| 204 | href="pure-mod.html"><img src='../icons/previous.png' |
| 205 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 206 | <td class='online-navigation'><a rel="parent" title="7. Examples" |
| 207 | href="examples.html"><img src='../icons/up.png' |
| 208 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 209 | <td class='online-navigation'><a rel="next" title="7.3 Single extension module" |
| 210 | href="single-ext.html"><img src='../icons/next.png' |
| 211 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 212 | <td align="center" width="100%">Distributing Python Modules</td> |
| 213 | <td class='online-navigation'><img src='../icons/blank.png' |
| 214 | border='0' height='32' alt='' width='32' /></td> |
| 215 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 216 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 217 | <td class='online-navigation'><a rel="index" title="Index" |
| 218 | href="genindex.html"><img src='../icons/index.png' |
| 219 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 220 | </tr></table> |
| 221 | <div class='online-navigation'> |
| 222 | <b class="navlabel">Previous:</b> |
| 223 | <a class="sectref" rel="prev" href="pure-mod.html">7.1 Pure Python distribution</A> |
| 224 | <b class="navlabel">Up:</b> |
| 225 | <a class="sectref" rel="parent" href="examples.html">7. Examples</A> |
| 226 | <b class="navlabel">Next:</b> |
| 227 | <a class="sectref" rel="next" href="single-ext.html">7.3 Single extension module</A> |
| 228 | </div> |
| 229 | </div> |
| 230 | <hr /> |
| 231 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 232 | </DIV> |
| 233 | <!--End of Navigation Panel--> |
| 234 | <ADDRESS> |
| 235 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 236 | </ADDRESS> |
| 237 | </BODY> |
| 238 | </HTML> |