Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import the part of PEP 566 about transforming core metadata to JSON #1466

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions source/specifications/core-metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ definition, the practical standard is set by what the standard library
Whenever metadata is serialised to a byte stream (for example, to save
to a file), strings must be serialised using the UTF-8 encoding.

Although :pep:`566` defined a way to transform metadata into a JSON-compatible
dictionary, this is not yet used as a standard interchange format. The need for
tools to work with years worth of existing packages makes it difficult to shift
to a new format.

.. note:: *Interpreting old metadata:* In :pep:`566`, the version specifier
field format specification was relaxed to accept the syntax used by popular
publishing tools (namely to remove the requirement that version specifiers
Expand Down Expand Up @@ -848,6 +843,27 @@ Example::
Obsoletes: Gorgon


Transforming core metadata to JSON
==================================

It may be necessary to store metadata in a data structure which does not allow
for multiple repeated keys, such as JSON. This specification defines a way to
transform metadata into a JSON-compatible dictionary [#json-not-interchange]_.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply stating the process seems a little sudden. Perhaps add the introduction from the PEP:

The canonical method to transform metadata fields into such a data structure is as follows:

#. The original key-value format should be read with
``email.parser.HeaderParser``.
#. All transformed keys should be reduced to lower case. Hyphens should be
replaced with underscores, but otherwise should retain all other characters.
#. The transformed value for any field marked with "(multiple use)" should be a
single list containing all the original values for the given key.
#. The ``Keywords`` field should be converted to a list by splitting the
original value on commas.
#. The message body, if present, should be set to the value of the
``description`` key.
#. The result should be stored as a string-keyed dictionary.



----

.. [1] reStructuredText markup:
Expand All @@ -857,3 +873,7 @@ Example::

.. [2] RFC 822 Long Header Fields:
:rfc:`822#section-3.1.1`

.. [#json-not-interchange] This is not yet used as a standard interchange
format; the need for tools to work with years worth of existing packages
makes it difficult to shift to a new format.
Comment on lines +877 to +879
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be a warning note rather than a footnote.