Skip to content

Commit c09018a

Browse files
authored
Merge pull request #1190 from pradyunsg/name-normalization
2 parents 049f06a + ed22b7d commit c09018a

7 files changed

Lines changed: 45 additions & 12 deletions

source/guides/hosting-your-own-index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ all repositories using a valid HTTPS setup.
3535
===================
3636

3737
The directory layout is fairly simple, within a root directory you need to
38-
create a directory for each project. This directory should be the normalized
39-
name (as defined by :pep:`503`) of the project. Within each of these directories
38+
create a directory for each project. This directory should be the :ref:`normalized name <name-normalization>` of the project. Within each of these directories
4039
simply place each of the downloadable files. If you have the projects "Foo"
4140
(with the versions 1.0 and 2.0) and "bar" (with the version 0.1) You should
4241
end up with a structure that looks like::

source/specifications/binary-distribution-format.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ this character cannot appear within any component. This is handled as follows:
161161
- In distribution names, any run of ``-_.`` characters (HYPHEN-MINUS, LOW LINE
162162
and FULL STOP) should be replaced with ``_`` (LOW LINE), and uppercase
163163
characters should be replaced with corresponding lowercase ones. This is
164-
equivalent to :pep:`503` normalisation followed by replacing ``-`` with ``_``.
164+
equivalent to regular :ref:`name normalization <name-normalization>` followed by replacing ``-`` with ``_``.
165165
Tools consuming wheels must be prepared to accept ``.`` (FULL STOP) and
166166
uppercase letters, however, as these were allowed by an earlier version of
167167
this specification.

source/specifications/core-metadata.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,7 @@ 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()
93-
87+
For comparison purposes, the names should be :ref:`normalized <name-normalization>` before comparing.
9488

9589
.. _core-metadata-version:
9690

source/specifications/declaring-project-metadata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The complete list of keys allowed in the ``[project]`` table are:
7070

7171
The name of the project.
7272

73-
Tools SHOULD normalize this name, as specified by :pep:`503`, as soon
73+
Tools SHOULD :ref:`normalize <name-normalization>` this name, as soon
7474
as it is read for internal consistency.
7575

7676
.. code-block:: toml

source/specifications/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Package Distribution Metadata
1515
.. toctree::
1616
:maxdepth: 1
1717

18+
name-normalization
1819
core-metadata
1920
version-specifiers
2021
dependency-specifiers
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. _name-normalization:
2+
3+
==========================
4+
Package name normalization
5+
==========================
6+
7+
Project names are "normalized" for use in various contexts. This document describes how project names should be normalized.
8+
9+
Valid non-normalized names
10+
--------------------------
11+
12+
A valid name consists only of ASCII letters and numbers, period,
13+
underscore and hyphen. It must start and end with a letter or number.
14+
This means that valid project names are limited to those which match the
15+
following regex (run with ``re.IGNORECASE``)::
16+
17+
^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$
18+
19+
Normalization
20+
-------------
21+
22+
The name should be lowercased with all runs of the characters ``.``, ``-``, or ``_`` replaced with a single ``-`` character. This can be implemented in Python with the re module:
23+
24+
.. code-block:: python
25+
26+
import re
27+
28+
def normalize(name):
29+
return re.sub(r"[-_.]+", "-", name).lower()
30+
31+
This means that the following names are all equivalent:
32+
33+
* ``friendly-bard`` (normalized form)
34+
* ``Friendly-Bard``
35+
* ``FRIENDLY-BARD``
36+
* ``friendly.bard``
37+
* ``friendly_bard``
38+
* ``friendly--bard``
39+
* ``FrIeNdLy-._.-bArD`` (a _terrible_ way to write a name, but it is valid)

source/specifications/recording-installed-packages.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ packages (commonly, the ``site-packages`` directory).
4040

4141
This directory is named as ``{name}-{version}.dist-info``, with ``name`` and
4242
``version`` fields corresponding to :ref:`core-metadata`. Both fields must be
43-
normalized (see :pep:`PEP 503 <503#normalized-names>` and
43+
normalized (see :ref:`name-normalization` and
4444
:pep:`PEP 440 <440#normalization>` for the definition of normalization for
4545
each field respectively), and replace dash (``-``) characters with
4646
underscore (``_``) characters, so the ``.dist-info`` directory always has

0 commit comments

Comments
 (0)