cpython: e19441e540ca (original) (raw)

Mercurial > cpython

changeset 87042:e19441e540ca 3.3

Issue 19544 and Issue #7457: Restore the read_pkg_file method to distutils.dist.DistributionMetadata accidentally removed in the undo of distutils2. [#7457]

Jason R. Coombs jaraco@jaraco.com
date Sun, 10 Nov 2013 18:15:03 -0500
parents 79b8b7c5fe8a
children 28059d8b395b 5e98c4e9c909
files Doc/distutils/examples.rst Lib/distutils/dist.py Lib/distutils/tests/test_dist.py Misc/NEWS
diffstat 4 files changed, 147 insertions(+), 18 deletions(-)[+] [-] Doc/distutils/examples.rst 42 Lib/distutils/dist.py 90 Lib/distutils/tests/test_dist.py 29 Misc/NEWS 4

line wrap: on

line diff

--- 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:: +

+ +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:: +

+ +Notice that the class can also be instanciated with a metadata file path to +loads its values:: +

+ + .. % \section{Multiple extension modules} .. % \label{multiple-ext}

--- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -5,6 +5,7 @@ being built/installed/distributed. """ import sys, os, re +from email import message_from_file try: import warnings @@ -999,25 +1000,80 @@ class DistributionMetadata: "provides", "requires", "obsoletes", )

+

+

+

+

+

+

+

+

+

def write_pkg_info(self, base_dir): """Write the PKG-INFO file into the release tree.

--- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -8,7 +8,7 @@ import textwrap from unittest import mock -from distutils.dist import Distribution, fix_help_options +from distutils.dist import Distribution, fix_help_options, DistributionMetadata from distutils.cmd import Command from test.support import TESTFN, captured_stdout, run_unittest @@ -388,6 +388,33 @@ class MetadataTestCase(support.TempdirMa self.assertTrue(output)

+

+

+

+ def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(DistributionTestCase))

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,10 @@ Core and Builtins Library ------- +- Issue #19544 and Issue #7457: Restore the read_pkg_file method to