[Distutils] [Python-Dev] accept the wheel PEPs 425, 426, 427

Daniel Holth dholth at gmail.com
Sun Oct 21 04:56:49 CEST 2012


I'm really happy with moving the troublesome Description: field to the
payload. Email Policy() is useful too.

http://hg.python.org/peps/rev/74868fe8ba17

Metadata 1.3 is a ...

+format with no maximum line length, followed by a blank line and an
+arbitrary payload.  It is parseable by the ``email`` module with an
+appropriate ``email.policy.Policy()``.

description is deprecated...

+Since Metadata 1.3 the recommended place for the description is in the
+payload section of the document, after the last header.  The description
+needs no special formatting when included in the payload.

includes a handy...

# Metadata 1.3 demo
from email.generator import Generator
from email import header
from email.parser import Parser
from email.policy import Compat32
from email.utils import _has_surrogates

class MetadataPolicy(Compat32):
    max_line_length = 0
    continuation_whitespace = '\t'

    def _sanitize_header(self, name, value):
        if not isinstance(value, str):
            return value
        if _has_surrogates(value):
            raise NotImplementedError()
        else:
            return value

    def _fold(self, name, value, sanitize):
        body = ((self.linesep+self.continuation_whitespace)
                .join(value.splitlines()))
        return ''.join((name, ': ', body, self.linesep))

if __name__ == "__main__":
    import sys
    import textwrap

    pkg_info = """\
Metadata-Version: 1.3
Name: package
Version: 0.1.0
Summary: A package.
Description: Description
    ===========


    A description of the package.

"""

    m = Parser(policy=MetadataPolicy()).parsestr(pkg_info)

    m['License'] = 'GPL'
    description = m['Description']
    description_lines = description.splitlines()
    m.set_payload(description_lines[0]
            + '\n'
            + textwrap.dedent('\n'.join(description_lines[1:]))
            + '\n')
    del m['Description']

    # Correct if sys.stdout.encoding == 'UTF-8':
    Generator(sys.stdout, maxheaderlen=0).flatten(m)


More information about the Distutils-SIG mailing list