blob: 2165b56fd400f514910db5231275c7118d26b7b7 [file] [log] [blame]
Éric Araujo3a9f58f2011-06-01 20:42:49 +02001.. _packaging-command-reference:
2
3*****************
4Command Reference
5*****************
6
7This reference briefly documents all standard Packaging commands and some of
8their options.
9
10.. FIXME does not work: Use pysetup run --help-commands to list all
11 standard and extra commands availavble on your system, with their
12 description. Use pysetup run <command> --help to get help about the options
13 of one command.
14
Éric Araujo7dc76fd2011-08-06 16:58:15 +020015.. XXX sections from this document should be merged with other docs (e.g. check
16 and upload with uploading.rst, install_* with install/install.rst, etc.);
17 there is no value in partially duplicating information. this file could
18 however serve as an index, i.e. just a list of all commands with links to
19 every section that describes options or usage
20
Éric Araujo3a9f58f2011-06-01 20:42:49 +020021
22Preparing distributions
23=======================
24
25:command:`check`
26----------------
27
28Perform some tests on the metadata of a distribution.
29
30For example, it verifies that all required metadata fields are provided in the
31:file:`setup.cfg` file.
32
33.. TODO document reST checks
34
35
36:command:`test`
37---------------
38
39Run a test suite.
40
41When doing test-driven development, or running automated builds that need
42testing before they are installed for downloading or use, it's often useful to
43be able to run a project's unit tests without actually installing the project
44anywhere. The :command:`test` command runs project's unit tests without
45actually installing it, by temporarily putting the project's source on
46:data:`sys.path`, after first running :command:`build_ext -i` to ensure that any
47C extensions are built.
48
49You can use this command in one of two ways: either by specifying a
50unittest-compatible test suite for your project (or any callable that returns
51it) or by passing a test runner function that will run your tests and display
52results in the console. Both options take a Python dotted name in the form
53``package.module.callable`` to specify the object to use.
54
55If none of these options are specified, Packaging will try to perform test
56discovery using either unittest (for Python 3.2 and higher) or unittest2 (for
57older versions, if installed).
58
59.. this is a pseudo-command name used to disambiguate the options in indexes and
60 links
61.. program:: packaging test
62
63.. cmdoption:: --suite=NAME, -s NAME
64
65 Specify the test suite (or module, class, or method) to be run. The default
Georg Brandld3b41c62011-07-09 11:48:50 +020066 for this option can be set by in the project's :file:`setup.cfg` file:
Éric Araujo3a9f58f2011-06-01 20:42:49 +020067
68 .. code-block:: cfg
69
70 [test]
71 suite = mypackage.tests.get_all_tests
72
73.. cmdoption:: --runner=NAME, -r NAME
74
75 Specify the test runner to be called.
76
77
78:command:`config`
79-----------------
80
81Perform distribution configuration.
82
83
84The build step
85==============
86
87This step is mainly useful to compile C/C++ libraries or extension modules. The
88build commands can be run manually to check for syntax errors or packaging
89issues (for example if the addition of a new source file was forgotten in the
90:file:`setup.cfg` file), and is also run automatically by commands which need
91it. Packaging checks the mtime of source and built files to avoid re-building
92if it's not necessary.
93
94
95:command:`build`
96----------------
97
98Build all files of a distribution, delegating to the other :command:`build_*`
99commands to do the work.
100
101
102:command:`build_clib`
103---------------------
104
105Build C libraries.
106
107
108:command:`build_ext`
109--------------------
110
111Build C/C++ extension modules.
112
113
114:command:`build_py`
115-------------------
116
117Build the Python modules (just copy them to the build directory) and
Éric Araujo88080152011-11-03 05:08:28 +0100118:term:`byte-compile <bytecode>` them to :file:`.pyc` and/or :file:`.pyo` files.
119
120The byte compilation is controlled by two sets of options:
121
122- ``--compile`` and ``--no-compile`` are used to control the creation of
123 :file:`.pyc` files; the default is ``--no-compile``.
124
125- ``--optimize N`` (or ``-ON``) is used to control the creation of :file:`.pyo`
126 files: ``-O1`` turns on basic optimizations, ``-O2`` also discards docstrings,
127 ``-O0`` does not create :file:`.pyo` files; the default is ``-O0``.
128
129You can mix and match these options: for example, ``--no-compile --optimize 2``
130will create :file:`.pyo` files but no :file:`.pyc` files.
131
132.. XXX these option roles do not work
133
134Calling Python with :option:`-O` or :option:`-B` does not control the creation
135of bytecode files, only the options described above do.
Éric Araujo3a9f58f2011-06-01 20:42:49 +0200136
137
138:command:`build_scripts`
139------------------------
140Build the scripts (just copy them to the build directory and adjust their
141shebang if they're Python scripts).
142
143
144:command:`clean`
145----------------
146
147Clean the build tree of the release.
148
149.. program:: packaging clean
150
151.. cmdoption:: --all, -a
152
153 Remove build directories for modules, scripts, etc., not only temporary build
154 by-products.
155
156
157Creating source and built distributions
158=======================================
159
160:command:`sdist`
161----------------
162
163Build a source distribution for a release.
164
165It is recommended that you always build and upload a source distribution. Users
166of OSes with easy access to compilers and users of advanced packaging tools will
167prefer to compile from source rather than using pre-built distributions. For
168Windows users, providing a binary installer is also recommended practice.
169
170
171:command:`bdist`
172----------------
173
174Build a binary distribution for a release.
175
176This command will call other :command:`bdist_*` commands to create one or more
177distributions depending on the options given. The default is to create a
178.tar.gz archive on Unix and a zip archive on Windows or OS/2.
179
180.. program:: packaging bdist
181
182.. cmdoption:: --formats
183
184 Binary formats to build (comma-separated list).
185
186.. cmdoption:: --show-formats
187
188 Dump list of available formats.
189
190
191:command:`bdist_dumb`
192---------------------
193
194Build a "dumb" installer, a simple archive of files that could be unpacked under
195``$prefix`` or ``$exec_prefix``.
196
197
198:command:`bdist_wininst`
199------------------------
200
201Build a Windows installer.
202
203
204:command:`bdist_msi`
205--------------------
206
207Build a `Microsoft Installer`_ (.msi) file.
208
209.. _Microsoft Installer: http://msdn.microsoft.com/en-us/library/cc185688(VS.85).aspx
210
211In most cases, the :command:`bdist_msi` installer is a better choice than the
212:command:`bdist_wininst` installer, because it provides better support for Win64
213platforms, allows administrators to perform non-interactive installations, and
214allows installation through group policies.
215
216
217Publishing distributions
218========================
219
220:command:`register`
221-------------------
222
223This command registers the current release with the Python Package Index. This
224is described in more detail in :PEP:`301`.
225
226.. TODO explain user and project registration with the web UI
227
228
229:command:`upload`
230-----------------
231
232Upload source and/or binary distributions to PyPI.
233
234The distributions have to be built on the same command line as the
235:command:`upload` command; see :ref:`packaging-package-upload` for more info.
236
237.. program:: packaging upload
238
239.. cmdoption:: --sign, -s
240
241 Sign each uploaded file using GPG (GNU Privacy Guard). The ``gpg`` program
242 must be available for execution on the system ``PATH``.
243
244.. cmdoption:: --identity=NAME, -i NAME
245
246 Specify the identity or key name for GPG to use when signing. The value of
247 this option will be passed through the ``--local-user`` option of the
248 ``gpg`` program.
249
250.. cmdoption:: --show-response
251
252 Display the full response text from server; this is useful for debugging
253 PyPI problems.
254
255.. cmdoption:: --repository=URL, -r URL
256
257 The URL of the repository to upload to. Defaults to
258 http://pypi.python.org/pypi (i.e., the main PyPI installation).
259
260.. cmdoption:: --upload-docs
261
262 Also run :command:`upload_docs`. Mainly useful as a default value in
263 :file:`setup.cfg` (on the command line, it's shorter to just type both
264 commands).
265
266
267:command:`upload_docs`
268----------------------
269
270Upload HTML documentation to PyPI.
271
272PyPI now supports publishing project documentation at a URI of the form
273``http://packages.python.org/<project>``. :command:`upload_docs` will create
274the necessary zip file out of a documentation directory and will post to the
275repository.
276
277Note that to upload the documentation of a project, the corresponding version
278must already be registered with PyPI, using the :command:`register` command ---
279just like with :command:`upload`.
280
281Assuming there is an ``Example`` project with documentation in the subdirectory
282:file:`docs`, for example::
283
284 Example/
285 example.py
286 setup.cfg
287 docs/
288 build/
289 html/
290 index.html
291 tips_tricks.html
292 conf.py
293 index.txt
294 tips_tricks.txt
295
296You can simply specify the directory with the HTML files in your
297:file:`setup.cfg` file:
298
299.. code-block:: cfg
300
301 [upload_docs]
302 upload-dir = docs/build/html
303
304
305.. program:: packaging upload_docs
306
307.. cmdoption:: --upload-dir
308
309 The directory to be uploaded to the repository. By default documentation
310 is searched for in ``docs`` (or ``doc``) directory in project root.
311
312.. cmdoption:: --show-response
313
314 Display the full response text from server; this is useful for debugging
315 PyPI problems.
316
317.. cmdoption:: --repository=URL, -r URL
318
319 The URL of the repository to upload to. Defaults to
320 http://pypi.python.org/pypi (i.e., the main PyPI installation).
321
322
323The install step
324================
325
326These commands are used by end-users of a project using :program:`pysetup` or
327another compatible installer. Each command will run the corresponding
328:command:`build_*` command and then move the built files to their destination on
329the target system.
330
331
332:command:`install_dist`
333-----------------------
334
335Install a distribution, delegating to the other :command:`install_*` commands to
Éric Araujo7dc76fd2011-08-06 16:58:15 +0200336do the work. See :ref:`packaging-how-install-works` for complete usage
337instructions.
Éric Araujo3a9f58f2011-06-01 20:42:49 +0200338
339
340:command:`install_data`
341-----------------------
342
343Install data files.
344
345
346:command:`install_distinfo`
347---------------------------
348
349Install files recording details of the installation as specified in :PEP:`376`.
350
351
352:command:`install_headers`
353--------------------------
354
355Install C/C++ header files.
356
357
358:command:`install_lib`
359----------------------
360
Éric Araujo88080152011-11-03 05:08:28 +0100361Install all modules (extensions and pure Python).
362
363.. XXX what about C libraries created with build_clib?
364
365Similarly to ``build_py``, there are options to control the compilation of
366Python code to :term:`bytecode` files (see above). By default, :file:`.pyc`
367files will be created (``--compile``) and :file:`.pyo` files will not
368(``--optimize 0``).
Éric Araujo3a9f58f2011-06-01 20:42:49 +0200369
370
371:command:`install_scripts`
372--------------------------
373
374Install scripts.