2007-08-15 11:28:01 -03:00
|
|
|
.. _setup-config:
|
|
|
|
|
|
|
|
************************************
|
|
|
|
Writing the Setup Configuration File
|
|
|
|
************************************
|
|
|
|
|
|
|
|
Often, it's not possible to write down everything needed to build a distribution
|
|
|
|
*a priori*: you may need to get some information from the user, or from the
|
|
|
|
user's system, in order to proceed. As long as that information is fairly
|
|
|
|
simple---a list of directories to search for C header files or libraries, for
|
|
|
|
example---then providing a configuration file, :file:`setup.cfg`, for users to
|
|
|
|
edit is a cheap and easy way to solicit it. Configuration files also let you
|
|
|
|
provide default values for any command option, which the installer can then
|
|
|
|
override either on the command-line or by editing the config file.
|
|
|
|
|
|
|
|
The setup configuration file is a useful middle-ground between the setup script
|
|
|
|
---which, ideally, would be opaque to installers [#]_---and the command-line to
|
|
|
|
the setup script, which is outside of your control and entirely up to the
|
|
|
|
installer. In fact, :file:`setup.cfg` (and any other Distutils configuration
|
|
|
|
files present on the target system) are processed after the contents of the
|
|
|
|
setup script, but before the command-line. This has several useful
|
|
|
|
consequences:
|
|
|
|
|
|
|
|
.. % (If you have more advanced needs, such as determining which extensions
|
|
|
|
.. % to build based on what capabilities are present on the target system,
|
|
|
|
.. % then you need the Distutils ``auto-configuration'' facility. This
|
|
|
|
.. % started to appear in Distutils 0.9 but, as of this writing, isn't mature
|
|
|
|
.. % or stable enough yet for real-world use.)
|
|
|
|
|
|
|
|
* installers can override some of what you put in :file:`setup.py` by editing
|
|
|
|
:file:`setup.cfg`
|
|
|
|
|
|
|
|
* you can provide non-standard defaults for options that are not easily set in
|
|
|
|
:file:`setup.py`
|
|
|
|
|
|
|
|
* installers can override anything in :file:`setup.cfg` using the command-line
|
|
|
|
options to :file:`setup.py`
|
|
|
|
|
|
|
|
The basic syntax of the configuration file is simple::
|
|
|
|
|
|
|
|
[command]
|
|
|
|
option=value
|
|
|
|
...
|
|
|
|
|
|
|
|
where *command* is one of the Distutils commands (e.g. :command:`build_py`,
|
|
|
|
:command:`install`), and *option* is one of the options that command supports.
|
|
|
|
Any number of options can be supplied for each command, and any number of
|
|
|
|
command sections can be included in the file. Blank lines are ignored, as are
|
|
|
|
comments, which run from a ``'#'`` character until the end of the line. Long
|
|
|
|
option values can be split across multiple lines simply by indenting the
|
|
|
|
continuation lines.
|
|
|
|
|
|
|
|
You can find out the list of options supported by a particular command with the
|
|
|
|
universal :option:`--help` option, e.g. ::
|
|
|
|
|
|
|
|
> python setup.py --help build_ext
|
|
|
|
[...]
|
|
|
|
Options for 'build_ext' command:
|
|
|
|
--build-lib (-b) directory for compiled extension modules
|
|
|
|
--build-temp (-t) directory for temporary files (build by-products)
|
|
|
|
--inplace (-i) ignore build-lib and put compiled extensions into the
|
|
|
|
source directory alongside your pure Python modules
|
|
|
|
--include-dirs (-I) list of directories to search for header files
|
|
|
|
--define (-D) C preprocessor macros to define
|
|
|
|
--undef (-U) C preprocessor macros to undefine
|
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68133 | antoine.pitrou | 2009-01-01 16:38:03 +0100 (Thu, 01 Jan 2009) | 1 line
fill in actual issue number in tests
........
r68134 | hirokazu.yamamoto | 2009-01-01 16:45:39 +0100 (Thu, 01 Jan 2009) | 2 lines
Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
file with `str' filename on Windows.
........
r68141 | benjamin.peterson | 2009-01-01 17:43:12 +0100 (Thu, 01 Jan 2009) | 1 line
fix highlighting
........
r68142 | benjamin.peterson | 2009-01-01 18:29:49 +0100 (Thu, 01 Jan 2009) | 2 lines
welcome to 2009, Python!
........
r68145 | amaury.forgeotdarc | 2009-01-02 01:03:54 +0100 (Fri, 02 Jan 2009) | 5 lines
#4801 _collections module fails to build on cygwin.
_PyObject_GC_TRACK is the macro version of PyObject_GC_Track,
and according to documentation it should not be used for extension modules.
........
r68146 | ronald.oussoren | 2009-01-02 11:44:46 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4472: "configure --enable-shared doesn't work on OSX"
........
r68148 | ronald.oussoren | 2009-01-02 11:48:31 +0100 (Fri, 02 Jan 2009) | 2 lines
Forgot to add a NEWS item in my previous checkin
........
r68149 | ronald.oussoren | 2009-01-02 11:50:48 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4780
........
r68159 | ronald.oussoren | 2009-01-02 15:48:17 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue 1627952
........
r68160 | ronald.oussoren | 2009-01-02 15:52:09 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue r1737832
........
r68161 | ronald.oussoren | 2009-01-02 16:00:05 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 1149804
........
r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 4472 is incompatible with Cygwin, this patch
should fix that.
........
r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line
document PyMemberDef
........
r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines
#4811: fix markup glitches (mostly remains of the conversion),
found by Gabriel Genellina.
........
r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4075: Use OutputDebugStringW in Py_FatalError.
........
r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4051: Prevent conflict of UNICODE macros in cPickle.
........
r68174 | benjamin.peterson | 2009-01-02 21:47:27 +0100 (Fri, 02 Jan 2009) | 1 line
fix compilation on non-Windows platforms
........
r68179 | raymond.hettinger | 2009-01-02 22:26:45 +0100 (Fri, 02 Jan 2009) | 1 line
Issue #4615. Document how to use itertools for de-duping.
........
r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove useless string literal.
........
r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix indentation.
........
r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines
Set eol-style correctly for mp_distributing.py.
........
r68214 | georg.brandl | 2009-01-03 20:44:48 +0100 (Sat, 03 Jan 2009) | 2 lines
Make indentation consistent.
........
r68215 | georg.brandl | 2009-01-03 21:15:14 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix role name.
........
r68217 | georg.brandl | 2009-01-03 21:30:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Add rstlint, a little tool to find subtle markup problems and inconsistencies in the Doc sources.
........
r68218 | georg.brandl | 2009-01-03 21:38:59 +0100 (Sat, 03 Jan 2009) | 2 lines
Recognize usage of the default role.
........
r68219 | georg.brandl | 2009-01-03 21:47:01 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix uses of the default role.
........
r68220 | georg.brandl | 2009-01-03 21:55:06 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove trailing whitespace.
........
r68221 | georg.brandl | 2009-01-03 22:04:55 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove tabs from the documentation.
........
r68222 | georg.brandl | 2009-01-03 22:11:58 +0100 (Sat, 03 Jan 2009) | 2 lines
Disable the line length checker by default.
........
2009-01-03 17:55:17 -04:00
|
|
|
--swig-opts list of SWIG command line options
|
2007-08-15 11:28:01 -03:00
|
|
|
[...]
|
|
|
|
|
|
|
|
Note that an option spelled :option:`--foo-bar` on the command-line is spelled
|
|
|
|
:option:`foo_bar` in configuration files.
|
|
|
|
|
|
|
|
For example, say you want your extensions to be built "in-place"---that is, you
|
|
|
|
have an extension :mod:`pkg.ext`, and you want the compiled extension file
|
|
|
|
(:file:`ext.so` on Unix, say) to be put in the same source directory as your
|
|
|
|
pure Python modules :mod:`pkg.mod1` and :mod:`pkg.mod2`. You can always use the
|
|
|
|
:option:`--inplace` option on the command-line to ensure this::
|
|
|
|
|
|
|
|
python setup.py build_ext --inplace
|
|
|
|
|
|
|
|
But this requires that you always specify the :command:`build_ext` command
|
|
|
|
explicitly, and remember to provide :option:`--inplace`. An easier way is to
|
|
|
|
"set and forget" this option, by encoding it in :file:`setup.cfg`, the
|
|
|
|
configuration file for this distribution::
|
|
|
|
|
|
|
|
[build_ext]
|
|
|
|
inplace=1
|
|
|
|
|
|
|
|
This will affect all builds of this module distribution, whether or not you
|
|
|
|
explicitly specify :command:`build_ext`. If you include :file:`setup.cfg` in
|
|
|
|
your source distribution, it will also affect end-user builds---which is
|
|
|
|
probably a bad idea for this option, since always building extensions in-place
|
|
|
|
would break installation of the module distribution. In certain peculiar cases,
|
|
|
|
though, modules are built right in their installation directory, so this is
|
|
|
|
conceivably a useful ability. (Distributing extensions that expect to be built
|
|
|
|
in their installation directory is almost always a bad idea, though.)
|
|
|
|
|
|
|
|
Another example: certain commands take a lot of options that don't change from
|
|
|
|
run to run; for example, :command:`bdist_rpm` needs to know everything required
|
|
|
|
to generate a "spec" file for creating an RPM distribution. Some of this
|
|
|
|
information comes from the setup script, and some is automatically generated by
|
|
|
|
the Distutils (such as the list of files installed). But some of it has to be
|
|
|
|
supplied as options to :command:`bdist_rpm`, which would be very tedious to do
|
|
|
|
on the command-line for every run. Hence, here is a snippet from the Distutils'
|
|
|
|
own :file:`setup.cfg`::
|
|
|
|
|
|
|
|
[bdist_rpm]
|
|
|
|
release = 1
|
|
|
|
packager = Greg Ward <gward@python.net>
|
|
|
|
doc_files = CHANGES.txt
|
|
|
|
README.txt
|
|
|
|
USAGE.txt
|
|
|
|
doc/
|
|
|
|
examples/
|
|
|
|
|
|
|
|
Note that the :option:`doc_files` option is simply a whitespace-separated string
|
|
|
|
split across multiple lines for readability.
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:ref:`inst-config-syntax` in "Installing Python Modules"
|
|
|
|
More information on the configuration files is available in the manual for
|
|
|
|
system administrators.
|
|
|
|
|
|
|
|
|
|
|
|
.. rubric:: Footnotes
|
|
|
|
|
|
|
|
.. [#] This ideal probably won't be achieved until auto-configuration is fully
|
|
|
|
supported by the Distutils.
|
|
|
|
|