Changeset 391 for python/trunk/Doc/distutils/setupscript.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/distutils/setupscript.rst
r2 r391 20 20 the package into Python 1.5.2.) :: 21 21 22 #!/usr/bin/env python23 24 from distutils.core import setup25 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 ) 34 34 35 35 There are only two differences between this and the trivial one-file … … 54 54 code instead of hardcoding path separators:: 55 55 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')) 58 58 59 59 … … 73 73 might be spelled differently on your system, but you get the idea) relative to 74 74 the directory where your setup script lives. If you break this promise, the 75 Distutils will issue a warning but still process the broken package anyway s.75 Distutils will issue a warning but still process the broken package anyway. 76 76 77 77 If you use a different convention to lay out your source directory, that's no … … 82 82 :file:`lib/foo`, and so forth. Then you would put :: 83 83 84 package_dir = {'': 'lib'}84 package_dir = {'': 'lib'} 85 85 86 86 in your setup script. The keys to this dictionary are package names, and an … … 93 93 written in the setup script as :: 94 94 95 package_dir = {'foo': 'lib'}95 package_dir = {'foo': 'lib'} 96 96 97 97 A ``package: dir`` entry in the :option:`package_dir` dictionary implicitly … … 115 115 section :ref:`distutils-simple-example`; here is a slightly more involved example:: 116 116 117 py_modules = ['mod1', 'pkg.mod2']117 py_modules = ['mod1', 'pkg.mod2'] 118 118 119 119 This describes two modules, one of them in the "root" package, the other in the … … 140 140 All of this is done through another keyword argument to :func:`setup`, the 141 141 :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 143 single extension module. 143 144 Suppose your distribution includes a single extension, called :mod:`foo` and 144 145 implemented by :file:`foo.c`. If no additional instructions to the 145 146 compiler/linker are needed, describing this extension is quite simple:: 146 147 147 Extension('foo', ['foo.c'])148 Extension('foo', ['foo.c']) 148 149 149 150 The :class:`Extension` class can be imported from :mod:`distutils.core` along … … 151 152 contains only this one extension and nothing else might be:: 152 153 153 from distutils.core import setup, Extension154 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 ) 158 159 159 160 The :class:`Extension` class (actually, the underlying extension-building … … 166 167 ---------------------------- 167 168 168 The first argument to the :class:` Extension` constructor is always the name of169 the extension, including any package names. For example, ::170 171 Extension('foo', ['src/foo1.c', 'src/foo2.c'])169 The first argument to the :class:`~distutils.core.Extension` constructor is 170 always the name of the extension, including any package names. For example, :: 171 172 Extension('foo', ['src/foo1.c', 'src/foo2.c']) 172 173 173 174 describes an extension that lives in the root package, while :: 174 175 175 Extension('pkg.foo', ['src/foo1.c', 'src/foo2.c'])176 Extension('pkg.foo', ['src/foo1.c', 'src/foo2.c']) 176 177 177 178 describes the same extension in the :mod:`pkg` package. The source files and … … 184 185 :func:`setup`. For example, :: 185 186 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 ) 191 192 192 193 will compile :file:`foo.c` to the extension :mod:`pkg.foo`, and :file:`bar.c` to … … 197 198 ---------------------- 198 199 199 The second argument to the :class:`Extension` constructor is a list of source 200 The second argument to the :class:`~distutils.core.Extension` constructor is 201 a list of source 200 202 files. Since the Distutils currently only support C, C++, and Objective-C 201 203 extensions, these are normally C/C++/Objective-C source files. (Be sure to use … … 208 210 extension. 209 211 210 **\*\*** SWIG support is rough around the edges and largely untested! **\*\*** 212 .. XXX SWIG support is rough around the edges and largely untested! 211 213 212 214 This warning notwithstanding, options to SWIG can be currently passed like 213 215 this:: 214 216 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 ) 220 222 221 223 Or on the commandline like this:: 222 224 223 > python setup.py build_ext --swig-opts="-modern -I../include"225 > python setup.py build_ext --swig-opts="-modern -I../include" 224 226 225 227 On some platforms, you can include non-source files that are processed by the … … 233 235 -------------------- 234 236 235 Three optional arguments to :class:` Extension` will help if you need to specify236 include directories to search or preprocessor macros to define/undefine: 237 ``include_dirs``, ``define_macros``, and ``undef_macros``.237 Three optional arguments to :class:`~distutils.core.Extension` will help if 238 you need to specify include directories to search or preprocessor macros to 239 define/undefine: ``include_dirs``, ``define_macros``, and ``undef_macros``. 238 240 239 241 For example, if your extension requires header files in the :file:`include` 240 242 directory under your distribution root, use the ``include_dirs`` option:: 241 243 242 Extension('foo', ['foo.c'], include_dirs=['include'])244 Extension('foo', ['foo.c'], include_dirs=['include']) 243 245 244 246 You can specify absolute directories there; if you know that your extension will … … 246 248 away with :: 247 249 248 Extension('foo', ['foo.c'], include_dirs=['/usr/include/X11'])250 Extension('foo', ['foo.c'], include_dirs=['/usr/include/X11']) 249 251 250 252 You should avoid this sort of non-portable usage if you plan to distribute your 251 253 code: it's probably better to write C code like :: 252 254 253 #include <X11/Xlib.h>255 #include <X11/Xlib.h> 254 256 255 257 If you need to include header files from some other Python extension, you can 256 258 take advantage of the fact that header files are installed in a consistent way 257 by the Distutils :command:`install_header ` command. For example, the Numerical259 by the Distutils :command:`install_headers` command. For example, the Numerical 258 260 Python header files are installed (on a standard Unix installation) to 259 261 :file:`/usr/local/include/python1.5/Numerical`. (The exact location will differ … … 263 265 is to write C code like :: 264 266 265 #include <Numerical/arrayobject.h>267 #include <Numerical/arrayobject.h> 266 268 267 269 If you must put the :file:`Numerical` include directory right into your header … … 269 271 :mod:`distutils.sysconfig` module:: 270 272 271 from distutils.sysconfig import get_python_inc272 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 ) 276 278 277 279 Even though this is quite portable---it will work on any Python installation, … … 289 291 For example:: 290 292 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']) 295 297 296 298 is the equivalent of having this at the top of every C source file:: 297 299 298 #define NDEBUG 1299 #define HAVE_STRFTIME300 #undef HAVE_FOO301 #undef HAVE_BAR300 #define NDEBUG 1 301 #define HAVE_STRFTIME 302 #undef HAVE_FOO 303 #undef HAVE_BAR 302 304 303 305 … … 314 316 library search path on target systems :: 315 317 316 Extension(...,317 libraries=['gdbm', 'readline'])318 Extension(..., 319 libraries=['gdbm', 'readline']) 318 320 319 321 If you need to link with libraries in a non-standard location, you'll have to 320 322 include the location in ``library_dirs``:: 321 323 322 Extension(...,323 library_dirs=['/usr/X11R6/lib'],324 libraries=['X11', 'Xt'])324 Extension(..., 325 library_dirs=['/usr/X11R6/lib'], 326 libraries=['X11', 'Xt']) 325 327 326 328 (Again, this sort of non-portable construct should be avoided if you intend to 327 329 distribute your code.) 328 330 329 **\*\*** Should mention clib libraries here or somewhere else! **\*\*** 331 .. XXX Should mention clib libraries here or somewhere else! 330 332 331 333 … … 348 350 to the list of exported symbols. 349 351 352 The :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 354 sources to rebuild extension if any on this files has been modified since the 355 previous build. 350 356 351 357 Relationships between Distributions and Packages … … 376 382 number. The accepted comparison operators are:: 377 383 378 < > ==379 <= >= !=384 < > == 385 <= >= != 380 386 381 387 These can be combined by using multiple qualifiers separated by commas (and … … 424 430 named module or package are understood to be obsoleted. 425 431 432 .. _distutils-installing-scripts: 426 433 427 434 Installing Scripts … … 442 449 way. From the PyXML setup script:: 443 450 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: 448 460 449 461 Installing Package Data … … 469 481 the files can be arranged like this in the source tree:: 470 482 471 setup.py472 src/473 mypkg/474 __init__.py475 module.py476 data/477 tables.dat478 spoons.dat479 forks.dat483 setup.py 484 src/ 485 mypkg/ 486 __init__.py 487 module.py 488 data/ 489 tables.dat 490 spoons.dat 491 forks.dat 480 492 481 493 The corresponding call to :func:`setup` might be:: 482 494 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 ) 488 500 489 501 .. versionadded:: 2.4 490 502 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: 491 509 492 510 Installing Additional Files … … 500 518 following way:: 501 519 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 ) 507 525 508 526 Note that you can specify the directory names where the data files will be … … 524 542 directory. 525 543 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 526 549 527 550 .. _meta-data: … … 556 579 | | package | | | 557 580 +----------------------+---------------------------+-----------------+--------+ 558 | ``long_description`` | longer description of the | long string | 581 | ``long_description`` | longer description of the | long string | \(5) | 559 582 | | package | | | 560 583 +----------------------+---------------------------+-----------------+--------+ … … 572 595 573 596 (1) 574 These fields are required.597 These fields are required. 575 598 576 599 (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]]*. 578 601 579 602 (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`. 581 605 582 606 (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>`. 586 615 587 616 (6) … … 593 622 594 623 'short string' 595 A single line of text, not more than 200 characters.624 A single line of text, not more than 200 characters. 596 625 597 626 'long string' 598 Multiple lines of plain text in reStructuredText format (see599 http://docutils.sf.net/).627 Multiple lines of plain text in reStructuredText format (see 628 http://docutils.sf.net/). 600 629 601 630 'list of strings' 602 See below.631 See below. 603 632 604 633 None of the string values may be Unicode. … … 616 645 617 646 0.1.0 618 the first, experimental release of a package647 the first, experimental release of a package 619 648 620 649 1.0.1a2 621 the second alpha release of the first patch version of 1.0650 the second alpha release of the first patch version of 1.0 622 651 623 652 :option:`classifiers` are specified in a Python list:: 624 653 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 ) 643 672 644 673 If you wish to include classifiers in your :file:`setup.py` file and also wish … … 647 676 :func:`setup` call. :: 648 677 649 # patch distutils if it can't cope with the "classifiers" or650 # "download_url" keywords651 from sys import version652 if version < '2.2.3':653 from distutils.dist import DistributionMetadata654 DistributionMetadata.classifiers = None655 DistributionMetadata.download_url = None678 # 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 656 685 657 686 … … 675 704 information what it is doing, and prints the full traceback in case an exception 676 705 occurs. 677 678
Note:
See TracChangeset
for help on using the changeset viewer.