Skip to content

Commit

Permalink
Deduplicate specification of valid package names
Browse files Browse the repository at this point in the history
- Rename the "Package name normalization" specification into "Package
  name grammar and normalization", to make it explicitly about the
  format of valid names too.

- Link to this spec in the core metadata specification instead of
  duplicating the part about valid names.
  • Loading branch information
jeanas committed Dec 22, 2023
1 parent 83fc010 commit 3a90a88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
9 changes: 2 additions & 7 deletions source/specifications/core-metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,10 @@ Name

.. versionadded:: 1.0
.. versionchanged:: 2.1
Added additional restrictions on format from :pep:`508`
Added restrictions on format from the :ref:`name grammar <name-grammar>`.

The name of the distribution. The name field is the primary identifier for a
distribution. A valid name consists only of ASCII letters and numbers, period,
underscore and hyphen. It must start and end with a letter or number.
Distribution names are limited to those which match the following
regex (run with ``re.IGNORECASE``)::

^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$
distribution. It must conform to the :ref:`package name grammar <name-grammar>`.

Example::

Expand Down
30 changes: 19 additions & 11 deletions source/specifications/name-normalization.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
.. _name-normalization:
======================================
Package name grammar and normalization
======================================

Project names obey a restricted format, and are "normalized" for use in various
contexts. This document describes what the valid project names are, and how
project names should be normalized.

==========================
Package name normalization
==========================

Project names are "normalized" for use in various contexts. This document describes how project names should be normalized.
.. _name-grammar:

Valid non-normalized names
--------------------------
Name grammar
============

A valid name consists only of ASCII letters and numbers, period,
underscore and hyphen. It must start and end with a letter or number.
Expand All @@ -16,10 +19,15 @@ following regex (run with ``re.IGNORECASE``)::

^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$

Normalization
-------------

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:
.. _name-normalization:

Name normalization
==================

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:

.. code-block:: python
Expand All @@ -30,7 +38,7 @@ The name should be lowercased with all runs of the characters ``.``, ``-``, or `
This means that the following names are all equivalent:

* ``friendly-bard`` (normalized form)
* ``friendly-bard`` (normalized form)
* ``Friendly-Bard``
* ``FRIENDLY-BARD``
* ``friendly.bard``
Expand Down

0 comments on commit 3a90a88

Please sign in to comment.