Skip to content

Commit

Permalink
PEP 685: address more feedback (python#2418)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon committed Mar 11, 2022
1 parent 7a514d3 commit 35c3f89
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions pep-0685.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ Rationale
This collapses any run of the substitution character down to a single
character,
e.g. ``---`` gets collapsed down to ``-``.
This does not produce a valid Python identifier as specified by the
core metadata 2.2 specification for extra names.
This does **not** produce a valid Python identifier as specified by
the core metadata 2.2 specification for extra names.

`Setuptools 60 does normalization <https://github.com/pypa/setuptools/blob/b2f7b8f92725c63b164d5776f85e67cc560def4e/pkg_resources/__init__.py#L1324-L1330>`__
via::

re.sub('[^A-Za-z0-9.-]+', '_', name).lower()
re.sub(r'[^A-Za-z0-9-.]+', '_', name).lower()

The use of an underscore/``_`` differs from PEP 503's use of a
hyphen/``-``.
Runs of ``_``, unlike PEP 503, do **not** get collapsed,
e.g. ``___`` stays the same.
Runs of ``.`` and ``-``, unlike PEP 503, do **not** get collapsed,
e.g. ``..`` stays the same.

For pip 22, its
"extra normalisation behaviour is quite convoluted and erratic" [pip-erratic]_,
Expand All @@ -80,10 +80,9 @@ using the semantics outlined in `PEP 503 for names <https://peps.python.org/pep-

The `core metadata`_ specification will be updated such that the allowed
names for `Provides-Extra`_ matches what :pep:`508` specifies for names.
As this is a superset of what is currently allowed by the core metadata 2.2
specification,
it allows for a *loosening* of the naming requirements.
It will also bring extra naming in line with that of the Name_ field.
This will bring extra naming in line with that of the Name_ field.
Because this changes what is considered valid, it will lead to a core
metadata version increase to ``2.3``.

For tools writing `core metadata`_,
they MUST write out extra names in their normalized form.
Expand All @@ -92,7 +91,15 @@ when used in the `Requires-Dist`_ field.

Tools generating metadata MUST raise an error if a user specified
two or more extra names which would normalize to the same name.
Tools SHOULD warn users when an invalid extra name is read.
Tools generating metadata MUST raise an error if an invalid extra
name is provided as appropriate for the specified core metadata version.
If an older core metadata version is specified and the name would be
invalid with newer core metadata versions,
tools SHOULD warn the user.
Tools SHOULD warn users when an invalid extra name is read and not use
the name to avoid ambiguity.
Tools MAY raise an error instead of a warning when reading an
invalid name if they so desire.


Backwards Compatibility
Expand Down Expand Up @@ -152,12 +159,14 @@ it will also implement this PEP.
Rejected Ideas
==============

Normalize names according to PEP 503
------------------------------------
Using setuptools 60's normalization
-----------------------------------

For backwards-compatibility concerns,
it was decided not to strictly follow how :pep:`503` normalizes
distribution names.
Initially this PEP proposed following setuptools to try and minimize
backwards-compatibility issues.
But after checking various wheels on PyPI,
it became clear that standardizing **all** naming on :pep:`508` and
:pep:`503` semantics was easier and better long-term.


Open Issues
Expand Down

0 comments on commit 35c3f89

Please sign in to comment.