1-----------------
2Command Reference
3-----------------
4
5.. _alias:
6
7``alias`` - Define shortcuts for commonly used commands
8=======================================================
9
10Sometimes, you need to use the same commands over and over, but you can't
11necessarily set them as defaults.  For example, if you produce both development
12snapshot releases and "stable" releases of a project, you may want to put
13the distributions in different places, or use different ``egg_info`` tagging
14options, etc.  In these cases, it doesn't make sense to set the options in
15a distutils configuration file, because the values of the options changed based
16on what you're trying to do.
17
18Setuptools therefore allows you to define "aliases" - shortcut names for
19an arbitrary string of commands and options, using ``setup.py alias aliasname
20expansion``, where aliasname is the name of the new alias, and the remainder of
21the command line supplies its expansion.  For example, this command defines
22a sitewide alias called "daily", that sets various ``egg_info`` tagging
23options::
24
25    setup.py alias --global-config daily egg_info --tag-build=development
26
27Once the alias is defined, it can then be used with other setup commands,
28e.g.::
29
30    setup.py daily bdist_egg        # generate a daily-build .egg file
31    setup.py daily sdist            # generate a daily-build source distro
32    setup.py daily sdist bdist_egg  # generate both
33
34The above commands are interpreted as if the word ``daily`` were replaced with
35``egg_info --tag-build=development``.
36
37Note that setuptools will expand each alias *at most once* in a given command
38line.  This serves two purposes.  First, if you accidentally create an alias
39loop, it will have no effect; you'll instead get an error message about an
40unknown command.  Second, it allows you to define an alias for a command, that
41uses that command.  For example, this (project-local) alias::
42
43    setup.py alias bdist_egg bdist_egg rotate -k1 -m.egg
44
45redefines the ``bdist_egg`` command so that it always runs the ``rotate``
46command afterwards to delete all but the newest egg file.  It doesn't loop
47indefinitely on ``bdist_egg`` because the alias is only expanded once when
48used.
49
50You can remove a defined alias with the ``--remove`` (or ``-r``) option, e.g.::
51
52    setup.py alias --global-config --remove daily
53
54would delete the "daily" alias we defined above.
55
56Aliases can be defined on a project-specific, per-user, or sitewide basis.  The
57default is to define or remove a project-specific alias, but you can use any of
58the `configuration file options`_ (listed under the `saveopts`_ command, below)
59to determine which distutils configuration file an aliases will be added to
60(or removed from).
61
62Note that if you omit the "expansion" argument to the ``alias`` command,
63you'll get output showing that alias' current definition (and what
64configuration file it's defined in).  If you omit the alias name as well,
65you'll get a listing of all current aliases along with their configuration
66file locations.
67
68
69``bdist_egg`` - Create a Python Egg for the project
70===================================================
71
72.. warning::
73    **eggs** are deprecated in favor of wheels, and not supported by pip.
74
75This command generates a Python Egg (``.egg`` file) for the project.  Python
76Eggs are the preferred binary distribution format for EasyInstall, because they
77are cross-platform (for "pure" packages), directly importable, and contain
78project metadata including scripts and information about the project's
79dependencies.  They can be simply downloaded and added to ``sys.path``
80directly, or they can be placed in a directory on ``sys.path`` and then
81automatically discovered by the egg runtime system.
82
83This command runs the `egg_info`_ command (if it hasn't already run) to update
84the project's metadata (``.egg-info``) directory.  If you have added any extra
85metadata files to the ``.egg-info`` directory, those files will be included in
86the new egg file's metadata directory, for use by the egg runtime system or by
87any applications or frameworks that use that metadata.
88
89You won't usually need to specify any special options for this command; just
90use ``bdist_egg`` and you're done.  But there are a few options that may
91be occasionally useful:
92
93``--dist-dir=DIR, -d DIR``
94    Set the directory where the ``.egg`` file will be placed.  If you don't
95    supply this, then the ``--dist-dir`` setting of the ``bdist`` command
96    will be used, which is usually a directory named ``dist`` in the project
97    directory.
98
99``--plat-name=PLATFORM, -p PLATFORM``
100    Set the platform name string that will be embedded in the egg's filename
101    (assuming the egg contains C extensions).  This can be used to override
102    the distutils default platform name with something more meaningful.  Keep
103    in mind, however, that the egg runtime system expects to see eggs with
104    distutils platform names, so it may ignore or reject eggs with non-standard
105    platform names.  Similarly, the EasyInstall program may ignore them when
106    searching web pages for download links.  However, if you are
107    cross-compiling or doing some other unusual things, you might find a use
108    for this option.
109
110``--exclude-source-files``
111    Don't include any modules' ``.py`` files in the egg, just compiled Python,
112    C, and data files.  (Note that this doesn't affect any ``.py`` files in the
113    EGG-INFO directory or its subdirectories, since for example there may be
114    scripts with a ``.py`` extension which must still be retained.)  We don't
115    recommend that you use this option except for packages that are being
116    bundled for proprietary end-user applications, or for "embedded" scenarios
117    where space is at an absolute premium.  On the other hand, if your package
118    is going to be installed and used in compressed form, you might as well
119    exclude the source because Python's ``traceback`` module doesn't currently
120    understand how to display zipped source code anyway, or how to deal with
121    files that are in a different place from where their code was compiled.
122
123There are also some options you will probably never need, but which are there
124because they were copied from similar ``bdist`` commands used as an example for
125creating this one.  They may be useful for testing and debugging, however,
126which is why we kept them:
127
128``--keep-temp, -k``
129    Keep the contents of the ``--bdist-dir`` tree around after creating the
130    ``.egg`` file.
131
132``--bdist-dir=DIR, -b DIR``
133    Set the temporary directory for creating the distribution.  The entire
134    contents of this directory are zipped to create the ``.egg`` file, after
135    running various installation commands to copy the package's modules, data,
136    and extensions here.
137
138``--skip-build``
139    Skip doing any "build" commands; just go straight to the
140    install-and-compress phases.
141
142
143.. _develop:
144
145``develop`` - Deploy the project source in "Development Mode"
146=============================================================
147
148This command allows you to deploy your project's source for use in one or more
149"staging areas" where it will be available for importing.  This deployment is
150done in such a way that changes to the project source are immediately available
151in the staging area(s), without needing to run a build or install step after
152each change.
153
154The ``develop`` command works by creating an ``.egg-link`` file (named for the
155project) in the given staging area.  If the staging area is Python's
156``site-packages`` directory, it also updates an ``easy-install.pth`` file so
157that the project is on ``sys.path`` by default for all programs run using that
158Python installation.
159
160The ``develop`` command also installs wrapper scripts in the staging area (or
161a separate directory, as specified) that will ensure the project's dependencies
162are available on ``sys.path`` before running the project's source scripts.
163And, it ensures that any missing project dependencies are available in the
164staging area, by downloading and installing them if necessary.
165
166Last, but not least, the ``develop`` command invokes the ``build_ext -i``
167command to ensure any C extensions in the project have been built and are
168up-to-date, and the ``egg_info`` command to ensure the project's metadata is
169updated (so that the runtime and wrappers know what the project's dependencies
170are).  If you make any changes to the project's setup script or C extensions,
171you should rerun the ``develop`` command against all relevant staging areas to
172keep the project's scripts, metadata and extensions up-to-date.  Most other
173kinds of changes to your project should not require any build operations or
174rerunning ``develop``, but keep in mind that even minor changes to the setup
175script (e.g. changing an entry point definition) require you to re-run the
176``develop`` or ``test`` commands to keep the distribution updated.
177
178Here are some of the options that the ``develop`` command accepts.  Note that
179they affect the project's dependencies as well as the project itself, so if you
180have dependencies that need to be installed and you use ``--exclude-scripts``
181(for example), the dependencies' scripts will not be installed either!  For
182this reason, you may want to use pip to install the project's dependencies
183before using the ``develop`` command, if you need finer control over the
184installation options for dependencies.
185
186``--uninstall, -u``
187    Un-deploy the current project.  You may use the ``--install-dir`` or ``-d``
188    option to designate the staging area.  The created ``.egg-link`` file will
189    be removed, if present and it is still pointing to the project directory.
190    The project directory will be removed from ``easy-install.pth`` if the
191    staging area is Python's ``site-packages`` directory.
192
193    Note that this option currently does *not* uninstall script wrappers!  You
194    must uninstall them yourself, or overwrite them by using pip to install a
195    different version of the package.  You can also avoid installing script
196    wrappers in the first place, if you use the ``--exclude-scripts`` (aka
197    ``-x``) option when you run ``develop`` to deploy the project.
198
199``--multi-version, -m``
200    "Multi-version" mode. Specifying this option prevents ``develop`` from
201    adding an ``easy-install.pth`` entry for the project(s) being deployed, and
202    if an entry for any version of a project already exists, the entry will be
203    removed upon successful deployment.  In multi-version mode, no specific
204    version of the package is available for importing, unless you use
205    ``pkg_resources.require()`` to put it on ``sys.path``, or you are running
206    a wrapper script generated by ``setuptools``.  (In which case the wrapper
207    script calls ``require()`` for you.)
208
209    Note that if you install to a directory other than ``site-packages``,
210    this option is automatically in effect, because ``.pth`` files can only be
211    used in ``site-packages`` (at least in Python 2.3 and 2.4). So, if you use
212    the ``--install-dir`` or ``-d`` option (or they are set via configuration
213    file(s)) your project and its dependencies will be deployed in multi-
214    version mode.
215
216``--install-dir=DIR, -d DIR``
217    Set the installation directory (staging area).  If this option is not
218    directly specified on the command line or in a distutils configuration
219    file, the distutils default installation location is used.  Normally, this
220    will be the ``site-packages`` directory, but if you are using distutils
221    configuration files, setting things like ``prefix`` or ``install_lib``,
222    then those settings are taken into account when computing the default
223    staging area.
224
225``--script-dir=DIR, -s DIR``
226    Set the script installation directory.  If you don't supply this option
227    (via the command line or a configuration file), but you *have* supplied
228    an ``--install-dir`` (via command line or config file), then this option
229    defaults to the same directory, so that the scripts will be able to find
230    their associated package installation.  Otherwise, this setting defaults
231    to the location where the distutils would normally install scripts, taking
232    any distutils configuration file settings into account.
233
234``--exclude-scripts, -x``
235    Don't deploy script wrappers.  This is useful if you don't want to disturb
236    existing versions of the scripts in the staging area.
237
238``--always-copy, -a``
239    Copy all needed distributions to the staging area, even if they
240    are already present in another directory on ``sys.path``.  By default, if
241    a requirement can be met using a distribution that is already available in
242    a directory on ``sys.path``, it will not be copied to the staging area.
243
244``--egg-path=DIR``
245    Force the generated ``.egg-link`` file to use a specified relative path
246    to the source directory.  This can be useful in circumstances where your
247    installation directory is being shared by code running under multiple
248    platforms (e.g. Mac and Windows) which have different absolute locations
249    for the code under development, but the same *relative* locations with
250    respect to the installation directory.  If you use this option when
251    installing, you must supply the same relative path when uninstalling.
252
253In addition to the above options, the ``develop`` command also accepts all of
254the same options accepted by ``easy_install``.  If you've configured any
255``easy_install`` settings in your ``setup.cfg`` (or other distutils config
256files), the ``develop`` command will use them as defaults, unless you override
257them in a ``[develop]`` section or on the command line.
258
259
260.. _egg_info:
261
262``egg_info`` - Create egg metadata and set build tags
263=====================================================
264
265This command performs two operations: it updates a project's ``.egg-info``
266metadata directory (used by the ``bdist_egg``, ``develop``, and ``test``
267commands), and it allows you to temporarily change a project's version string,
268to support "daily builds" or "snapshot" releases.  It is run automatically by
269the ``sdist``, ``bdist_egg``, ``develop``, and ``test`` commands in order to
270update the project's metadata, but you can also specify it explicitly in order
271to temporarily change the project's version string while executing other
272commands.  (It also generates the ``.egg-info/SOURCES.txt`` manifest file, which
273is used when you are building source distributions.)
274
275In addition to writing the core egg metadata defined by ``setuptools`` and
276required by ``pkg_resources``, this command can be extended to write other
277metadata files as well, by defining entry points in the ``egg_info.writers``
278group.  See the section on :ref:`Adding new EGG-INFO Files` below for more details.
279Note that using additional metadata writers may require you to include a
280``setup_requires`` argument to ``setup()`` in order to ensure that the desired
281writers are available on ``sys.path``.
282
283
284Release Tagging Options
285-----------------------
286
287The following options can be used to modify the project's version string for
288all remaining commands on the setup command line.  The options are processed
289in the order shown, so if you use more than one, the requested tags will be
290added in the following order:
291
292``--tag-build=NAME, -b NAME``
293    Append NAME to the project's version string.  Due to the way setuptools
294    processes "pre-release" version suffixes beginning with the letters "a"
295    through "e" (like "alpha", "beta", and "candidate"), you will usually want
296    to use a tag like ".build" or ".dev", as this will cause the version number
297    to be considered *lower* than the project's default version.  (If you
298    want to make the version number *higher* than the default version, you can
299    always leave off --tag-build and then use one or both of the following
300    options.)
301
302    If you have a default build tag set in your ``setup.cfg``, you can suppress
303    it on the command line using ``-b ""`` or ``--tag-build=""`` as an argument
304    to the ``egg_info`` command.
305
306``--tag-date, -d``
307    Add a date stamp of the form "-YYYYMMDD" (e.g. "-20050528") to the
308    project's version number.
309
310``--no-date, -D``
311    Don't include a date stamp in the version number.  This option is included
312    so you can override a default setting in ``setup.cfg``.
313
314
315(Note: Because these options modify the version number used for source and
316binary distributions of your project, you should first make sure that you know
317how the resulting version numbers will be interpreted by automated tools
318like pip.  See the section above on :ref:`Specifying Your Project's Version` for an
319explanation of pre- and post-release tags, as well as tips on how to choose and
320verify a versioning scheme for your project.)
321
322For advanced uses, there is one other option that can be set, to change the
323location of the project's ``.egg-info`` directory.  Commands that need to find
324the project's source directory or metadata should get it from this setting:
325
326
327Other ``egg_info`` Options
328--------------------------
329
330``--egg-base=SOURCEDIR, -e SOURCEDIR``
331    Specify the directory that should contain the .egg-info directory.  This
332    should normally be the root of your project's source tree (which is not
333    necessarily the same as your project directory; some projects use a ``src``
334    or ``lib`` subdirectory as the source root).  You should not normally need
335    to specify this directory, as it is normally determined from the
336    ``package_dir`` argument to the ``setup()`` function, if any.  If there is
337    no ``package_dir`` set, this option defaults to the current directory.
338
339
340``egg_info`` Examples
341---------------------
342
343Creating a dated "nightly build" snapshot egg::
344
345    setup.py egg_info --tag-date --tag-build=DEV bdist_egg
346
347Creating a release with no version tags, even if some default tags are
348specified in ``setup.cfg``::
349
350    setup.py egg_info -RDb "" sdist bdist_egg
351
352(Notice that ``egg_info`` must always appear on the command line *before* any
353commands that you want the version changes to apply to.)
354
355.. _rotate:
356
357``rotate`` - Delete outdated distribution files
358===============================================
359
360As you develop new versions of your project, your distribution (``dist``)
361directory will gradually fill up with older source and/or binary distribution
362files.  The ``rotate`` command lets you automatically clean these up, keeping
363only the N most-recently modified files matching a given pattern.
364
365``--match=PATTERNLIST, -m PATTERNLIST``
366    Comma-separated list of glob patterns to match.  This option is *required*.
367    The project name and ``-*`` is prepended to the supplied patterns, in order
368    to match only distributions belonging to the current project (in case you
369    have a shared distribution directory for multiple projects).  Typically,
370    you will use a glob pattern like ``.zip`` or ``.egg`` to match files of
371    the specified type.  Note that each supplied pattern is treated as a
372    distinct group of files for purposes of selecting files to delete.
373
374``--keep=COUNT, -k COUNT``
375    Number of matching distributions to keep.  For each group of files
376    identified by a pattern specified with the ``--match`` option, delete all
377    but the COUNT most-recently-modified files in that group.  This option is
378    *required*.
379
380``--dist-dir=DIR, -d DIR``
381    Directory where the distributions are.  This defaults to the value of the
382    ``bdist`` command's ``--dist-dir`` option, which will usually be the
383    project's ``dist`` subdirectory.
384
385**Example 1**: Delete all .tar.gz files from the distribution directory, except
386for the 3 most recently modified ones::
387
388    setup.py rotate --match=.tar.gz --keep=3
389
390**Example 2**: Delete all Python 2.3 or Python 2.4 eggs from the distribution
391directory, except the most recently modified one for each Python version::
392
393    setup.py rotate --match=-py2.3*.egg,-py2.4*.egg --keep=1
394
395
396.. _saveopts:
397
398``saveopts`` - Save used options to a configuration file
399========================================================
400
401Finding and editing ``distutils`` configuration files can be a pain, especially
402since you also have to translate the configuration options from command-line
403form to the proper configuration file format.  You can avoid these hassles by
404using the ``saveopts`` command.  Just add it to the command line to save the
405options you used.  For example, this command builds the project using
406the ``mingw32`` C compiler, then saves the --compiler setting as the default
407for future builds (even those run implicitly by the ``install`` command)::
408
409    setup.py build --compiler=mingw32 saveopts
410
411The ``saveopts`` command saves all options for every command specified on the
412command line to the project's local ``setup.cfg`` file, unless you use one of
413the `configuration file options`_ to change where the options are saved.  For
414example, this command does the same as above, but saves the compiler setting
415to the site-wide (global) distutils configuration::
416
417    setup.py build --compiler=mingw32 saveopts -g
418
419Note that it doesn't matter where you place the ``saveopts`` command on the
420command line; it will still save all the options specified for all commands.
421For example, this is another valid way to spell the last example::
422
423    setup.py saveopts -g build --compiler=mingw32
424
425Note, however, that all of the commands specified are always run, regardless of
426where ``saveopts`` is placed on the command line.
427
428
429Configuration File Options
430--------------------------
431
432Normally, settings such as options and aliases are saved to the project's
433local ``setup.cfg`` file.  But you can override this and save them to the
434global or per-user configuration files, or to a manually-specified filename.
435
436``--global-config, -g``
437    Save settings to the global ``distutils.cfg`` file inside the ``distutils``
438    package directory.  You must have write access to that directory to use
439    this option.  You also can't combine this option with ``-u`` or ``-f``.
440
441``--user-config, -u``
442    Save settings to the current user's ``~/.pydistutils.cfg`` (POSIX) or
443    ``$HOME/pydistutils.cfg`` (Windows) file.  You can't combine this option
444    with ``-g`` or ``-f``.
445
446``--filename=FILENAME, -f FILENAME``
447    Save settings to the specified configuration file to use.  You can't
448    combine this option with ``-g`` or ``-u``.  Note that if you specify a
449    non-standard filename, the ``distutils`` and ``setuptools`` will not
450    use the file's contents.  This option is mainly included for use in
451    testing.
452
453These options are used by other ``setuptools`` commands that modify
454configuration files, such as the `alias`_ and `setopt`_ commands.
455
456
457.. _setopt:
458
459``setopt`` - Set a distutils or setuptools option in a config file
460==================================================================
461
462This command is mainly for use by scripts, but it can also be used as a quick
463and dirty way to change a distutils configuration option without having to
464remember what file the options are in and then open an editor.
465
466**Example 1**.  Set the default C compiler to ``mingw32`` (using long option
467names)::
468
469    setup.py setopt --command=build --option=compiler --set-value=mingw32
470
471**Example 2**.  Remove any setting for the distutils default package
472installation directory (short option names)::
473
474    setup.py setopt -c install -o install_lib -r
475
476
477Options for the ``setopt`` command:
478
479``--command=COMMAND, -c COMMAND``
480    Command to set the option for.  This option is required.
481
482``--option=OPTION, -o OPTION``
483    The name of the option to set.  This option is required.
484
485``--set-value=VALUE, -s VALUE``
486    The value to set the option to.  Not needed if ``-r`` or ``--remove`` is
487    set.
488
489``--remove, -r``
490    Remove (unset) the option, instead of setting it.
491
492In addition to the above options, you may use any of the `configuration file
493options`_ (listed under the `saveopts`_ command, above) to determine which
494distutils configuration file the option will be added to (or removed from).
495
496
497.. _test:
498
499``test`` - Build package and run a unittest suite
500=================================================
501
502.. warning::
503    ``test`` is deprecated and will be removed in a future version. Users
504    looking for a generic test entry point independent of test runner are
505    encouraged to use `tox <https://tox.readthedocs.io>`_.
506
507When doing test-driven development, or running automated builds that need
508testing before they are deployed for downloading or use, it's often useful
509to be able to run a project's unit tests without actually deploying the project
510anywhere, even using the ``develop`` command.  The ``test`` command runs a
511project's unit tests without actually deploying it, by temporarily putting the
512project's source on ``sys.path``, after first running ``build_ext -i`` and
513``egg_info`` to ensure that any C extensions and project metadata are
514up-to-date.
515
516To use this command, your project's tests must be wrapped in a ``unittest``
517test suite by either a function, a ``TestCase`` class or method, or a module
518or package containing ``TestCase`` classes.  If the named suite is a module,
519and the module has an ``additional_tests()`` function, it is called and the
520result (which must be a ``unittest.TestSuite``) is added to the tests to be
521run.  If the named suite is a package, any submodules and subpackages are
522recursively added to the overall test suite.  (Note: if your project specifies
523a ``test_loader``, the rules for processing the chosen ``test_suite`` may
524differ; see the :ref:`test_loader <test_loader>` documentation for more details.)
525
526Note that many test systems including ``doctest`` support wrapping their
527non-``unittest`` tests in ``TestSuite`` objects.  So, if you are using a test
528package that does not support this, we suggest you encourage its developers to
529implement test suite support, as this is a convenient and standard way to
530aggregate a collection of tests to be run under a common test harness.
531
532By default, tests will be run in the "verbose" mode of the ``unittest``
533package's text test runner, but you can get the "quiet" mode (just dots) if
534you supply the ``-q`` or ``--quiet`` option, either as a global option to
535the setup script (e.g. ``setup.py -q test``) or as an option for the ``test``
536command itself (e.g. ``setup.py test -q``).  There is one other option
537available:
538
539``--test-suite=NAME, -s NAME``
540    Specify the test suite (or module, class, or method) to be run
541    (e.g. ``some_module.test_suite``).  The default for this option can be
542    set by giving a ``test_suite`` argument to the ``setup()`` function, e.g.::
543
544        setup(
545            # ...
546            test_suite="my_package.tests.test_all"
547        )
548
549    If you did not set a ``test_suite`` in your ``setup()`` call, and do not
550    provide a ``--test-suite`` option, an error will occur.
551
552New in 41.5.0: Deprecated the test command.
553
554
555.. _upload:
556
557``upload`` - Upload source and/or egg distributions to PyPI
558===========================================================
559
560The ``upload`` command was deprecated in version 40.0 and removed in version
56142.0. Use `twine <https://pypi.org/p/twine>`_ instead.
562
563For  more information on the current best practices in uploading your packages
564to PyPI, see the Python Packaging User Guide's "Packaging Python Projects"
565tutorial specifically the section on `uploading the distribution archives
566<https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives>`_.
567