|
| 1 | +.. _`well-known-project-urls`: |
| 2 | + |
| 3 | +=================================== |
| 4 | +Well-known Project URLs in Metadata |
| 5 | +=================================== |
| 6 | + |
| 7 | +.. important:: |
| 8 | + |
| 9 | + This document is primarily of interest to metadata *consumers*, |
| 10 | + who should use the normalization rules and well-known list below |
| 11 | + to make their presentation of project URLs consistent across the |
| 12 | + Python ecosystem. |
| 13 | + |
| 14 | + Metadata *producers* (such as build tools and individual package |
| 15 | + maintainers) may continue to use any labels they please, within the |
| 16 | + overall ``Project-URL`` length restrictions. However, when possible, users are |
| 17 | + *encouraged* to pick meaningful labels that normalize to well-known |
| 18 | + labels. |
| 19 | + |
| 20 | +.. note:: |
| 21 | + |
| 22 | + See :ref:`Writing your pyproject.toml - urls <writing-pyproject-toml-urls>` |
| 23 | + for user-oriented guidance on choosing project URL labels in your package's |
| 24 | + metadata. |
| 25 | + |
| 26 | +.. note:: This specification was originally defined in :pep:`753`. |
| 27 | + |
| 28 | +:pep:`753` deprecates the :ref:`core-metadata-home-page` and |
| 29 | +:ref:`core-metadata-download-url` metadata fields in favor of |
| 30 | +:ref:`core-metadata-project-url`, and defines a normalization and |
| 31 | +lookup procedure for determining whether a ``Project-URL`` is |
| 32 | +"well-known," i.e. has the semantics assigned to ``Home-page``, |
| 33 | +``Download-URL``, or other common project URLs. |
| 34 | + |
| 35 | +This allows indices (such as the Python Package Index) and other downstream |
| 36 | +metadata consumers to present project URLs in a |
| 37 | +consistent manner. |
| 38 | + |
| 39 | +.. _project-url-label-normalization: |
| 40 | + |
| 41 | +Label normalization |
| 42 | +=================== |
| 43 | + |
| 44 | +.. note:: |
| 45 | + |
| 46 | + Label normalization is performed by metadata *consumers*, not metadata |
| 47 | + producers. |
| 48 | + |
| 49 | +To determine whether a ``Project-URL`` label is "well-known," metadata |
| 50 | +consumers should normalize the label before comparing it to the |
| 51 | +:ref:`list of well-known labels <well-known-labels>`. |
| 52 | + |
| 53 | +The normalization procedure for ``Project-URL`` labels is defined |
| 54 | +by the following Python function: |
| 55 | + |
| 56 | +.. code-block:: python |
| 57 | +
|
| 58 | + import string |
| 59 | +
|
| 60 | + def normalize_label(label: str) -> str: |
| 61 | + chars_to_remove = string.punctuation + string.whitespace |
| 62 | + removal_map = str.maketrans("", "", chars_to_remove) |
| 63 | + return label.translate(removal_map).lower() |
| 64 | +
|
| 65 | +In plain language: a label is *normalized* by deleting all ASCII punctuation |
| 66 | +and whitespace, and then converting the result to lowercase. |
| 67 | + |
| 68 | +The following table shows examples of labels before (raw) and after |
| 69 | +normalization: |
| 70 | + |
| 71 | +.. list-table:: |
| 72 | + :header-rows: 1 |
| 73 | + |
| 74 | + * - Raw |
| 75 | + - Normalized |
| 76 | + * - ``Homepage`` |
| 77 | + - ``homepage`` |
| 78 | + * - ``Home-page`` |
| 79 | + - ``homepage`` |
| 80 | + * - ``Home page`` |
| 81 | + - ``homepage`` |
| 82 | + * - ``Change_Log`` |
| 83 | + - ``changelog`` |
| 84 | + * - ``What's New?`` |
| 85 | + - ``whatsnew`` |
| 86 | + * - ``github`` |
| 87 | + - ``github`` |
| 88 | + |
| 89 | +.. _well-known-labels: |
| 90 | + |
| 91 | +Well-known labels |
| 92 | +================= |
| 93 | + |
| 94 | +.. note:: |
| 95 | + |
| 96 | + The list of well-known labels is a living standard, maintained as part of |
| 97 | + this document. |
| 98 | + |
| 99 | +The following table lists labels that are well-known for the purpose of |
| 100 | +specializing the presentation of ``Project-URL`` metadata: |
| 101 | + |
| 102 | +.. list-table:: |
| 103 | + :header-rows: 1 |
| 104 | + |
| 105 | + * - Label (Human-readable equivalent) |
| 106 | + - Description |
| 107 | + - Aliases |
| 108 | + * - ``homepage`` (Homepage) |
| 109 | + - The project's home page |
| 110 | + - *(none)* |
| 111 | + * - ``source`` (Source Code) |
| 112 | + - The project's hosted source code or repository |
| 113 | + - ``repository``, ``sourcecode``, ``github`` |
| 114 | + * - ``download`` (Download) |
| 115 | + - A download URL for the current distribution, equivalent to ``Download-URL`` |
| 116 | + - *(none)* |
| 117 | + * - ``changelog`` (Changelog) |
| 118 | + - The project's comprehensive changelog |
| 119 | + - ``changes``, ``whatsnew``, ``history`` |
| 120 | + * - ``releasenotes`` (Release Notes) |
| 121 | + - The project's curated release notes |
| 122 | + - *(none)* |
| 123 | + * - ``documentation`` (Documentation) |
| 124 | + - The project's online documentation |
| 125 | + - ``docs`` |
| 126 | + * - ``issues`` (Issue Tracker) |
| 127 | + - The project's bug tracker |
| 128 | + - ``bugs``, ``issue``, ``tracker``, ``issuetracker``, ``bugtracker`` |
| 129 | + * - ``funding`` (Funding) |
| 130 | + - Funding Information |
| 131 | + - ``sponsor``, ``donate``, ``donation`` |
| 132 | + |
| 133 | +Package metadata consumers may choose to render aliased labels the same as |
| 134 | +their "parent" well known label, or further specialize them. |
| 135 | + |
| 136 | +Example behavior |
| 137 | +================ |
| 138 | + |
| 139 | +The following shows the flow of project URL metadata from |
| 140 | +``pyproject.toml`` to core metadata to a potential index presentation: |
| 141 | + |
| 142 | +.. code-block:: toml |
| 143 | + :caption: Example project URLs in standard configuration |
| 144 | +
|
| 145 | + [project.urls] |
| 146 | + "Home Page" = "https://example.com" |
| 147 | + DOCUMENTATION = "https://readthedocs.org" |
| 148 | + Repository = "https://upstream.example.com/me/spam.git" |
| 149 | + GitHub = "https://github.com/example/spam" |
| 150 | +
|
| 151 | +.. code-block:: email |
| 152 | + :caption: Core metadata representation |
| 153 | +
|
| 154 | + Project-URL: Home page, https://example.com |
| 155 | + Project-URL: DOCUMENTATION, https://readthedocs.org |
| 156 | + Project-URL: Repository, https://upstream.example.com/me/spam.git |
| 157 | + Project-URL: GitHub, https://github.com/example/spam |
| 158 | +
|
| 159 | +.. code-block:: text |
| 160 | + :caption: Potential rendering |
| 161 | +
|
| 162 | + Homepage: https://example.com |
| 163 | + Documentation: https://readthedocs.org |
| 164 | + Source Code: https://upstream.example.com/me/spam.git |
| 165 | + Source Code (GitHub): https://github.com/example/spam |
| 166 | +
|
| 167 | +Observe that the core metadata appears in the form provided by the user |
| 168 | +(since metadata *producers* do not perform normalization), but the |
| 169 | +metadata *consumer* normalizes and identifies appropriate |
| 170 | +human-readable equivalents based on the normalized form: |
| 171 | + |
| 172 | +* ``Home page`` becomes ``homepage``, which is rendered as ``Homepage`` |
| 173 | +* ``DOCUMENTATION`` becomes ``documentation``, which is rendered as ``Documentation`` |
| 174 | +* ``Repository`` becomes ``repository``, which is rendered as ``Source Code`` |
| 175 | +* ``GitHub`` becomes ``github``, which is rendered as ``Source Code (GitHub)`` |
| 176 | + (as a specialization of ``Source Code``) |
0 commit comments