mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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 ........
This commit is contained in:
parent
0b9293f28b
commit
b88a49607a
5 changed files with 150 additions and 18 deletions
|
@ -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}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue