diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-10 23:21:49 (GMT) |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-10 23:21:49 (GMT) |
commit | 375dc9b8b42cd9a8b98679c751dc859620956be3 (patch) | |
tree | 060aadab7a2f633b28c029e131b568afe0f165f6 /Doc | |
parent | 711e91b28397281f95c2d98dfc9561d38b8f8c41 (diff) | |
parent | 3492e39b447a8e76df9da1cc05bd1cdf504e74f1 (diff) | |
download | cpython-375dc9b8b42cd9a8b98679c751dc859620956be3.zip cpython-375dc9b8b42cd9a8b98679c751dc859620956be3.tar.gz cpython-375dc9b8b42cd9a8b98679c751dc859620956be3.tar.bz2 |
Merge with 3.3 for Issue #19544 and Issue #7457
Diffstat (limited to 'Doc')
-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 b268486..5eb654a 100644 --- a/Doc/distutils/examples.rst +++ b/Doc/distutils/examples.rst @@ -284,6 +284,48 @@ by using the :mod:`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} |