Skip to content

Commit d8643aa

Browse files
authored
Merge pull request #1070 from brettcannon/pep-685
Add changes introduced by PEP 685
2 parents e59950e + cab5cfd commit d8643aa

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

source/specifications/core-metadata.rst

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Metadata-Version
4545

4646
.. versionadded:: 1.0
4747

48-
Version of the file format; legal values are "1.0", "1.1", "1.2", "2.1"
49-
and "2.2".
48+
Version of the file format; legal values are "1.0", "1.1", "1.2", "2.1",
49+
"2.2", and "2.3".
5050

5151
Automated tools consuming metadata SHOULD warn if ``metadata_version`` is
5252
greater than the highest version they support, and MUST fail if
@@ -60,7 +60,7 @@ all of the needed fields.
6060

6161
Example::
6262

63-
Metadata-Version: 2.2
63+
Metadata-Version: 2.3
6464

6565

6666
.. _core-metadata-name:
@@ -84,6 +84,12 @@ Example::
8484

8585
Name: BeagleVote
8686

87+
To normalize a distribution name for comparison purposes, it should be
88+
lowercased with all runs of the characters ``.``, ``-``, or ``_`` replaced with
89+
a single ``-`` character. This can be done using the following snippet of code
90+
(as specified in :pep:`503`)::
91+
92+
re.sub(r"[-_.]+", "-", name).lower()
8793

8894
.. _core-metadata-version:
8995

@@ -510,7 +516,8 @@ The format of a requirement string contains from one to four parts:
510516
The only mandatory part.
511517
* A comma-separated list of 'extra' names. These are defined by
512518
the required project, referring to specific features which may
513-
need extra dependencies.
519+
need extra dependencies. The names MUST conform to the restrictions
520+
specified by the ``Provides-Extra:`` field.
514521
* A version specifier. Tools parsing the format should accept optional
515522
parentheses around this, but tools generating it should not use
516523
parentheses.
@@ -613,9 +620,20 @@ Provides-Extra (multiple use)
613620
=============================
614621

615622
.. versionadded:: 2.1
623+
.. versionchanged:: 2.3
624+
:pep:`685` restricted valid values to be unambiguous (i.e. no normalization
625+
required). For older metadata versions, value restrictions were brought into
626+
line with ``Name:`` and normalization rules were introduced.
627+
628+
A string containing the name of an optional feature. A valid name consists only
629+
of lowercase ASCII letters, ASCII numbers, and hyphen. It must start and end
630+
with a letter or number. Hyphens cannot be followed by another hyphen. Names are
631+
limited to those which match the following regex (which guarantees unambiguity)::
632+
633+
^([a-z0-9]|[a-z0-9]([a-z0-9-](?!-))*[a-z0-9])$
616634

617-
A string containing the name of an optional feature. Must be a valid Python
618-
identifier. May be used to make a dependency conditional on whether the
635+
636+
The specified name may be used to make a dependency conditional on whether the
619637
optional feature has been requested.
620638

621639
Example::
@@ -640,6 +658,17 @@ respectively.
640658
It is legal to specify ``Provides-Extra:`` without referencing it in any
641659
``Requires-Dist:``.
642660

661+
When writing data for older metadata versions, names MUST be normalized
662+
following the same rules used for the ``Name:`` field when performing
663+
comparisons. Tools writing metadata MUST raise an error if two
664+
``Provides-Extra:`` entries would clash after being normalized.
665+
666+
When reading data for older metadata versions, tools SHOULD warn when values
667+
for this field would be invalid under newer metadata versions. If a value would
668+
be invalid following the rules for ``Name:`` in any core metadata version, the
669+
user SHOULD be warned and the value ignored to avoid ambiguity. Tools MAY choose
670+
to raise an error when reading an invalid name for older metadata versions.
671+
643672

644673
Rarely Used Fields
645674
==================

source/specifications/dependency-specifiers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ component is defined in :pep:`508`.
1010

1111
The environment markers section in this PEP supersedes the environment markers
1212
section in :pep:`345`.
13+
14+
Restrictions on names for extras is defined in :pep:`685`.

source/specifications/entry-points.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ Within a value, readers must accept and ignore spaces (including multiple
105105
consecutive spaces) before or after the colon, between the object reference and
106106
the left square bracket, between the extra names and the square brackets and
107107
colons delimiting them, and after the right square bracket. The syntax for
108-
extras is formally specified as part of :pep:`508` (as ``extras``).
108+
extras is formally specified as part of :pep:`508` (as ``extras``) and
109+
restrictions on values specified in :pep:`685`.
109110
For tools writing the file, it is recommended only to insert a space between the
110111
object reference and the left square bracket.
111112

0 commit comments

Comments
 (0)