|
| 1 | +:orphan: |
| 2 | + |
| 3 | +Appendix: Licensing Examples |
| 4 | +============================ |
| 5 | + |
| 6 | +Abstract |
| 7 | +-------- |
| 8 | + |
| 9 | +This document contains guidance on PEP 639 application in the |
| 10 | +real-life :ref:`examples <639-examples>`. |
| 11 | + |
| 12 | + |
| 13 | +.. _639-examples: |
| 14 | + |
| 15 | +Examples |
| 16 | +-------- |
| 17 | + |
| 18 | +.. _639-example-basic: |
| 19 | + |
| 20 | +Basic example |
| 21 | +''''''''''''' |
| 22 | + |
| 23 | +The Setuptools project itself, as of `version 59.1.1 <setuptools5911_>`__, |
| 24 | +does not use the ``License`` field in its own project source metadata. |
| 25 | +Further, it no longer explicitly specifies ``license_file``/``license_files`` |
| 26 | +as it did previously, since Setuptools relies on its own automatic |
| 27 | +inclusion of license-related files matching common patterns, |
| 28 | +such as the ``LICENSE`` file it uses. |
| 29 | + |
| 30 | +It includes the following license-related metadata in its ``setup.cfg``: |
| 31 | + |
| 32 | +.. code-block:: ini |
| 33 | +
|
| 34 | + [metadata] |
| 35 | + classifiers = |
| 36 | + License :: OSI Approved :: MIT License |
| 37 | +
|
| 38 | +The simplest migration to PEP 639 would consist of using this instead: |
| 39 | + |
| 40 | +.. code-block:: ini |
| 41 | +
|
| 42 | + [metadata] |
| 43 | + license_expression = MIT |
| 44 | +
|
| 45 | +Or, in the ``[project]`` table of ``pyproject.toml``: |
| 46 | + |
| 47 | +.. code-block:: toml |
| 48 | +
|
| 49 | + [project] |
| 50 | + license = "MIT" |
| 51 | +
|
| 52 | +The output core metadata for the distribution packages would then be: |
| 53 | + |
| 54 | +.. code-block:: email |
| 55 | +
|
| 56 | + License-Expression: MIT |
| 57 | + License-File: LICENSE |
| 58 | +
|
| 59 | +The ``LICENSE`` file would be stored at ``/setuptools-${VERSION}/LICENSE`` |
| 60 | +in the sdist and ``/setuptools-${VERSION}.dist-info/licenses/LICENSE`` |
| 61 | +in the wheel, and unpacked from there into the site directory (e.g. |
| 62 | +``site-packages``) on installation; ``/`` is the root of the respective archive |
| 63 | +and ``${VERSION}`` the version of the Setuptools release in the core metadata. |
| 64 | + |
| 65 | + |
| 66 | +.. _639-example-advanced: |
| 67 | + |
| 68 | +Advanced example |
| 69 | +'''''''''''''''' |
| 70 | + |
| 71 | +Suppose Setuptools were to include the licenses of the third-party projects |
| 72 | +that are vendored in the ``setuptools/_vendor/`` and ``pkg_resources/_vendor`` |
| 73 | +directories; specifically: |
| 74 | + |
| 75 | +.. code-block:: text |
| 76 | +
|
| 77 | + packaging==21.2 |
| 78 | + pyparsing==2.2.1 |
| 79 | + ordered-set==3.1.1 |
| 80 | + more_itertools==8.8.0 |
| 81 | +
|
| 82 | +The license expressions for these projects are: |
| 83 | + |
| 84 | +.. code-block:: text |
| 85 | +
|
| 86 | + packaging: Apache-2.0 OR BSD-2-Clause |
| 87 | + pyparsing: MIT |
| 88 | + ordered-set: MIT |
| 89 | + more_itertools: MIT |
| 90 | +
|
| 91 | +A comprehensive license expression covering both Setuptools |
| 92 | +proper and its vendored dependencies would contain these metadata, |
| 93 | +combining all the license expressions into one. Such an expression might be: |
| 94 | + |
| 95 | +.. code-block:: text |
| 96 | +
|
| 97 | + MIT AND (Apache-2.0 OR BSD-2-Clause) |
| 98 | +
|
| 99 | +In addition, per the requirements of the licenses, the relevant license files |
| 100 | +must be included in the package. Suppose the ``LICENSE`` file contains the text |
| 101 | +of the MIT license and the copyrights used by Setuptools, ``pyparsing``, |
| 102 | +``more_itertools`` and ``ordered-set``; and the ``LICENSE*`` files in the |
| 103 | +``setuptools/_vendor/packaging/`` directory contain the Apache 2.0 and |
| 104 | +2-clause BSD license text, and the Packaging copyright statement and |
| 105 | +`license choice notice <packaginglicense_>`__. |
| 106 | + |
| 107 | +Specifically, we assume the license files are located at the following |
| 108 | +paths in the project source tree (relative to the project root and |
| 109 | +``pyproject.toml``): |
| 110 | + |
| 111 | +.. code-block:: ini |
| 112 | +
|
| 113 | + LICENSE |
| 114 | + setuptools/_vendor/packaging/LICENSE |
| 115 | + setuptools/_vendor/packaging/LICENSE.APACHE |
| 116 | + setuptools/_vendor/packaging/LICENSE.BSD |
| 117 | +
|
| 118 | +Putting it all together, our ``setup.cfg`` would be: |
| 119 | + |
| 120 | +.. code-block:: ini |
| 121 | +
|
| 122 | + [metadata] |
| 123 | + license_expression = MIT AND (Apache-2.0 OR BSD-2-Clause) |
| 124 | + license_files = |
| 125 | + LICENSE |
| 126 | + setuptools/_vendor/packaging/LICENSE |
| 127 | + setuptools/_vendor/packaging/LICENSE.APACHE |
| 128 | + setuptools/_vendor/packaging/LICENSE.BSD |
| 129 | +
|
| 130 | +In the ``[project]`` table of ``pyproject.toml``, with license files |
| 131 | +specified explicitly via the ``paths`` subkey, this would look like: |
| 132 | + |
| 133 | +.. code-block:: toml |
| 134 | +
|
| 135 | + [project] |
| 136 | + license = "MIT AND (Apache-2.0 OR BSD-2-Clause)" |
| 137 | + license-files.paths = [ |
| 138 | + "LICENSE", |
| 139 | + "setuptools/_vendor/LICENSE", |
| 140 | + "setuptools/_vendor/LICENSE.APACHE", |
| 141 | + "setuptools/_vendor/LICENSE.BSD", |
| 142 | + ] |
| 143 | +
|
| 144 | +Or alternatively, matched via glob patterns, this could be: |
| 145 | + |
| 146 | +.. code-block:: toml |
| 147 | +
|
| 148 | + [project] |
| 149 | + license = "MIT AND (Apache-2.0 OR BSD-2-Clause)" |
| 150 | + license-files.globs = [ |
| 151 | + "LICENSE*", |
| 152 | + "setuptools/_vendor/LICENSE*", |
| 153 | + ] |
| 154 | +
|
| 155 | +With either approach, the output core metadata in the distribution |
| 156 | +would be: |
| 157 | + |
| 158 | +.. code-block:: email |
| 159 | +
|
| 160 | + License-Expression: MIT AND (Apache-2.0 OR BSD-2-Clause) |
| 161 | + License-File: LICENSE |
| 162 | + License-File: setuptools/_vendor/packaging/LICENSE |
| 163 | + License-File: setuptools/_vendor/packaging/LICENSE.APACHE |
| 164 | + License-File: setuptools/_vendor/packaging/LICENSE.BSD |
| 165 | +
|
| 166 | +In the resulting sdist, with ``/`` as the root of the archive and ``${VERSION}`` |
| 167 | +the version of the Setuptools release specified in the core metadata, |
| 168 | +the license files would be located at the paths: |
| 169 | + |
| 170 | +.. code-block:: shell |
| 171 | +
|
| 172 | + /setuptools-${VERSION}/LICENSE |
| 173 | + /setuptools-${VERSION}/setuptools/_vendor/packaging/LICENSE |
| 174 | + /setuptools-${VERSION}/setuptools/_vendor/packaging/LICENSE.APACHE |
| 175 | + /setuptools-${VERSION}/setuptools/_vendor/packaging/LICENSE.BSD |
| 176 | +
|
| 177 | +In the built wheel, with ``/`` being the root of the archive and |
| 178 | +``{version}`` as the previous, the license files would be stored at: |
| 179 | + |
| 180 | +.. code-block:: shell |
| 181 | +
|
| 182 | + /setuptools-${VERSION}.dist-info/licenses/LICENSE |
| 183 | + /setuptools-${VERSION}.dist-info/licenses/setuptools/_vendor/packaging/LICENSE |
| 184 | + /setuptools-${VERSION}.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.APACHE |
| 185 | + /setuptools-${VERSION}.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.BSD |
| 186 | +
|
| 187 | +Finally, in the installed project, with ``site-packages`` being the site dir |
| 188 | +and ``{version}`` as the previous, the license files would be installed to: |
| 189 | + |
| 190 | +.. code-block:: shell |
| 191 | +
|
| 192 | + site-packages/setuptools-${VERSION}.dist-info/licenses/LICENSE |
| 193 | + site-packages/setuptools-${VERSION}.dist-info/licenses/setuptools/_vendor/packaging/LICENSE |
| 194 | + site-packages/setuptools-${VERSION}.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.APACHE |
| 195 | + site-packages/setuptools-${VERSION}.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.BSD |
| 196 | +
|
| 197 | +
|
| 198 | +.. _639-example-expression: |
| 199 | + |
| 200 | +Expression examples |
| 201 | +''''''''''''''''''' |
| 202 | + |
| 203 | +Some additional examples of valid ``License-Expression`` values: |
| 204 | + |
| 205 | +.. code-block:: email |
| 206 | +
|
| 207 | + License-Expression: MIT |
| 208 | + License-Expression: BSD-3-Clause |
| 209 | + License-Expression: MIT AND (Apache-2.0 OR BSD-2-clause) |
| 210 | + License-Expression: MIT OR GPL-2.0-or-later OR (FSFUL AND BSD-2-Clause) |
| 211 | + License-Expression: GPL-3.0-only WITH Classpath-Exception-2.0 OR BSD-3-Clause |
| 212 | + License-Expression: LicenseRef-Public-Domain OR CC0-1.0 OR Unlicense |
| 213 | + License-Expression: LicenseRef-Proprietary |
| 214 | +
|
| 215 | +
|
| 216 | +.. _packaginglicense: https://github.com/pypa/packaging/blob/21.2/LICENSE |
| 217 | +.. _setuptools5911: https://github.com/pypa/setuptools/blob/v59.1.1/setup.cfg |
0 commit comments