Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / dist / pure-pkg.html
CommitLineData
920dae64
AT
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>
567.2 Pure Python distribution (by package)
57</H1>
58
59<P>
60If you have more than a couple of modules to distribute, especially if
61they are in multiple packages, it's probably easier to specify whole
62packages rather than individual modules. This works even if your
63modules are not in a package; you can just tell the Distutils to process
64modules from the root package, and that works the same as any other
65package (except that you don't have to have an <span class="file">__init__.py</span>
66file).
67
68<P>
69The setup script from the last example could also be written as
70<div class="verbatim"><pre>
71from distutils.core import setup
72setup(name='foobar',
73 version='1.0',
74 packages=[''],
75 )
76</pre></div>
77(The empty string stands for the root package.)
78
79<P>
80If those two files are moved into a subdirectory, but remain in the root
81package, e.g.:
82<div class="verbatim"><pre>
83&lt;root&gt;/
84 setup.py
85 src/ foo.py
86 bar.py
87</pre></div>
88then you would still specify the root package, but you have to tell the
89Distutils where source files in the root package live:
90<div class="verbatim"><pre>
91from distutils.core import setup
92setup(name='foobar',
93 version='1.0',
94 package_dir={'': 'src'},
95 packages=[''],
96 )
97</pre></div>
98
99<P>
100More typically, though, you will want to distribute multiple modules in
101the same package (or in sub-packages). For example, if the <tt class="module">foo</tt>
102and <tt class="module">bar</tt> modules belong in package <tt class="module">foobar</tt>, one way to
103layout your source tree is
104<div class="verbatim"><pre>
105&lt;root&gt;/
106 setup.py
107 foobar/
108 __init__.py
109 foo.py
110 bar.py
111</pre></div>
112This is in fact the default layout expected by the Distutils, and the
113one that requires the least work to describe in your setup script:
114<div class="verbatim"><pre>
115from distutils.core import setup
116setup(name='foobar',
117 version='1.0',
118 packages=['foobar'],
119 )
120</pre></div>
121
122<P>
123If you want to put modules in directories not named for their package,
124then you need to use the <span class="du-option">package_dir</span> option again. For
125example, 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&lt;root&gt;/
129 setup.py
130 src/
131 __init__.py
132 foo.py
133 bar.py
134</pre></div>
135an appropriate setup script would be
136<div class="verbatim"><pre>
137from distutils.core import setup
138setup(name='foobar',
139 version='1.0',
140 package_dir={'foobar': 'src'},
141 packages=['foobar'],
142 )
143</pre></div>
144
145<P>
146Or, you might put modules from your main package right in the
147distribution root:
148<div class="verbatim"><pre>
149&lt;root&gt;/
150 setup.py
151 __init__.py
152 foo.py
153 bar.py
154</pre></div>
155in which case your setup script would be
156<div class="verbatim"><pre>
157from distutils.core import setup
158setup(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>
167If 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>
169automatically extend to sub-packages. (In other words, the Distutils
170does <em>not</em> scan your source tree, trying to figure out which
171directories correspond to Python packages by looking for
172<span class="file">__init__.py</span> files.) Thus, if the default layout grows a
173sub-package:
174<div class="verbatim"><pre>
175&lt;root&gt;/
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>
185then the corresponding setup script would be
186<div class="verbatim"><pre>
187from distutils.core import setup
188setup(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
194directory.)
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>
235See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
236</ADDRESS>
237</BODY>
238</HTML>