Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 1 | .. _packaging-command-reference: |
| 2 | |
| 3 | ***************** |
| 4 | Command Reference |
| 5 | ***************** |
| 6 | |
| 7 | This reference briefly documents all standard Packaging commands and some of |
| 8 | their 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 Araujo | 7dc76fd | 2011-08-06 16:58:15 +0200 | [diff] [blame] | 15 | .. 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 Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 21 | |
| 22 | Preparing distributions |
| 23 | ======================= |
| 24 | |
| 25 | :command:`check` |
| 26 | ---------------- |
| 27 | |
| 28 | Perform some tests on the metadata of a distribution. |
| 29 | |
| 30 | For 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 | |
| 39 | Run a test suite. |
| 40 | |
| 41 | When doing test-driven development, or running automated builds that need |
| 42 | testing before they are installed for downloading or use, it's often useful to |
| 43 | be able to run a project's unit tests without actually installing the project |
| 44 | anywhere. The :command:`test` command runs project's unit tests without |
| 45 | actually 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 |
| 47 | C extensions are built. |
| 48 | |
| 49 | You can use this command in one of two ways: either by specifying a |
| 50 | unittest-compatible test suite for your project (or any callable that returns |
| 51 | it) or by passing a test runner function that will run your tests and display |
| 52 | results in the console. Both options take a Python dotted name in the form |
| 53 | ``package.module.callable`` to specify the object to use. |
| 54 | |
| 55 | If none of these options are specified, Packaging will try to perform test |
| 56 | discovery using either unittest (for Python 3.2 and higher) or unittest2 (for |
| 57 | older 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 Brandl | d3b41c6 | 2011-07-09 11:48:50 +0200 | [diff] [blame] | 66 | for this option can be set by in the project's :file:`setup.cfg` file: |
Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 67 | |
| 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 | |
| 81 | Perform distribution configuration. |
| 82 | |
| 83 | |
| 84 | The build step |
| 85 | ============== |
| 86 | |
| 87 | This step is mainly useful to compile C/C++ libraries or extension modules. The |
| 88 | build commands can be run manually to check for syntax errors or packaging |
| 89 | issues (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 |
| 91 | it. Packaging checks the mtime of source and built files to avoid re-building |
| 92 | if it's not necessary. |
| 93 | |
| 94 | |
| 95 | :command:`build` |
| 96 | ---------------- |
| 97 | |
| 98 | Build all files of a distribution, delegating to the other :command:`build_*` |
| 99 | commands to do the work. |
| 100 | |
| 101 | |
| 102 | :command:`build_clib` |
| 103 | --------------------- |
| 104 | |
| 105 | Build C libraries. |
| 106 | |
| 107 | |
| 108 | :command:`build_ext` |
| 109 | -------------------- |
| 110 | |
| 111 | Build C/C++ extension modules. |
| 112 | |
| 113 | |
| 114 | :command:`build_py` |
| 115 | ------------------- |
| 116 | |
| 117 | Build the Python modules (just copy them to the build directory) and |
Éric Araujo | 8808015 | 2011-11-03 05:08:28 +0100 | [diff] [blame] | 118 | :term:`byte-compile <bytecode>` them to :file:`.pyc` and/or :file:`.pyo` files. |
| 119 | |
| 120 | The 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 | |
| 129 | You can mix and match these options: for example, ``--no-compile --optimize 2`` |
| 130 | will create :file:`.pyo` files but no :file:`.pyc` files. |
| 131 | |
| 132 | .. XXX these option roles do not work |
| 133 | |
| 134 | Calling Python with :option:`-O` or :option:`-B` does not control the creation |
| 135 | of bytecode files, only the options described above do. |
Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 136 | |
| 137 | |
| 138 | :command:`build_scripts` |
| 139 | ------------------------ |
| 140 | Build the scripts (just copy them to the build directory and adjust their |
| 141 | shebang if they're Python scripts). |
| 142 | |
| 143 | |
| 144 | :command:`clean` |
| 145 | ---------------- |
| 146 | |
| 147 | Clean 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 | |
| 157 | Creating source and built distributions |
| 158 | ======================================= |
| 159 | |
| 160 | :command:`sdist` |
| 161 | ---------------- |
| 162 | |
| 163 | Build a source distribution for a release. |
| 164 | |
| 165 | It is recommended that you always build and upload a source distribution. Users |
| 166 | of OSes with easy access to compilers and users of advanced packaging tools will |
| 167 | prefer to compile from source rather than using pre-built distributions. For |
| 168 | Windows users, providing a binary installer is also recommended practice. |
| 169 | |
| 170 | |
| 171 | :command:`bdist` |
| 172 | ---------------- |
| 173 | |
| 174 | Build a binary distribution for a release. |
| 175 | |
| 176 | This command will call other :command:`bdist_*` commands to create one or more |
| 177 | distributions 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 | |
| 194 | Build 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 | |
| 201 | Build a Windows installer. |
| 202 | |
| 203 | |
| 204 | :command:`bdist_msi` |
| 205 | -------------------- |
| 206 | |
| 207 | Build a `Microsoft Installer`_ (.msi) file. |
| 208 | |
| 209 | .. _Microsoft Installer: http://msdn.microsoft.com/en-us/library/cc185688(VS.85).aspx |
| 210 | |
| 211 | In 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 |
| 213 | platforms, allows administrators to perform non-interactive installations, and |
| 214 | allows installation through group policies. |
| 215 | |
| 216 | |
| 217 | Publishing distributions |
| 218 | ======================== |
| 219 | |
| 220 | :command:`register` |
| 221 | ------------------- |
| 222 | |
| 223 | This command registers the current release with the Python Package Index. This |
| 224 | is 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 | |
| 232 | Upload source and/or binary distributions to PyPI. |
| 233 | |
| 234 | The 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 | |
| 270 | Upload HTML documentation to PyPI. |
| 271 | |
| 272 | PyPI now supports publishing project documentation at a URI of the form |
| 273 | ``http://packages.python.org/<project>``. :command:`upload_docs` will create |
| 274 | the necessary zip file out of a documentation directory and will post to the |
| 275 | repository. |
| 276 | |
| 277 | Note that to upload the documentation of a project, the corresponding version |
| 278 | must already be registered with PyPI, using the :command:`register` command --- |
| 279 | just like with :command:`upload`. |
| 280 | |
| 281 | Assuming 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 | |
| 296 | You 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 | |
| 323 | The install step |
| 324 | ================ |
| 325 | |
| 326 | These commands are used by end-users of a project using :program:`pysetup` or |
| 327 | another compatible installer. Each command will run the corresponding |
| 328 | :command:`build_*` command and then move the built files to their destination on |
| 329 | the target system. |
| 330 | |
| 331 | |
| 332 | :command:`install_dist` |
| 333 | ----------------------- |
| 334 | |
| 335 | Install a distribution, delegating to the other :command:`install_*` commands to |
Éric Araujo | 7dc76fd | 2011-08-06 16:58:15 +0200 | [diff] [blame] | 336 | do the work. See :ref:`packaging-how-install-works` for complete usage |
| 337 | instructions. |
Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 338 | |
| 339 | |
| 340 | :command:`install_data` |
| 341 | ----------------------- |
| 342 | |
| 343 | Install data files. |
| 344 | |
| 345 | |
| 346 | :command:`install_distinfo` |
| 347 | --------------------------- |
| 348 | |
| 349 | Install files recording details of the installation as specified in :PEP:`376`. |
| 350 | |
| 351 | |
| 352 | :command:`install_headers` |
| 353 | -------------------------- |
| 354 | |
| 355 | Install C/C++ header files. |
| 356 | |
| 357 | |
| 358 | :command:`install_lib` |
| 359 | ---------------------- |
| 360 | |
Éric Araujo | 8808015 | 2011-11-03 05:08:28 +0100 | [diff] [blame] | 361 | Install all modules (extensions and pure Python). |
| 362 | |
| 363 | .. XXX what about C libraries created with build_clib? |
| 364 | |
| 365 | Similarly to ``build_py``, there are options to control the compilation of |
| 366 | Python code to :term:`bytecode` files (see above). By default, :file:`.pyc` |
| 367 | files will be created (``--compile``) and :file:`.pyo` files will not |
| 368 | (``--optimize 0``). |
Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 369 | |
| 370 | |
| 371 | :command:`install_scripts` |
| 372 | -------------------------- |
| 373 | |
| 374 | Install scripts. |