diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-12-08 09:45:25 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-12-08 09:45:25 (GMT) |
commit | b88a49607a6e36489a41003a66b673f573f32069 (patch) | |
tree | 397cb44893ec683ae459905d4b3d2f022a462410 /Doc/distutils | |
parent | 0b9293f28bcfc05cb67b2b3f9c6c1fec3194ea28 (diff) | |
download | cpython-b88a49607a6e36489a41003a66b673f573f32069.zip cpython-b88a49607a6e36489a41003a66b673f573f32069.tar.gz cpython-b88a49607a6e36489a41003a66b673f573f32069.tar.bz2 |
Merged revisions 76702,76704 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76702 | tarek.ziade | 2009-12-08 09:56:49 +0100 (Tue, 08 Dec 2009) | 1 line
Issue #7457: added a read_pkg_file method to distutils.dist.DistributionMetadata so we can read back PKG-INFO files
........
r76704 | tarek.ziade | 2009-12-08 10:39:51 +0100 (Tue, 08 Dec 2009) | 1 line
removed the usage of rfc822 in favor of email.message.Message
........
Diffstat (limited to 'Doc/distutils')
-rw-r--r-- | Doc/distutils/examples.rst | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Doc/distutils/examples.rst b/Doc/distutils/examples.rst index 648063b..35de57e 100644 --- a/Doc/distutils/examples.rst +++ b/Doc/distutils/examples.rst @@ -285,6 +285,48 @@ by using the `docutils` parser:: warning: check: Title underline too short. (line 2) warning: check: Could not finish the parsing. +Reading the metadata +===================== + +The :func:`distutils.core.setup` function provides a command-line interface +that allows you to query the metadata fields of a project through the +`setup.py` script of a given project:: + + $ python setup.py --name + distribute + +This call reads the `name` metadata by running the +: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`, +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`. + +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' + + .. % \section{Multiple extension modules} .. % \label{multiple-ext} |