/Doc/distutils/setupscript.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 678 lines · 516 code · 162 blank · 0 comment · 0 complexity · 40d912ec7c5973eed4f3a19c02616419 MD5 · raw file

  1. .. _setup-script:
  2. ************************
  3. Writing the Setup Script
  4. ************************
  5. The setup script is the centre of all activity in building, distributing, and
  6. installing modules using the Distutils. The main purpose of the setup script is
  7. to describe your module distribution to the Distutils, so that the various
  8. commands that operate on your modules do the right thing. As we saw in section
  9. :ref:`distutils-simple-example` above, the setup script consists mainly of a call to
  10. :func:`setup`, and most information supplied to the Distutils by the module
  11. developer is supplied as keyword arguments to :func:`setup`.
  12. Here's a slightly more involved example, which we'll follow for the next couple
  13. of sections: the Distutils' own setup script. (Keep in mind that although the
  14. Distutils are included with Python 1.6 and later, they also have an independent
  15. existence so that Python 1.5.2 users can use them to install other module
  16. distributions. The Distutils' own setup script, shown here, is used to install
  17. the package into Python 1.5.2.) ::
  18. #!/usr/bin/env python
  19. from distutils.core import setup
  20. setup(name='Distutils',
  21. version='1.0',
  22. description='Python Distribution Utilities',
  23. author='Greg Ward',
  24. author_email='gward@python.net',
  25. url='http://www.python.org/sigs/distutils-sig/',
  26. packages=['distutils', 'distutils.command'],
  27. )
  28. There are only two differences between this and the trivial one-file
  29. distribution presented in section :ref:`distutils-simple-example`: more metadata, and the
  30. specification of pure Python modules by package, rather than by module. This is
  31. important since the Distutils consist of a couple of dozen modules split into
  32. (so far) two packages; an explicit list of every module would be tedious to
  33. generate and difficult to maintain. For more information on the additional
  34. meta-data, see section :ref:`meta-data`.
  35. Note that any pathnames (files or directories) supplied in the setup script
  36. should be written using the Unix convention, i.e. slash-separated. The
  37. Distutils will take care of converting this platform-neutral representation into
  38. whatever is appropriate on your current platform before actually using the
  39. pathname. This makes your setup script portable across operating systems, which
  40. of course is one of the major goals of the Distutils. In this spirit, all
  41. pathnames in this document are slash-separated.
  42. This, of course, only applies to pathnames given to Distutils functions. If
  43. you, for example, use standard Python functions such as :func:`glob.glob` or
  44. :func:`os.listdir` to specify files, you should be careful to write portable
  45. code instead of hardcoding path separators::
  46. glob.glob(os.path.join('mydir', 'subdir', '*.html'))
  47. os.listdir(os.path.join('mydir', 'subdir'))
  48. .. _listing-packages:
  49. Listing whole packages
  50. ======================
  51. The :option:`packages` option tells the Distutils to process (build, distribute,
  52. install, etc.) all pure Python modules found in each package mentioned in the
  53. :option:`packages` list. In order to do this, of course, there has to be a
  54. correspondence between package names and directories in the filesystem. The
  55. default correspondence is the most obvious one, i.e. package :mod:`distutils` is
  56. found in the directory :file:`distutils` relative to the distribution root.
  57. Thus, when you say ``packages = ['foo']`` in your setup script, you are
  58. promising that the Distutils will find a file :file:`foo/__init__.py` (which
  59. might be spelled differently on your system, but you get the idea) relative to
  60. the directory where your setup script lives. If you break this promise, the
  61. Distutils will issue a warning but still process the broken package anyways.
  62. If you use a different convention to lay out your source directory, that's no
  63. problem: you just have to supply the :option:`package_dir` option to tell the
  64. Distutils about your convention. For example, say you keep all Python source
  65. under :file:`lib`, so that modules in the "root package" (i.e., not in any
  66. package at all) are in :file:`lib`, modules in the :mod:`foo` package are in
  67. :file:`lib/foo`, and so forth. Then you would put ::
  68. package_dir = {'': 'lib'}
  69. in your setup script. The keys to this dictionary are package names, and an
  70. empty package name stands for the root package. The values are directory names
  71. relative to your distribution root. In this case, when you say ``packages =
  72. ['foo']``, you are promising that the file :file:`lib/foo/__init__.py` exists.
  73. Another possible convention is to put the :mod:`foo` package right in
  74. :file:`lib`, the :mod:`foo.bar` package in :file:`lib/bar`, etc. This would be
  75. written in the setup script as ::
  76. package_dir = {'foo': 'lib'}
  77. A ``package: dir`` entry in the :option:`package_dir` dictionary implicitly
  78. applies to all packages below *package*, so the :mod:`foo.bar` case is
  79. automatically handled here. In this example, having ``packages = ['foo',
  80. 'foo.bar']`` tells the Distutils to look for :file:`lib/__init__.py` and
  81. :file:`lib/bar/__init__.py`. (Keep in mind that although :option:`package_dir`
  82. applies recursively, you must explicitly list all packages in
  83. :option:`packages`: the Distutils will *not* recursively scan your source tree
  84. looking for any directory with an :file:`__init__.py` file.)
  85. .. _listing-modules:
  86. Listing individual modules
  87. ==========================
  88. For a small module distribution, you might prefer to list all modules rather
  89. than listing packages---especially the case of a single module that goes in the
  90. "root package" (i.e., no package at all). This simplest case was shown in
  91. section :ref:`distutils-simple-example`; here is a slightly more involved example::
  92. py_modules = ['mod1', 'pkg.mod2']
  93. This describes two modules, one of them in the "root" package, the other in the
  94. :mod:`pkg` package. Again, the default package/directory layout implies that
  95. these two modules can be found in :file:`mod1.py` and :file:`pkg/mod2.py`, and
  96. that :file:`pkg/__init__.py` exists as well. And again, you can override the
  97. package/directory correspondence using the :option:`package_dir` option.
  98. .. _describing-extensions:
  99. Describing extension modules
  100. ============================
  101. Just as writing Python extension modules is a bit more complicated than writing
  102. pure Python modules, describing them to the Distutils is a bit more complicated.
  103. Unlike pure modules, it's not enough just to list modules or packages and expect
  104. the Distutils to go out and find the right files; you have to specify the
  105. extension name, source file(s), and any compile/link requirements (include
  106. directories, libraries to link with, etc.).
  107. .. XXX read over this section
  108. All of this is done through another keyword argument to :func:`setup`, the
  109. :option:`ext_modules` option. :option:`ext_modules` is just a list of
  110. :class:`Extension` instances, each of which describes a single extension module.
  111. Suppose your distribution includes a single extension, called :mod:`foo` and
  112. implemented by :file:`foo.c`. If no additional instructions to the
  113. compiler/linker are needed, describing this extension is quite simple::
  114. Extension('foo', ['foo.c'])
  115. The :class:`Extension` class can be imported from :mod:`distutils.core` along
  116. with :func:`setup`. Thus, the setup script for a module distribution that
  117. contains only this one extension and nothing else might be::
  118. from distutils.core import setup, Extension
  119. setup(name='foo',
  120. version='1.0',
  121. ext_modules=[Extension('foo', ['foo.c'])],
  122. )
  123. The :class:`Extension` class (actually, the underlying extension-building
  124. machinery implemented by the :command:`build_ext` command) supports a great deal
  125. of flexibility in describing Python extensions, which is explained in the
  126. following sections.
  127. Extension names and packages
  128. ----------------------------
  129. The first argument to the :class:`Extension` constructor is always the name of
  130. the extension, including any package names. For example, ::
  131. Extension('foo', ['src/foo1.c', 'src/foo2.c'])
  132. describes an extension that lives in the root package, while ::
  133. Extension('pkg.foo', ['src/foo1.c', 'src/foo2.c'])
  134. describes the same extension in the :mod:`pkg` package. The source files and
  135. resulting object code are identical in both cases; the only difference is where
  136. in the filesystem (and therefore where in Python's namespace hierarchy) the
  137. resulting extension lives.
  138. If you have a number of extensions all in the same package (or all under the
  139. same base package), use the :option:`ext_package` keyword argument to
  140. :func:`setup`. For example, ::
  141. setup(...,
  142. ext_package='pkg',
  143. ext_modules=[Extension('foo', ['foo.c']),
  144. Extension('subpkg.bar', ['bar.c'])],
  145. )
  146. will compile :file:`foo.c` to the extension :mod:`pkg.foo`, and :file:`bar.c` to
  147. :mod:`pkg.subpkg.bar`.
  148. Extension source files
  149. ----------------------
  150. The second argument to the :class:`Extension` constructor is a list of source
  151. files. Since the Distutils currently only support C, C++, and Objective-C
  152. extensions, these are normally C/C++/Objective-C source files. (Be sure to use
  153. appropriate extensions to distinguish C++\ source files: :file:`.cc` and
  154. :file:`.cpp` seem to be recognized by both Unix and Windows compilers.)
  155. However, you can also include SWIG interface (:file:`.i`) files in the list; the
  156. :command:`build_ext` command knows how to deal with SWIG extensions: it will run
  157. SWIG on the interface file and compile the resulting C/C++ file into your
  158. extension.
  159. **\*\*** SWIG support is rough around the edges and largely untested! **\*\***
  160. This warning notwithstanding, options to SWIG can be currently passed like
  161. this::
  162. setup(...,
  163. ext_modules=[Extension('_foo', ['foo.i'],
  164. swig_opts=['-modern', '-I../include'])],
  165. py_modules=['foo'],
  166. )
  167. Or on the commandline like this::
  168. > python setup.py build_ext --swig-opts="-modern -I../include"
  169. On some platforms, you can include non-source files that are processed by the
  170. compiler and included in your extension. Currently, this just means Windows
  171. message text (:file:`.mc`) files and resource definition (:file:`.rc`) files for
  172. Visual C++. These will be compiled to binary resource (:file:`.res`) files and
  173. linked into the executable.
  174. Preprocessor options
  175. --------------------
  176. Three optional arguments to :class:`Extension` will help if you need to specify
  177. include directories to search or preprocessor macros to define/undefine:
  178. ``include_dirs``, ``define_macros``, and ``undef_macros``.
  179. For example, if your extension requires header files in the :file:`include`
  180. directory under your distribution root, use the ``include_dirs`` option::
  181. Extension('foo', ['foo.c'], include_dirs=['include'])
  182. You can specify absolute directories there; if you know that your extension will
  183. only be built on Unix systems with X11R6 installed to :file:`/usr`, you can get
  184. away with ::
  185. Extension('foo', ['foo.c'], include_dirs=['/usr/include/X11'])
  186. You should avoid this sort of non-portable usage if you plan to distribute your
  187. code: it's probably better to write C code like ::
  188. #include <X11/Xlib.h>
  189. If you need to include header files from some other Python extension, you can
  190. take advantage of the fact that header files are installed in a consistent way
  191. by the Distutils :command:`install_header` command. For example, the Numerical
  192. Python header files are installed (on a standard Unix installation) to
  193. :file:`/usr/local/include/python1.5/Numerical`. (The exact location will differ
  194. according to your platform and Python installation.) Since the Python include
  195. directory---\ :file:`/usr/local/include/python1.5` in this case---is always
  196. included in the search path when building Python extensions, the best approach
  197. is to write C code like ::
  198. #include <Numerical/arrayobject.h>
  199. If you must put the :file:`Numerical` include directory right into your header
  200. search path, though, you can find that directory using the Distutils
  201. :mod:`distutils.sysconfig` module::
  202. from distutils.sysconfig import get_python_inc
  203. incdir = os.path.join(get_python_inc(plat_specific=1), 'Numerical')
  204. setup(...,
  205. Extension(..., include_dirs=[incdir]),
  206. )
  207. Even though this is quite portable---it will work on any Python installation,
  208. regardless of platform---it's probably easier to just write your C code in the
  209. sensible way.
  210. You can define and undefine pre-processor macros with the ``define_macros`` and
  211. ``undef_macros`` options. ``define_macros`` takes a list of ``(name, value)``
  212. tuples, where ``name`` is the name of the macro to define (a string) and
  213. ``value`` is its value: either a string or ``None``. (Defining a macro ``FOO``
  214. to ``None`` is the equivalent of a bare ``#define FOO`` in your C source: with
  215. most compilers, this sets ``FOO`` to the string ``1``.) ``undef_macros`` is
  216. just a list of macros to undefine.
  217. For example::
  218. Extension(...,
  219. define_macros=[('NDEBUG', '1'),
  220. ('HAVE_STRFTIME', None)],
  221. undef_macros=['HAVE_FOO', 'HAVE_BAR'])
  222. is the equivalent of having this at the top of every C source file::
  223. #define NDEBUG 1
  224. #define HAVE_STRFTIME
  225. #undef HAVE_FOO
  226. #undef HAVE_BAR
  227. Library options
  228. ---------------
  229. You can also specify the libraries to link against when building your extension,
  230. and the directories to search for those libraries. The ``libraries`` option is
  231. a list of libraries to link against, ``library_dirs`` is a list of directories
  232. to search for libraries at link-time, and ``runtime_library_dirs`` is a list of
  233. directories to search for shared (dynamically loaded) libraries at run-time.
  234. For example, if you need to link against libraries known to be in the standard
  235. library search path on target systems ::
  236. Extension(...,
  237. libraries=['gdbm', 'readline'])
  238. If you need to link with libraries in a non-standard location, you'll have to
  239. include the location in ``library_dirs``::
  240. Extension(...,
  241. library_dirs=['/usr/X11R6/lib'],
  242. libraries=['X11', 'Xt'])
  243. (Again, this sort of non-portable construct should be avoided if you intend to
  244. distribute your code.)
  245. **\*\*** Should mention clib libraries here or somewhere else! **\*\***
  246. Other options
  247. -------------
  248. There are still some other options which can be used to handle special cases.
  249. The :option:`extra_objects` option is a list of object files to be passed to the
  250. linker. These files must not have extensions, as the default extension for the
  251. compiler is used.
  252. :option:`extra_compile_args` and :option:`extra_link_args` can be used to
  253. specify additional command line options for the respective compiler and linker
  254. command lines.
  255. :option:`export_symbols` is only useful on Windows. It can contain a list of
  256. symbols (functions or variables) to be exported. This option is not needed when
  257. building compiled extensions: Distutils will automatically add ``initmodule``
  258. to the list of exported symbols.
  259. Relationships between Distributions and Packages
  260. ================================================
  261. A distribution may relate to packages in three specific ways:
  262. #. It can require packages or modules.
  263. #. It can provide packages or modules.
  264. #. It can obsolete packages or modules.
  265. These relationships can be specified using keyword arguments to the
  266. :func:`distutils.core.setup` function.
  267. Dependencies on other Python modules and packages can be specified by supplying
  268. the *requires* keyword argument to :func:`setup`. The value must be a list of
  269. strings. Each string specifies a package that is required, and optionally what
  270. versions are sufficient.
  271. To specify that any version of a module or package is required, the string
  272. should consist entirely of the module or package name. Examples include
  273. ``'mymodule'`` and ``'xml.parsers.expat'``.
  274. If specific versions are required, a sequence of qualifiers can be supplied in
  275. parentheses. Each qualifier may consist of a comparison operator and a version
  276. number. The accepted comparison operators are::
  277. < > ==
  278. <= >= !=
  279. These can be combined by using multiple qualifiers separated by commas (and
  280. optional whitespace). In this case, all of the qualifiers must be matched; a
  281. logical AND is used to combine the evaluations.
  282. Let's look at a bunch of examples:
  283. +-------------------------+----------------------------------------------+
  284. | Requires Expression | Explanation |
  285. +=========================+==============================================+
  286. | ``==1.0`` | Only version ``1.0`` is compatible |
  287. +-------------------------+----------------------------------------------+
  288. | ``>1.0, !=1.5.1, <2.0`` | Any version after ``1.0`` and before ``2.0`` |
  289. | | is compatible, except ``1.5.1`` |
  290. +-------------------------+----------------------------------------------+
  291. Now that we can specify dependencies, we also need to be able to specify what we
  292. provide that other distributions can require. This is done using the *provides*
  293. keyword argument to :func:`setup`. The value for this keyword is a list of
  294. strings, each of which names a Python module or package, and optionally
  295. identifies the version. If the version is not specified, it is assumed to match
  296. that of the distribution.
  297. Some examples:
  298. +---------------------+----------------------------------------------+
  299. | Provides Expression | Explanation |
  300. +=====================+==============================================+
  301. | ``mypkg`` | Provide ``mypkg``, using the distribution |
  302. | | version |
  303. +---------------------+----------------------------------------------+
  304. | ``mypkg (1.1)`` | Provide ``mypkg`` version 1.1, regardless of |
  305. | | the distribution version |
  306. +---------------------+----------------------------------------------+
  307. A package can declare that it obsoletes other packages using the *obsoletes*
  308. keyword argument. The value for this is similar to that of the *requires*
  309. keyword: a list of strings giving module or package specifiers. Each specifier
  310. consists of a module or package name optionally followed by one or more version
  311. qualifiers. Version qualifiers are given in parentheses after the module or
  312. package name.
  313. The versions identified by the qualifiers are those that are obsoleted by the
  314. distribution being described. If no qualifiers are given, all versions of the
  315. named module or package are understood to be obsoleted.
  316. Installing Scripts
  317. ==================
  318. So far we have been dealing with pure and non-pure Python modules, which are
  319. usually not run by themselves but imported by scripts.
  320. Scripts are files containing Python source code, intended to be started from the
  321. command line. Scripts don't require Distutils to do anything very complicated.
  322. The only clever feature is that if the first line of the script starts with
  323. ``#!`` and contains the word "python", the Distutils will adjust the first line
  324. to refer to the current interpreter location. By default, it is replaced with
  325. the current interpreter location. The :option:`--executable` (or :option:`-e`)
  326. option will allow the interpreter path to be explicitly overridden.
  327. The :option:`scripts` option simply is a list of files to be handled in this
  328. way. From the PyXML setup script::
  329. setup(...,
  330. scripts=['scripts/xmlproc_parse', 'scripts/xmlproc_val']
  331. )
  332. Installing Package Data
  333. =======================
  334. Often, additional files need to be installed into a package. These files are
  335. often data that's closely related to the package's implementation, or text files
  336. containing documentation that might be of interest to programmers using the
  337. package. These files are called :dfn:`package data`.
  338. Package data can be added to packages using the ``package_data`` keyword
  339. argument to the :func:`setup` function. The value must be a mapping from
  340. package name to a list of relative path names that should be copied into the
  341. package. The paths are interpreted as relative to the directory containing the
  342. package (information from the ``package_dir`` mapping is used if appropriate);
  343. that is, the files are expected to be part of the package in the source
  344. directories. They may contain glob patterns as well.
  345. The path names may contain directory portions; any necessary directories will be
  346. created in the installation.
  347. For example, if a package should contain a subdirectory with several data files,
  348. the files can be arranged like this in the source tree::
  349. setup.py
  350. src/
  351. mypkg/
  352. __init__.py
  353. module.py
  354. data/
  355. tables.dat
  356. spoons.dat
  357. forks.dat
  358. The corresponding call to :func:`setup` might be::
  359. setup(...,
  360. packages=['mypkg'],
  361. package_dir={'mypkg': 'src/mypkg'},
  362. package_data={'mypkg': ['data/*.dat']},
  363. )
  364. .. versionadded:: 2.4
  365. Installing Additional Files
  366. ===========================
  367. The :option:`data_files` option can be used to specify additional files needed
  368. by the module distribution: configuration files, message catalogs, data files,
  369. anything which doesn't fit in the previous categories.
  370. :option:`data_files` specifies a sequence of (*directory*, *files*) pairs in the
  371. following way::
  372. setup(...,
  373. data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
  374. ('config', ['cfg/data.cfg']),
  375. ('/etc/init.d', ['init-script'])]
  376. )
  377. Note that you can specify the directory names where the data files will be
  378. installed, but you cannot rename the data files themselves.
  379. Each (*directory*, *files*) pair in the sequence specifies the installation
  380. directory and the files to install there. If *directory* is a relative path, it
  381. is interpreted relative to the installation prefix (Python's ``sys.prefix`` for
  382. pure-Python packages, ``sys.exec_prefix`` for packages that contain extension
  383. modules). Each file name in *files* is interpreted relative to the
  384. :file:`setup.py` script at the top of the package source distribution. No
  385. directory information from *files* is used to determine the final location of
  386. the installed file; only the name of the file is used.
  387. You can specify the :option:`data_files` options as a simple sequence of files
  388. without specifying a target directory, but this is not recommended, and the
  389. :command:`install` command will print a warning in this case. To install data
  390. files directly in the target directory, an empty string should be given as the
  391. directory.
  392. .. _meta-data:
  393. Additional meta-data
  394. ====================
  395. The setup script may include additional meta-data beyond the name and version.
  396. This information includes:
  397. +----------------------+---------------------------+-----------------+--------+
  398. | Meta-Data | Description | Value | Notes |
  399. +======================+===========================+=================+========+
  400. | ``name`` | name of the package | short string | \(1) |
  401. +----------------------+---------------------------+-----------------+--------+
  402. | ``version`` | version of this release | short string | (1)(2) |
  403. +----------------------+---------------------------+-----------------+--------+
  404. | ``author`` | package author's name | short string | \(3) |
  405. +----------------------+---------------------------+-----------------+--------+
  406. | ``author_email`` | email address of the | email address | \(3) |
  407. | | package author | | |
  408. +----------------------+---------------------------+-----------------+--------+
  409. | ``maintainer`` | package maintainer's name | short string | \(3) |
  410. +----------------------+---------------------------+-----------------+--------+
  411. | ``maintainer_email`` | email address of the | email address | \(3) |
  412. | | package maintainer | | |
  413. +----------------------+---------------------------+-----------------+--------+
  414. | ``url`` | home page for the package | URL | \(1) |
  415. +----------------------+---------------------------+-----------------+--------+
  416. | ``description`` | short, summary | short string | |
  417. | | description of the | | |
  418. | | package | | |
  419. +----------------------+---------------------------+-----------------+--------+
  420. | ``long_description`` | longer description of the | long string | |
  421. | | package | | |
  422. +----------------------+---------------------------+-----------------+--------+
  423. | ``download_url`` | location where the | URL | \(4) |
  424. | | package may be downloaded | | |
  425. +----------------------+---------------------------+-----------------+--------+
  426. | ``classifiers`` | a list of classifiers | list of strings | \(4) |
  427. +----------------------+---------------------------+-----------------+--------+
  428. | ``platforms`` | a list of platforms | list of strings | |
  429. +----------------------+---------------------------+-----------------+--------+
  430. | ``license`` | license for the package | short string | \(6) |
  431. +----------------------+---------------------------+-----------------+--------+
  432. Notes:
  433. (1)
  434. These fields are required.
  435. (2)
  436. It is recommended that versions take the form *major.minor[.patch[.sub]]*.
  437. (3)
  438. Either the author or the maintainer must be identified.
  439. (4)
  440. These fields should not be used if your package is to be compatible with Python
  441. versions prior to 2.2.3 or 2.3. The list is available from the `PyPI website
  442. <http://pypi.python.org/pypi>`_.
  443. (6)
  444. The ``license`` field is a text indicating the license covering the
  445. package where the license is not a selection from the "License" Trove
  446. classifiers. See the ``Classifier`` field. Notice that
  447. there's a ``licence`` distribution option which is deprecated but still
  448. acts as an alias for ``license``.
  449. 'short string'
  450. A single line of text, not more than 200 characters.
  451. 'long string'
  452. Multiple lines of plain text in reStructuredText format (see
  453. http://docutils.sf.net/).
  454. 'list of strings'
  455. See below.
  456. None of the string values may be Unicode.
  457. Encoding the version information is an art in itself. Python packages generally
  458. adhere to the version format *major.minor[.patch][sub]*. The major number is 0
  459. for initial, experimental releases of software. It is incremented for releases
  460. that represent major milestones in a package. The minor number is incremented
  461. when important new features are added to the package. The patch number
  462. increments when bug-fix releases are made. Additional trailing version
  463. information is sometimes used to indicate sub-releases. These are
  464. "a1,a2,...,aN" (for alpha releases, where functionality and API may change),
  465. "b1,b2,...,bN" (for beta releases, which only fix bugs) and "pr1,pr2,...,prN"
  466. (for final pre-release release testing). Some examples:
  467. 0.1.0
  468. the first, experimental release of a package
  469. 1.0.1a2
  470. the second alpha release of the first patch version of 1.0
  471. :option:`classifiers` are specified in a python list::
  472. setup(...,
  473. classifiers=[
  474. 'Development Status :: 4 - Beta',
  475. 'Environment :: Console',
  476. 'Environment :: Web Environment',
  477. 'Intended Audience :: End Users/Desktop',
  478. 'Intended Audience :: Developers',
  479. 'Intended Audience :: System Administrators',
  480. 'License :: OSI Approved :: Python Software Foundation License',
  481. 'Operating System :: MacOS :: MacOS X',
  482. 'Operating System :: Microsoft :: Windows',
  483. 'Operating System :: POSIX',
  484. 'Programming Language :: Python',
  485. 'Topic :: Communications :: Email',
  486. 'Topic :: Office/Business',
  487. 'Topic :: Software Development :: Bug Tracking',
  488. ],
  489. )
  490. If you wish to include classifiers in your :file:`setup.py` file and also wish
  491. to remain backwards-compatible with Python releases prior to 2.2.3, then you can
  492. include the following code fragment in your :file:`setup.py` before the
  493. :func:`setup` call. ::
  494. # patch distutils if it can't cope with the "classifiers" or
  495. # "download_url" keywords
  496. from sys import version
  497. if version < '2.2.3':
  498. from distutils.dist import DistributionMetadata
  499. DistributionMetadata.classifiers = None
  500. DistributionMetadata.download_url = None
  501. Debugging the setup script
  502. ==========================
  503. Sometimes things go wrong, and the setup script doesn't do what the developer
  504. wants.
  505. Distutils catches any exceptions when running the setup script, and print a
  506. simple error message before the script is terminated. The motivation for this
  507. behaviour is to not confuse administrators who don't know much about Python and
  508. are trying to install a package. If they get a big long traceback from deep
  509. inside the guts of Distutils, they may think the package or the Python
  510. installation is broken because they don't read all the way down to the bottom
  511. and see that it's a permission problem.
  512. On the other hand, this doesn't help the developer to find the cause of the
  513. failure. For this purpose, the DISTUTILS_DEBUG environment variable can be set
  514. to anything except an empty string, and distutils will now print detailed
  515. information what it is doing, and prints the full traceback in case an exception
  516. occurs.