2007-08-15 11:28:22 -03:00
|
|
|
.. _examples:
|
|
|
|
|
|
|
|
********
|
|
|
|
Examples
|
|
|
|
********
|
|
|
|
|
|
|
|
This chapter provides a number of basic examples to help get started with
|
|
|
|
distutils. Additional information about using distutils can be found in the
|
|
|
|
Distutils Cookbook.
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
2009-04-11 11:32:37 -03:00
|
|
|
`Distutils Cookbook <http://wiki.python.org/moin/Distutils/Cookbook>`_
|
2007-08-15 11:28:22 -03:00
|
|
|
Collection of recipes showing how to achieve more control over distutils.
|
|
|
|
|
|
|
|
|
|
|
|
.. _pure-mod:
|
|
|
|
|
|
|
|
Pure Python distribution (by module)
|
|
|
|
====================================
|
|
|
|
|
|
|
|
If you're just distributing a couple of modules, especially if they don't live
|
|
|
|
in a particular package, you can specify them individually using the
|
|
|
|
:option:`py_modules` option in the setup script.
|
|
|
|
|
|
|
|
In the simplest case, you'll have two files to worry about: a setup script and
|
|
|
|
the single module you're distributing, :file:`foo.py` in this example::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
foo.py
|
|
|
|
|
|
|
|
(In all diagrams in this section, *<root>* will refer to the distribution root
|
|
|
|
directory.) A minimal setup script to describe this situation would be::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foo',
|
|
|
|
version='1.0',
|
|
|
|
py_modules=['foo'],
|
|
|
|
)
|
|
|
|
|
|
|
|
Note that the name of the distribution is specified independently with the
|
|
|
|
:option:`name` option, and there's no rule that says it has to be the same as
|
|
|
|
the name of the sole module in the distribution (although that's probably a good
|
|
|
|
convention to follow). However, the distribution name is used to generate
|
|
|
|
filenames, so you should stick to letters, digits, underscores, and hyphens.
|
|
|
|
|
|
|
|
Since :option:`py_modules` is a list, you can of course specify multiple
|
|
|
|
modules, eg. if you're distributing modules :mod:`foo` and :mod:`bar`, your
|
|
|
|
setup might look like this::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
foo.py
|
|
|
|
bar.py
|
|
|
|
|
|
|
|
and the setup script might be ::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
py_modules=['foo', 'bar'],
|
|
|
|
)
|
|
|
|
|
|
|
|
You can put module source files into another directory, but if you have enough
|
|
|
|
modules to do that, it's probably easier to specify modules by package rather
|
|
|
|
than listing them individually.
|
|
|
|
|
|
|
|
|
|
|
|
.. _pure-pkg:
|
|
|
|
|
|
|
|
Pure Python distribution (by package)
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
If you have more than a couple of modules to distribute, especially if they are
|
|
|
|
in multiple packages, it's probably easier to specify whole packages rather than
|
|
|
|
individual modules. This works even if your modules are not in a package; you
|
|
|
|
can just tell the Distutils to process modules from the root package, and that
|
|
|
|
works the same as any other package (except that you don't have to have an
|
|
|
|
:file:`__init__.py` file).
|
|
|
|
|
|
|
|
The setup script from the last example could also be written as ::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
packages=[''],
|
|
|
|
)
|
|
|
|
|
|
|
|
(The empty string stands for the root package.)
|
|
|
|
|
|
|
|
If those two files are moved into a subdirectory, but remain in the root
|
|
|
|
package, e.g.::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
src/ foo.py
|
|
|
|
bar.py
|
|
|
|
|
|
|
|
then you would still specify the root package, but you have to tell the
|
|
|
|
Distutils where source files in the root package live::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
package_dir={'': 'src'},
|
|
|
|
packages=[''],
|
|
|
|
)
|
|
|
|
|
|
|
|
More typically, though, you will want to distribute multiple modules in the same
|
|
|
|
package (or in sub-packages). For example, if the :mod:`foo` and :mod:`bar`
|
|
|
|
modules belong in package :mod:`foobar`, one way to layout your source tree is
|
|
|
|
::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
foobar/
|
|
|
|
__init__.py
|
|
|
|
foo.py
|
|
|
|
bar.py
|
|
|
|
|
|
|
|
This is in fact the default layout expected by the Distutils, and the one that
|
|
|
|
requires the least work to describe in your setup script::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
packages=['foobar'],
|
|
|
|
)
|
|
|
|
|
|
|
|
If you want to put modules in directories not named for their package, then you
|
|
|
|
need to use the :option:`package_dir` option again. For example, if the
|
|
|
|
:file:`src` directory holds modules in the :mod:`foobar` package::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
src/
|
|
|
|
__init__.py
|
|
|
|
foo.py
|
|
|
|
bar.py
|
|
|
|
|
|
|
|
an appropriate setup script would be ::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
package_dir={'foobar': 'src'},
|
|
|
|
packages=['foobar'],
|
|
|
|
)
|
|
|
|
|
|
|
|
Or, you might put modules from your main package right in the distribution
|
|
|
|
root::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
__init__.py
|
|
|
|
foo.py
|
|
|
|
bar.py
|
|
|
|
|
|
|
|
in which case your setup script would be ::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
package_dir={'foobar': ''},
|
|
|
|
packages=['foobar'],
|
|
|
|
)
|
|
|
|
|
|
|
|
(The empty string also stands for the current directory.)
|
|
|
|
|
|
|
|
If you have sub-packages, they must be explicitly listed in :option:`packages`,
|
|
|
|
but any entries in :option:`package_dir` automatically extend to sub-packages.
|
|
|
|
(In other words, the Distutils does *not* scan your source tree, trying to
|
|
|
|
figure out which directories correspond to Python packages by looking for
|
|
|
|
:file:`__init__.py` files.) Thus, if the default layout grows a sub-package::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
foobar/
|
|
|
|
__init__.py
|
|
|
|
foo.py
|
|
|
|
bar.py
|
|
|
|
subfoo/
|
|
|
|
__init__.py
|
|
|
|
blah.py
|
|
|
|
|
|
|
|
then the corresponding setup script would be ::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
packages=['foobar', 'foobar.subfoo'],
|
|
|
|
)
|
|
|
|
|
|
|
|
(Again, the empty string in :option:`package_dir` stands for the current
|
|
|
|
directory.)
|
|
|
|
|
|
|
|
|
|
|
|
.. _single-ext:
|
|
|
|
|
|
|
|
Single extension module
|
|
|
|
=======================
|
|
|
|
|
|
|
|
Extension modules are specified using the :option:`ext_modules` option.
|
|
|
|
:option:`package_dir` has no effect on where extension source files are found;
|
|
|
|
it only affects the source for pure Python modules. The simplest case, a
|
|
|
|
single extension module in a single C source file, is::
|
|
|
|
|
|
|
|
<root>/
|
|
|
|
setup.py
|
|
|
|
foo.c
|
|
|
|
|
|
|
|
If the :mod:`foo` extension belongs in the root package, the setup script for
|
|
|
|
this could be ::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
from distutils.extension import Extension
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
ext_modules=[Extension('foo', ['foo.c'])],
|
|
|
|
)
|
|
|
|
|
|
|
|
If the extension actually belongs in a package, say :mod:`foopkg`, then
|
|
|
|
|
|
|
|
With exactly the same source tree layout, this extension can be put in the
|
|
|
|
:mod:`foopkg` package simply by changing the name of the extension::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
from distutils.extension import Extension
|
|
|
|
setup(name='foobar',
|
|
|
|
version='1.0',
|
|
|
|
ext_modules=[Extension('foopkg.foo', ['foo.c'])],
|
|
|
|
)
|
|
|
|
|
2009-04-11 12:00:43 -03:00
|
|
|
Checking a package
|
|
|
|
==================
|
|
|
|
|
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines
Mention issue6972 in extractall docs about overwriting things outside of
the supplied path.
........
r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line
Wording fix
........
r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line
Fix narkup
........
r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line
Document 'skip' parameter to constructor
........
r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line
Note side benefit of socket.create_connection()
........
r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line
Reword sentence
........
r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line
Use standard comma punctuation; reword some sentences in the docs
........
r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line
Backport r73983: Document the thousands separator.
........
r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line
death to old CVS keyword
........
r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line
fix some coding style
........
r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line
platform we don't care about
........
r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines
Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
Patch by Christopher Tur Lesniewski-Laas.
........
r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line
pep8ify if blocks
........
r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line
use floor division and add a test that exercises the tabsize codepath
........
r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line
change test to what I intended
........
r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line
some cleanups
........
r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line
make inspect.isabstract() always return a boolean; add a test for it, too #7069
........
r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line
only clear a module's __dict__ if the module is the only one with a reference to it #7140
........
r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line
Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE.
........
r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines
Add a comment about unreachable code, and fix a typo
........
r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line
use property api
........
r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line
clarify buffer arg #7178
........
r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line
whitespace
........
r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line
rewrite to be nice to other implementations
........
r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines
rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
........
r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines
Fix compilation error in debug mode.
........
r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line
use 'is' instead of id()
........
r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line
test expect base classes
........
r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line
Use the correct function name in docstring.
........
r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line
Remove mention of the old -X command line switch.
........
r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line
Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests.
........
r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line
Use a single style for all the docstrings in the math module.
........
r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line
I do not think the "railroad" program mentioned is still available.
........
r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line
Fix constant name.
........
r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line
prevent a rather unlikely segfault
........
r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line
#7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs.
........
r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line
spelling
........
r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line
#7271: fix typo.
........
r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line
discuss how to use -p
........
r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line
Give the profile module a module directive.
........
2009-11-12 22:25:08 -04:00
|
|
|
The ``check`` command allows you to verify if your package meta-data
|
|
|
|
meet the minimum requirements to build a distribution.
|
2009-04-11 12:00:43 -03:00
|
|
|
|
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines
Mention issue6972 in extractall docs about overwriting things outside of
the supplied path.
........
r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line
Wording fix
........
r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line
Fix narkup
........
r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line
Document 'skip' parameter to constructor
........
r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line
Note side benefit of socket.create_connection()
........
r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line
Reword sentence
........
r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line
Use standard comma punctuation; reword some sentences in the docs
........
r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line
Backport r73983: Document the thousands separator.
........
r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line
death to old CVS keyword
........
r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line
fix some coding style
........
r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line
platform we don't care about
........
r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines
Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
Patch by Christopher Tur Lesniewski-Laas.
........
r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line
pep8ify if blocks
........
r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line
use floor division and add a test that exercises the tabsize codepath
........
r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line
change test to what I intended
........
r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line
some cleanups
........
r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line
make inspect.isabstract() always return a boolean; add a test for it, too #7069
........
r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line
only clear a module's __dict__ if the module is the only one with a reference to it #7140
........
r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line
Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE.
........
r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines
Add a comment about unreachable code, and fix a typo
........
r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line
use property api
........
r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line
clarify buffer arg #7178
........
r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line
whitespace
........
r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line
rewrite to be nice to other implementations
........
r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines
rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
........
r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines
Fix compilation error in debug mode.
........
r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line
use 'is' instead of id()
........
r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line
test expect base classes
........
r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line
Use the correct function name in docstring.
........
r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line
Remove mention of the old -X command line switch.
........
r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line
Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests.
........
r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line
Use a single style for all the docstrings in the math module.
........
r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line
I do not think the "railroad" program mentioned is still available.
........
r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line
Fix constant name.
........
r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line
prevent a rather unlikely segfault
........
r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line
#7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs.
........
r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line
spelling
........
r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line
#7271: fix typo.
........
r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line
discuss how to use -p
........
r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line
Give the profile module a module directive.
........
2009-11-12 22:25:08 -04:00
|
|
|
To run it, just call it using your :file:`setup.py` script. If something is
|
2009-04-11 12:00:43 -03:00
|
|
|
missing, ``check`` will display a warning.
|
|
|
|
|
|
|
|
Let's take an example with a simple script::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
|
|
|
|
setup(name='foobar')
|
|
|
|
|
|
|
|
Running the ``check`` command will display some warnings::
|
|
|
|
|
|
|
|
$ python setup.py check
|
|
|
|
running check
|
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines
Mention issue6972 in extractall docs about overwriting things outside of
the supplied path.
........
r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line
Wording fix
........
r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line
Fix narkup
........
r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line
Document 'skip' parameter to constructor
........
r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line
Note side benefit of socket.create_connection()
........
r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line
Reword sentence
........
r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line
Use standard comma punctuation; reword some sentences in the docs
........
r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line
Backport r73983: Document the thousands separator.
........
r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line
death to old CVS keyword
........
r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line
fix some coding style
........
r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line
platform we don't care about
........
r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines
Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
Patch by Christopher Tur Lesniewski-Laas.
........
r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line
pep8ify if blocks
........
r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line
use floor division and add a test that exercises the tabsize codepath
........
r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line
change test to what I intended
........
r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line
some cleanups
........
r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line
make inspect.isabstract() always return a boolean; add a test for it, too #7069
........
r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line
only clear a module's __dict__ if the module is the only one with a reference to it #7140
........
r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line
Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE.
........
r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines
Add a comment about unreachable code, and fix a typo
........
r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line
use property api
........
r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line
clarify buffer arg #7178
........
r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line
whitespace
........
r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line
rewrite to be nice to other implementations
........
r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines
rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
........
r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines
Fix compilation error in debug mode.
........
r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line
use 'is' instead of id()
........
r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line
test expect base classes
........
r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line
Use the correct function name in docstring.
........
r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line
Remove mention of the old -X command line switch.
........
r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line
Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests.
........
r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line
Use a single style for all the docstrings in the math module.
........
r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line
I do not think the "railroad" program mentioned is still available.
........
r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line
Fix constant name.
........
r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line
prevent a rather unlikely segfault
........
r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line
#7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs.
........
r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line
spelling
........
r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line
#7271: fix typo.
........
r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line
discuss how to use -p
........
r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line
Give the profile module a module directive.
........
2009-11-12 22:25:08 -04:00
|
|
|
warning: check: missing required meta-data: version, url
|
2009-04-11 12:00:43 -03:00
|
|
|
warning: check: missing meta-data: either (author and author_email) or
|
|
|
|
(maintainer and maintainer_email) must be supplied
|
|
|
|
|
|
|
|
|
2010-03-12 06:06:40 -04:00
|
|
|
If you use the reStructuredText syntax in the ``long_description`` field and
|
2009-04-11 12:00:43 -03:00
|
|
|
`docutils <http://docutils.sourceforge.net/>`_ is installed you can check if
|
2010-03-12 06:06:40 -04:00
|
|
|
the syntax is fine with the ``check`` command, using the ``restructuredtext``
|
2009-04-11 12:00:43 -03:00
|
|
|
option.
|
|
|
|
|
|
|
|
For example, if the :file:`setup.py` script is changed like this::
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
|
|
|
|
desc = """\
|
|
|
|
My description
|
|
|
|
=============
|
|
|
|
|
|
|
|
This is the description of the ``foobar`` package.
|
|
|
|
"""
|
|
|
|
|
|
|
|
setup(name='foobar', version='1', author='tarek',
|
|
|
|
author_email='tarek@ziade.org',
|
|
|
|
url='http://example.com', long_description=desc)
|
|
|
|
|
|
|
|
Where the long description is broken, ``check`` will be able to detect it
|
2010-03-12 06:06:40 -04:00
|
|
|
by using the :mod:`docutils` parser::
|
2009-04-11 12:00:43 -03:00
|
|
|
|
|
|
|
$ pythontrunk setup.py check --restructuredtext
|
|
|
|
running check
|
|
|
|
warning: check: Title underline too short. (line 2)
|
|
|
|
warning: check: Could not finish the parsing.
|
|
|
|
|
Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines
Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done
partially before. Also add a comment describing how this might have to work
with different versions of the interpreter.
........
r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line
Fixed typo
........
r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line
#7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such.
........
r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line
Add note about usage of STRINGLIB_EMPTY.
........
r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line
Fix internal reference.
........
r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines
data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
........
r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
........
r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line
Add two more test_strtod test values.
........
r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line
#7762: fix refcount annotation of PyUnicode_Tailmatch().
........
r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line
#7725: fix referencing issue.
........
r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line
mention from_float() in error message
........
r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line
#7802: fix invalid example (heh).
........
r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines
Fix-up ftplib documentation:
move exception descriptions to toplevel, not inside a class
remove attribution in "versionadded"
spell and grammar check docstring of FTP_TLS
........
r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line
Minor modification to unittest documentation.
........
2010-02-02 22:35:45 -04:00
|
|
|
|
|
|
|
.. _reading-metadata:
|
|
|
|
|
2009-12-08 05:45:25 -04:00
|
|
|
Reading the metadata
|
Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines
Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done
partially before. Also add a comment describing how this might have to work
with different versions of the interpreter.
........
r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line
Fixed typo
........
r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line
#7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such.
........
r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line
Add note about usage of STRINGLIB_EMPTY.
........
r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line
Fix internal reference.
........
r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines
data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
........
r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
........
r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line
Add two more test_strtod test values.
........
r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line
#7762: fix refcount annotation of PyUnicode_Tailmatch().
........
r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line
#7725: fix referencing issue.
........
r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line
mention from_float() in error message
........
r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line
#7802: fix invalid example (heh).
........
r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines
Fix-up ftplib documentation:
move exception descriptions to toplevel, not inside a class
remove attribution in "versionadded"
spell and grammar check docstring of FTP_TLS
........
r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line
Minor modification to unittest documentation.
........
2010-02-02 22:35:45 -04:00
|
|
|
====================
|
2009-12-08 05:45:25 -04:00
|
|
|
|
|
|
|
The :func:`distutils.core.setup` function provides a command-line interface
|
|
|
|
that allows you to query the metadata fields of a project through the
|
2010-03-12 06:06:40 -04:00
|
|
|
:file:`setup.py` script of a given project::
|
2009-12-08 05:45:25 -04:00
|
|
|
|
|
|
|
$ python setup.py --name
|
|
|
|
distribute
|
|
|
|
|
2010-03-12 06:06:40 -04:00
|
|
|
This call reads the ``name`` metadata by running the
|
2009-12-08 05:45:25 -04:00
|
|
|
:func:`distutils.core.setup` function. Although, when a source or binary
|
|
|
|
distribution is created with Distutils, the metadata fields are written
|
|
|
|
in a static file called :file:`PKG-INFO`. When a Distutils-based project is
|
|
|
|
installed in Python, the :file:`PKG-INFO` file is copied alongside the modules
|
|
|
|
and packages of the distribution under :file:`NAME-VERSION-pyX.X.egg-info`,
|
2010-03-12 06:06:40 -04:00
|
|
|
where ``NAME`` is the name of the project, ``VERSION`` its version as defined
|
|
|
|
in the Metadata, and ``pyX.X`` the major and minor version of Python like
|
|
|
|
``2.7`` or ``3.2``.
|
2009-12-08 05:45:25 -04:00
|
|
|
|
|
|
|
You can read back this static file, by using the
|
|
|
|
:class:`distutils.dist.DistributionMetadata` class and its
|
|
|
|
:func:`read_pkg_file` method::
|
|
|
|
|
|
|
|
>>> from distutils.dist import DistributionMetadata
|
|
|
|
>>> metadata = DistributionMetadata()
|
|
|
|
>>> metadata.read_pkg_file(open('distribute-0.6.8-py2.7.egg-info'))
|
|
|
|
>>> metadata.name
|
|
|
|
'distribute'
|
|
|
|
>>> metadata.version
|
|
|
|
'0.6.8'
|
|
|
|
>>> metadata.description
|
|
|
|
'Easily download, build, install, upgrade, and uninstall Python packages'
|
|
|
|
|
|
|
|
Notice that the class can also be instanciated with a metadata file path to
|
|
|
|
loads its values::
|
|
|
|
|
|
|
|
>>> pkg_info_path = 'distribute-0.6.8-py2.7.egg-info'
|
|
|
|
>>> DistributionMetadata(pkg_info_path).name
|
|
|
|
'distribute'
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. % \section{Multiple extension modules}
|
|
|
|
.. % \label{multiple-ext}
|
|
|
|
|
|
|
|
.. % \section{Putting it all together}
|
|
|
|
|
|
|
|
|