Skip to content

Commit

Permalink
Merge pull request #1463 from jeanas/valid-names
Browse files Browse the repository at this point in the history
Deduplicate specification of valid package names
  • Loading branch information
webknjaz committed Dec 31, 2023
2 parents 9cd20c6 + 1ca542e commit 045d09a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
10 changes: 3 additions & 7 deletions source/specifications/core-metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ Name

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

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:`name format specification
<name-format>`.

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:
=======================
Names and normalization
=======================

This specification defines the format that names for packages and extras are
required to follow. It also describes how to normalize them, which should be
done before lookups and comparisons.

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

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

Valid non-normalized names
--------------------------
Name format
===========

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 045d09a

Please sign in to comment.