Skip to content

Commit 33bc2a8

Browse files
committed
Add a dedicated specification page for name normalization
1 parent bb7b118 commit 33bc2a8

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

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

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)

0 commit comments

Comments
 (0)