diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-10 23:15:03 (GMT) |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-10 23:15:03 (GMT) |
commit | 3492e39b447a8e76df9da1cc05bd1cdf504e74f1 (patch) | |
tree | 44fb85c20ba355d5b1799ea50aa564725054e55b /Doc | |
parent | a44372fd0b143947b86926d9377f2b4c3a585dca (diff) | |
download | cpython-3492e39b447a8e76df9da1cc05bd1cdf504e74f1.zip cpython-3492e39b447a8e76df9da1cc05bd1cdf504e74f1.tar.gz cpython-3492e39b447a8e76df9da1cc05bd1cdf504e74f1.tar.bz2 |
Issue 19544 and Issue #7457: Restore the read_pkg_file method to distutils.dist.DistributionMetadata accidentally removed in the undo of distutils2.
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} |