Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/distutils/setupscript.rst

    r2 r391  
    2020the package into Python 1.5.2.) ::
    2121
    22    #!/usr/bin/env python
    23 
    24    from distutils.core import setup
    25 
    26    setup(name='Distutils',
    27          version='1.0',
    28          description='Python Distribution Utilities',
    29          author='Greg Ward',
    30          author_email='gward@python.net',
    31          url='http://www.python.org/sigs/distutils-sig/',
    32          packages=['distutils', 'distutils.command'],
    33         )
     22    #!/usr/bin/env python
     23
     24    from distutils.core import setup
     25
     26    setup(name='Distutils',
     27          version='1.0',
     28          description='Python Distribution Utilities',
     29          author='Greg Ward',
     30          author_email='gward@python.net',
     31          url='http://www.python.org/sigs/distutils-sig/',
     32          packages=['distutils', 'distutils.command'],
     33         )
    3434
    3535There are only two differences between this and the trivial one-file
     
    5454code instead of hardcoding path separators::
    5555
    56    glob.glob(os.path.join('mydir', 'subdir', '*.html'))
    57    os.listdir(os.path.join('mydir', 'subdir'))
     56    glob.glob(os.path.join('mydir', 'subdir', '*.html'))
     57    os.listdir(os.path.join('mydir', 'subdir'))
    5858
    5959
     
    7373might be spelled differently on your system, but you get the idea) relative to
    7474the directory where your setup script lives.  If you break this promise, the
    75 Distutils will issue a warning but still process the broken package anyways.
     75Distutils will issue a warning but still process the broken package anyway.
    7676
    7777If you use a different convention to lay out your source directory, that's no
     
    8282:file:`lib/foo`, and so forth.  Then you would put ::
    8383
    84    package_dir = {'': 'lib'}
     84    package_dir = {'': 'lib'}
    8585
    8686in your setup script.  The keys to this dictionary are package names, and an
     
    9393written in the setup script as ::
    9494
    95    package_dir = {'foo': 'lib'}
     95    package_dir = {'foo': 'lib'}
    9696
    9797A ``package: dir`` entry in the :option:`package_dir` dictionary implicitly
     
    115115section :ref:`distutils-simple-example`; here is a slightly more involved example::
    116116
    117    py_modules = ['mod1', 'pkg.mod2']
     117    py_modules = ['mod1', 'pkg.mod2']
    118118
    119119This describes two modules, one of them in the "root" package, the other in the
     
    140140All of this is done through another keyword argument to :func:`setup`, the
    141141:option:`ext_modules` option.  :option:`ext_modules` is just a list of
    142 :class:`Extension` instances, each of which describes a single extension module.
     142:class:`~distutils.core.Extension` instances, each of which describes a
     143single extension module.
    143144Suppose your distribution includes a single extension, called :mod:`foo` and
    144145implemented by :file:`foo.c`.  If no additional instructions to the
    145146compiler/linker are needed, describing this extension is quite simple::
    146147
    147    Extension('foo', ['foo.c'])
     148    Extension('foo', ['foo.c'])
    148149
    149150The :class:`Extension` class can be imported from :mod:`distutils.core` along
     
    151152contains only this one extension and nothing else might be::
    152153
    153    from distutils.core import setup, Extension
    154    setup(name='foo',
    155          version='1.0',
    156          ext_modules=[Extension('foo', ['foo.c'])],
    157          )
     154    from distutils.core import setup, Extension
     155    setup(name='foo',
     156          version='1.0',
     157          ext_modules=[Extension('foo', ['foo.c'])],
     158          )
    158159
    159160The :class:`Extension` class (actually, the underlying extension-building
     
    166167----------------------------
    167168
    168 The first argument to the :class:`Extension` constructor is always the name of
    169 the extension, including any package names.  For example, ::
    170 
    171    Extension('foo', ['src/foo1.c', 'src/foo2.c'])
     169The first argument to the :class:`~distutils.core.Extension` constructor is
     170always the name of the extension, including any package names.  For example, ::
     171
     172    Extension('foo', ['src/foo1.c', 'src/foo2.c'])
    172173
    173174describes an extension that lives in the root package, while ::
    174175
    175    Extension('pkg.foo', ['src/foo1.c', 'src/foo2.c'])
     176    Extension('pkg.foo', ['src/foo1.c', 'src/foo2.c'])
    176177
    177178describes the same extension in the :mod:`pkg` package.  The source files and
     
    184185:func:`setup`.  For example, ::
    185186
    186    setup(...,
    187          ext_package='pkg',
    188          ext_modules=[Extension('foo', ['foo.c']),
    189                       Extension('subpkg.bar', ['bar.c'])],
    190         )
     187    setup(...,
     188          ext_package='pkg',
     189          ext_modules=[Extension('foo', ['foo.c']),
     190                       Extension('subpkg.bar', ['bar.c'])],
     191         )
    191192
    192193will compile :file:`foo.c` to the extension :mod:`pkg.foo`, and :file:`bar.c` to
     
    197198----------------------
    198199
    199 The second argument to the :class:`Extension` constructor is a list of source
     200The second argument to the :class:`~distutils.core.Extension` constructor is
     201a list of source
    200202files.  Since the Distutils currently only support C, C++, and Objective-C
    201203extensions, these are normally C/C++/Objective-C source files.  (Be sure to use
     
    208210extension.
    209211
    210 **\*\*** SWIG support is rough around the edges and largely untested! **\*\***
     212.. XXX SWIG support is rough around the edges and largely untested!
    211213
    212214This warning notwithstanding, options to SWIG can be currently passed like
    213215this::
    214216
    215    setup(...,
    216          ext_modules=[Extension('_foo', ['foo.i'],
    217                                 swig_opts=['-modern', '-I../include'])],
    218          py_modules=['foo'],
    219         )
     217    setup(...,
     218          ext_modules=[Extension('_foo', ['foo.i'],
     219                                 swig_opts=['-modern', '-I../include'])],
     220          py_modules=['foo'],
     221         )
    220222
    221223Or on the commandline like this::
    222224
    223    > python setup.py build_ext --swig-opts="-modern -I../include"
     225    > python setup.py build_ext --swig-opts="-modern -I../include"
    224226
    225227On some platforms, you can include non-source files that are processed by the
     
    233235--------------------
    234236
    235 Three optional arguments to :class:`Extension` will help if you need to specify
    236 include directories to search or preprocessor macros to define/undefine:
    237 ``include_dirs``, ``define_macros``, and ``undef_macros``.
     237Three optional arguments to :class:`~distutils.core.Extension` will help if
     238you need to specify include directories to search or preprocessor macros to
     239define/undefine: ``include_dirs``, ``define_macros``, and ``undef_macros``.
    238240
    239241For example, if your extension requires header files in the :file:`include`
    240242directory under your distribution root, use the ``include_dirs`` option::
    241243
    242    Extension('foo', ['foo.c'], include_dirs=['include'])
     244    Extension('foo', ['foo.c'], include_dirs=['include'])
    243245
    244246You can specify absolute directories there; if you know that your extension will
     
    246248away with ::
    247249
    248    Extension('foo', ['foo.c'], include_dirs=['/usr/include/X11'])
     250    Extension('foo', ['foo.c'], include_dirs=['/usr/include/X11'])
    249251
    250252You should avoid this sort of non-portable usage if you plan to distribute your
    251253code: it's probably better to write C code like  ::
    252254
    253    #include <X11/Xlib.h>
     255    #include <X11/Xlib.h>
    254256
    255257If you need to include header files from some other Python extension, you can
    256258take advantage of the fact that header files are installed in a consistent way
    257 by the Distutils :command:`install_header` command.  For example, the Numerical
     259by the Distutils :command:`install_headers` command.  For example, the Numerical
    258260Python header files are installed (on a standard Unix installation) to
    259261:file:`/usr/local/include/python1.5/Numerical`. (The exact location will differ
     
    263265is to write C code like  ::
    264266
    265    #include <Numerical/arrayobject.h>
     267    #include <Numerical/arrayobject.h>
    266268
    267269If you must put the :file:`Numerical` include directory right into your header
     
    269271:mod:`distutils.sysconfig` module::
    270272
    271    from distutils.sysconfig import get_python_inc
    272    incdir = os.path.join(get_python_inc(plat_specific=1), 'Numerical')
    273    setup(...,
    274          Extension(..., include_dirs=[incdir]),
    275          )
     273    from distutils.sysconfig import get_python_inc
     274    incdir = os.path.join(get_python_inc(plat_specific=1), 'Numerical')
     275    setup(...,
     276          Extension(..., include_dirs=[incdir]),
     277          )
    276278
    277279Even though this is quite portable---it will work on any Python installation,
     
    289291For example::
    290292
    291    Extension(...,
    292              define_macros=[('NDEBUG', '1'),
    293                             ('HAVE_STRFTIME', None)],
    294              undef_macros=['HAVE_FOO', 'HAVE_BAR'])
     293    Extension(...,
     294              define_macros=[('NDEBUG', '1'),
     295                             ('HAVE_STRFTIME', None)],
     296              undef_macros=['HAVE_FOO', 'HAVE_BAR'])
    295297
    296298is the equivalent of having this at the top of every C source file::
    297299
    298    #define NDEBUG 1
    299    #define HAVE_STRFTIME
    300    #undef HAVE_FOO
    301    #undef HAVE_BAR
     300    #define NDEBUG 1
     301    #define HAVE_STRFTIME
     302    #undef HAVE_FOO
     303    #undef HAVE_BAR
    302304
    303305
     
    314316library search path on target systems ::
    315317
    316    Extension(...,
    317              libraries=['gdbm', 'readline'])
     318    Extension(...,
     319              libraries=['gdbm', 'readline'])
    318320
    319321If you need to link with libraries in a non-standard location, you'll have to
    320322include the location in ``library_dirs``::
    321323
    322    Extension(...,
    323              library_dirs=['/usr/X11R6/lib'],
    324              libraries=['X11', 'Xt'])
     324    Extension(...,
     325              library_dirs=['/usr/X11R6/lib'],
     326              libraries=['X11', 'Xt'])
    325327
    326328(Again, this sort of non-portable construct should be avoided if you intend to
    327329distribute your code.)
    328330
    329 **\*\*** Should mention clib libraries here or somewhere else! **\*\***
     331.. XXX Should mention clib libraries here or somewhere else!
    330332
    331333
     
    348350to the list of exported symbols.
    349351
     352The :option:`depends` option is a list of files that the extension depends on
     353(for example header files). The build command will call the compiler on the
     354sources to rebuild extension if any on this files has been modified since the
     355previous build.
    350356
    351357Relationships between Distributions and Packages
     
    376382number.  The accepted comparison operators are::
    377383
    378    <    >    ==
    379    <=   >=   !=
     384    <    >    ==
     385    <=   >=   !=
    380386
    381387These can be combined by using multiple qualifiers separated by commas (and
     
    424430named module or package are understood to be obsoleted.
    425431
     432.. _distutils-installing-scripts:
    426433
    427434Installing Scripts
     
    442449way.  From the PyXML setup script::
    443450
    444    setup(...,
    445          scripts=['scripts/xmlproc_parse', 'scripts/xmlproc_val']
    446          )
    447 
     451    setup(...,
     452          scripts=['scripts/xmlproc_parse', 'scripts/xmlproc_val']
     453          )
     454
     455.. versionchanged:: 2.7
     456    All the scripts will also be added to the ``MANIFEST``
     457    file if no template is provided. See :ref:`manifest`.
     458
     459.. _distutils-installing-package-data:
    448460
    449461Installing Package Data
     
    469481the files can be arranged like this in the source tree::
    470482
    471    setup.py
    472    src/
    473        mypkg/
    474            __init__.py
    475            module.py
    476            data/
    477                tables.dat
    478                spoons.dat
    479                forks.dat
     483    setup.py
     484    src/
     485        mypkg/
     486            __init__.py
     487            module.py
     488            data/
     489                tables.dat
     490                spoons.dat
     491                forks.dat
    480492
    481493The corresponding call to :func:`setup` might be::
    482494
    483    setup(...,
    484          packages=['mypkg'],
    485          package_dir={'mypkg': 'src/mypkg'},
    486          package_data={'mypkg': ['data/*.dat']},
    487          )
     495    setup(...,
     496          packages=['mypkg'],
     497          package_dir={'mypkg': 'src/mypkg'},
     498          package_data={'mypkg': ['data/*.dat']},
     499          )
    488500
    489501.. versionadded:: 2.4
    490502
     503.. versionchanged:: 2.7
     504    All the files that match ``package_data`` will be added to the ``MANIFEST``
     505    file if no template is provided. See :ref:`manifest`.
     506
     507
     508.. _distutils-additional-files:
    491509
    492510Installing Additional Files
     
    500518following way::
    501519
    502    setup(...,
    503          data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
    504                      ('config', ['cfg/data.cfg']),
    505                      ('/etc/init.d', ['init-script'])]
    506         )
     520    setup(...,
     521          data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
     522                      ('config', ['cfg/data.cfg']),
     523                      ('/etc/init.d', ['init-script'])]
     524         )
    507525
    508526Note that you can specify the directory names where the data files will be
     
    524542directory.
    525543
     544.. versionchanged:: 2.7
     545    All the files that match ``data_files`` will be added to the ``MANIFEST``
     546    file if no template is provided. See :ref:`manifest`.
     547
     548
    526549
    527550.. _meta-data:
     
    556579|                      | package                   |                 |        |
    557580+----------------------+---------------------------+-----------------+--------+
    558 | ``long_description`` | longer description of the | long string     |        |
     581| ``long_description`` | longer description of the | long string     | \(5)   |
    559582|                      | package                   |                 |        |
    560583+----------------------+---------------------------+-----------------+--------+
     
    572595
    573596(1)
    574    These fields are required.
     597    These fields are required.
    575598
    576599(2)
    577    It is recommended that versions take the form *major.minor[.patch[.sub]]*.
     600    It is recommended that versions take the form *major.minor[.patch[.sub]]*.
    578601
    579602(3)
    580    Either the author or the maintainer must be identified.
     603    Either the author or the maintainer must be identified. If maintainer is
     604    provided, distutils lists it as the author in :file:`PKG-INFO`.
    581605
    582606(4)
    583    These fields should not be used if your package is to be compatible with Python
    584    versions prior to 2.2.3 or 2.3.  The list is available from the `PyPI website
    585    <http://pypi.python.org/pypi>`_.
     607    These fields should not be used if your package is to be compatible with Python
     608    versions prior to 2.2.3 or 2.3.  The list is available from the `PyPI website
     609    <http://pypi.python.org/pypi>`_.
     610
     611(5)
     612    The ``long_description`` field is used by PyPI when you are
     613    :ref:`registering <package-register>` a package, to
     614    :ref:`build its home page <package-display>`.
    586615
    587616(6)
     
    593622
    594623'short string'
    595    A single line of text, not more than 200 characters.
     624    A single line of text, not more than 200 characters.
    596625
    597626'long string'
    598    Multiple lines of plain text in reStructuredText format (see
    599    http://docutils.sf.net/).
     627    Multiple lines of plain text in reStructuredText format (see
     628    http://docutils.sf.net/).
    600629
    601630'list of strings'
    602    See below.
     631    See below.
    603632
    604633None of the string values may be Unicode.
     
    616645
    6176460.1.0
    618    the first, experimental release of a package
     647    the first, experimental release of a package
    619648
    6206491.0.1a2
    621    the second alpha release of the first patch version of 1.0
     650    the second alpha release of the first patch version of 1.0
    622651
    623652:option:`classifiers` are specified in a Python list::
    624653
    625    setup(...,
    626          classifiers=[
    627              'Development Status :: 4 - Beta',
    628              'Environment :: Console',
    629              'Environment :: Web Environment',
    630              'Intended Audience :: End Users/Desktop',
    631              'Intended Audience :: Developers',
    632              'Intended Audience :: System Administrators',
    633              'License :: OSI Approved :: Python Software Foundation License',
    634              'Operating System :: MacOS :: MacOS X',
    635              'Operating System :: Microsoft :: Windows',
    636              'Operating System :: POSIX',
    637              'Programming Language :: Python',
    638              'Topic :: Communications :: Email',
    639              'Topic :: Office/Business',
    640              'Topic :: Software Development :: Bug Tracking',
    641              ],
    642          )
     654    setup(...,
     655          classifiers=[
     656              'Development Status :: 4 - Beta',
     657              'Environment :: Console',
     658              'Environment :: Web Environment',
     659              'Intended Audience :: End Users/Desktop',
     660              'Intended Audience :: Developers',
     661              'Intended Audience :: System Administrators',
     662              'License :: OSI Approved :: Python Software Foundation License',
     663              'Operating System :: MacOS :: MacOS X',
     664              'Operating System :: Microsoft :: Windows',
     665              'Operating System :: POSIX',
     666              'Programming Language :: Python',
     667              'Topic :: Communications :: Email',
     668              'Topic :: Office/Business',
     669              'Topic :: Software Development :: Bug Tracking',
     670              ],
     671          )
    643672
    644673If you wish to include classifiers in your :file:`setup.py` file and also wish
     
    647676:func:`setup` call. ::
    648677
    649    # patch distutils if it can't cope with the "classifiers" or
    650    # "download_url" keywords
    651    from sys import version
    652    if version < '2.2.3':
    653        from distutils.dist import DistributionMetadata
    654        DistributionMetadata.classifiers = None
    655        DistributionMetadata.download_url = None
     678    # patch distutils if it can't cope with the "classifiers" or
     679    # "download_url" keywords
     680    from sys import version
     681    if version < '2.2.3':
     682        from distutils.dist import DistributionMetadata
     683        DistributionMetadata.classifiers = None
     684        DistributionMetadata.download_url = None
    656685
    657686
     
    675704information what it is doing, and prints the full traceback in case an exception
    676705occurs.
    677 
    678 
Note: See TracChangeset for help on using the changeset viewer.