python-peps/pep-0639/appendix-examples/index.html

271 lines
20 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>Appendix: Licensing Examples | peps.python.org</title>
<link rel="shortcut icon" href="../../_static/py.png">
<link rel="canonical" href="https://peps.python.org/pep-0639/appendix-examples/">
<link rel="stylesheet" href="../../_static/style.css" type="text/css">
<link rel="stylesheet" href="../../_static/mq.css" type="text/css">
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" media="(prefers-color-scheme: light)" id="pyg-light">
<link rel="stylesheet" href="../../_static/pygments_dark.css" type="text/css" media="(prefers-color-scheme: dark)" id="pyg-dark">
<link rel="alternate" type="application/rss+xml" title="Latest PEPs" href="https://peps.python.org/peps.rss">
<meta property="og:title" content='Appendix: Licensing Examples | peps.python.org'>
<meta property="og:description" content="This document contains guidance on PEP 639 application in the real-life examples.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://peps.python.org/pep-0639/appendix-examples/">
<meta property="og:site_name" content="Python Enhancement Proposals (PEPs)">
<meta property="og:image" content="https://peps.python.org/_static/og-image.png">
<meta property="og:image:alt" content="Python PEPs">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="description" content="This document contains guidance on PEP 639 application in the real-life examples.">
<meta name="theme-color" content="#3776ab">
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-sun-half" viewBox="0 0 24 24" pointer-events="all">
<title>Following system colour scheme</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="9"></circle>
<path d="M12 3v18m0-12l4.65-4.65M12 14.3l7.37-7.37M12 19.6l8.85-8.85"></path>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24" pointer-events="all">
<title>Selected dark colour scheme</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z"></path>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24" pointer-events="all">
<title>Selected light colour scheme</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
</svg>
<script>
document.documentElement.dataset.colour_scheme = localStorage.getItem("colour_scheme") || "auto"
</script>
<section id="pep-page-section">
<header>
<h1>Python Enhancement Proposals</h1>
<ul class="breadcrumbs">
<li><a href="https://www.python.org/" title="The Python Programming Language">Python</a> &raquo; </li>
<li><a href="../../pep-0000/">PEP Index</a> &raquo; </li>
<li>Appendix: Licensing Examples</li>
</ul>
<button id="colour-scheme-cycler" onClick="setColourScheme(nextColourScheme())">
<svg aria-hidden="true" class="colour-scheme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
<svg aria-hidden="true" class="colour-scheme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg aria-hidden="true" class="colour-scheme-icon-when-light"><use href="#svg-sun"></use></svg>
<span class="visually-hidden">Toggle light / dark / auto colour theme</span>
</button>
</header>
<article>
<section id="appendix-licensing-examples">
<h1>Appendix: Licensing Examples</h1>
<section id="abstract">
<h2>Abstract</h2>
<p>This document contains guidance on PEP 639 application in the
real-life <a class="reference internal" href="#examples"><span class="std std-ref">examples</span></a>.</p>
</section>
<section id="examples">
<span id="id1"></span><h2>Examples</h2>
<section id="basic-example">
<span id="example-basic"></span><h3>Basic example</h3>
<p>The Setuptools project itself, as of <a class="reference external" href="https://github.com/pypa/setuptools/blob/v59.1.1/setup.cfg">version 59.1.1</a>,
does not use the <code class="docutils literal notranslate"><span class="pre">License</span></code> field in its own project source metadata.
Further, it no longer explicitly specifies <code class="docutils literal notranslate"><span class="pre">license_file</span></code>/<code class="docutils literal notranslate"><span class="pre">license_files</span></code>
as it did previously, since Setuptools relies on its own automatic
inclusion of license-related files matching common patterns,
such as the <code class="docutils literal notranslate"><span class="pre">LICENSE</span></code> file it uses.</p>
<p>It includes the following license-related metadata in its <code class="docutils literal notranslate"><span class="pre">setup.cfg</span></code>:</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[metadata]</span>
<span class="na">classifiers</span><span class="w"> </span><span class="o">=</span>
<span class="w"> </span><span class="na">License</span><span class="w"> </span><span class="o">:</span><span class="s">: OSI Approved :: MIT License</span>
</pre></div>
</div>
<p>The simplest migration to PEP 639 would consist of using this instead:</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[metadata]</span>
<span class="na">license_expression</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">MIT</span>
</pre></div>
</div>
<p>Or, in the <code class="docutils literal notranslate"><span class="pre">[project]</span></code> table of <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code>:</p>
<div class="highlight-toml notranslate"><div class="highlight"><pre><span></span><span class="k">[project]</span>
<span class="n">license</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;MIT&quot;</span>
</pre></div>
</div>
<p>The output Core Metadata for the distribution packages would then be:</p>
<div class="highlight-email notranslate"><div class="highlight"><pre><span></span><span class="nt">License-Expression:</span><span class="w"> </span>MIT
<span class="nt">License-File:</span><span class="w"> </span>LICENSE
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">LICENSE</span></code> file would be stored at <code class="docutils literal notranslate"><span class="pre">/setuptools-${VERSION}/LICENSE</span></code>
in the sdist and <code class="docutils literal notranslate"><span class="pre">/setuptools-${VERSION}.dist-info/licenses/LICENSE</span></code>
in the wheel, and unpacked from there into the site directory (e.g.
<code class="docutils literal notranslate"><span class="pre">site-packages</span></code>) on installation; <code class="docutils literal notranslate"><span class="pre">/</span></code> is the root of the respective archive
and <code class="docutils literal notranslate"><span class="pre">${VERSION}</span></code> the version of the Setuptools release in the Core Metadata.</p>
</section>
<section id="advanced-example">
<span id="example-advanced"></span><h3>Advanced example</h3>
<p>Suppose Setuptools were to include the licenses of the third-party projects
that are vendored in the <code class="docutils literal notranslate"><span class="pre">setuptools/_vendor/</span></code> and <code class="docutils literal notranslate"><span class="pre">pkg_resources/_vendor</span></code>
directories; specifically:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>packaging==21.2
pyparsing==2.2.1
ordered-set==3.1.1
more_itertools==8.8.0
</pre></div>
</div>
<p>The license expressions for these projects are:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>packaging: Apache-2.0 OR BSD-2-Clause
pyparsing: MIT
ordered-set: MIT
more_itertools: MIT
</pre></div>
</div>
<p>A comprehensive license expression covering both Setuptools
proper and its vendored dependencies would contain these metadata,
combining all the license expressions into one. Such an expression might be:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>MIT AND (Apache-2.0 OR BSD-2-Clause)
</pre></div>
</div>
<p>In addition, per the requirements of the licenses, the relevant license files
must be included in the package. Suppose the <code class="docutils literal notranslate"><span class="pre">LICENSE</span></code> file contains the text
of the MIT license and the copyrights used by Setuptools, <code class="docutils literal notranslate"><span class="pre">pyparsing</span></code>,
<code class="docutils literal notranslate"><span class="pre">more_itertools</span></code> and <code class="docutils literal notranslate"><span class="pre">ordered-set</span></code>; and the <code class="docutils literal notranslate"><span class="pre">LICENSE*</span></code> files in the
<code class="docutils literal notranslate"><span class="pre">setuptools/_vendor/packaging/</span></code> directory contain the Apache 2.0 and
2-clause BSD license text, and the Packaging copyright statement and
<a class="reference external" href="https://github.com/pypa/packaging/blob/21.2/LICENSE">license choice notice</a>.</p>
<p>Specifically, we assume the license files are located at the following
paths in the project source tree (relative to the project root and
<code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code>):</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="na">LICENSE</span>
<span class="na">setuptools/_vendor/packaging/LICENSE</span>
<span class="na">setuptools/_vendor/packaging/LICENSE.APACHE</span>
<span class="na">setuptools/_vendor/packaging/LICENSE.BSD</span>
</pre></div>
</div>
<p>Putting it all together, our <code class="docutils literal notranslate"><span class="pre">setup.cfg</span></code> would be:</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[metadata]</span>
<span class="na">license_expression</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">MIT AND (Apache-2.0 OR BSD-2-Clause)</span>
<span class="na">license_files</span><span class="w"> </span><span class="o">=</span>
<span class="w"> </span><span class="na">LICENSE</span>
<span class="w"> </span><span class="na">setuptools/_vendor/packaging/LICENSE</span>
<span class="w"> </span><span class="na">setuptools/_vendor/packaging/LICENSE.APACHE</span>
<span class="w"> </span><span class="na">setuptools/_vendor/packaging/LICENSE.BSD</span>
</pre></div>
</div>
<p>In the <code class="docutils literal notranslate"><span class="pre">[project]</span></code> table of <code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code>, license files
can be specified via glob patterns:</p>
<div class="highlight-toml notranslate"><div class="highlight"><pre><span></span><span class="k">[project]</span>
<span class="n">license</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;MIT AND (Apache-2.0 OR BSD-2-Clause)&quot;</span>
<span class="n">license-files</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span>
<span class="w"> </span><span class="s2">&quot;LICENSE*&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="s2">&quot;setuptools/_vendor/LICENSE*&quot;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>Or alternatively, they can be specified explicitly (paths will be interpreted
as glob patterns):</p>
<div class="highlight-toml notranslate"><div class="highlight"><pre><span></span><span class="k">[project]</span>
<span class="n">license</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;MIT AND (Apache-2.0 OR BSD-2-Clause)&quot;</span>
<span class="n">license-files</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span>
<span class="w"> </span><span class="s2">&quot;LICENSE&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="s2">&quot;setuptools/_vendor/LICENSE&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="s2">&quot;setuptools/_vendor/LICENSE.APACHE&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="s2">&quot;setuptools/_vendor/LICENSE.BSD&quot;</span><span class="p">,</span>
<span class="p">]</span>
</pre></div>
</div>
<p>With either approach, the output Core Metadata in the distribution
would be:</p>
<div class="highlight-email notranslate"><div class="highlight"><pre><span></span><span class="nt">License-Expression:</span><span class="w"> </span>MIT<span class="w"> </span>AND<span class="w"> </span>(Apache-2.0<span class="w"> </span>OR<span class="w"> </span>BSD-2-Clause)
<span class="nt">License-File:</span><span class="w"> </span>LICENSE
<span class="nt">License-File:</span><span class="w"> </span>setuptools/_vendor/packaging/LICENSE
<span class="nt">License-File:</span><span class="w"> </span>setuptools/_vendor/packaging/<span class="nf">LICENSE.APACHE</span>
<span class="nt">License-File:</span><span class="w"> </span>setuptools/_vendor/packaging/<span class="nf">LICENSE.BSD</span>
</pre></div>
</div>
<p>In the resulting sdist, with <code class="docutils literal notranslate"><span class="pre">/</span></code> as the root of the archive and <code class="docutils literal notranslate"><span class="pre">${VERSION}</span></code>
the version of the Setuptools release specified in the Core Metadata,
the license files would be located at the paths:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>/LICENSE
/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>/setuptools/_vendor/packaging/LICENSE
/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>/setuptools/_vendor/packaging/LICENSE.APACHE
/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>/setuptools/_vendor/packaging/LICENSE.BSD
</pre></div>
</div>
<p>In the built wheel, with <code class="docutils literal notranslate"><span class="pre">/</span></code> being the root of the archive and
<code class="docutils literal notranslate"><span class="pre">${VERSION}</span></code> as the previous, the license files would be stored at:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/LICENSE
/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/setuptools/_vendor/packaging/LICENSE
/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.APACHE
/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.BSD
</pre></div>
</div>
<p>Finally, in the installed project, with <code class="docutils literal notranslate"><span class="pre">site-packages</span></code> being the site dir
and <code class="docutils literal notranslate"><span class="pre">${VERSION}</span></code> as the previous, the license files would be installed to:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>site-packages/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/LICENSE
site-packages/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/setuptools/_vendor/packaging/LICENSE
site-packages/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.APACHE
site-packages/setuptools-<span class="si">${</span><span class="nv">VERSION</span><span class="si">}</span>.dist-info/licenses/setuptools/_vendor/packaging/LICENSE.BSD
</pre></div>
</div>
</section>
<section id="expression-examples">
<span id="example-expression"></span><h3>Expression examples</h3>
<p>Some additional examples of valid <code class="docutils literal notranslate"><span class="pre">License-Expression</span></code> values:</p>
<div class="highlight-email notranslate"><div class="highlight"><pre><span></span><span class="nt">License-Expression:</span><span class="w"> </span>MIT
<span class="nt">License-Expression:</span><span class="w"> </span>BSD-3-Clause
<span class="nt">License-Expression:</span><span class="w"> </span>MIT<span class="w"> </span>AND<span class="w"> </span>(Apache-2.0<span class="w"> </span>OR<span class="w"> </span>BSD-2-clause)
<span class="nt">License-Expression:</span><span class="w"> </span>MIT<span class="w"> </span>OR<span class="w"> </span><span class="nf">GPL-2.0-or-later</span><span class="w"> </span>OR<span class="w"> </span>(FSFUL<span class="w"> </span>AND<span class="w"> </span>BSD-2-Clause)
<span class="nt">License-Expression:</span><span class="w"> </span><span class="nf">GPL-3.0-only</span><span class="w"> </span>WITH<span class="w"> </span>Classpath-Exception-2.0<span class="w"> </span>OR<span class="w"> </span>BSD-3-Clause
<span class="nt">License-Expression:</span><span class="w"> </span>LicenseRef-Public-Domain<span class="w"> </span>OR<span class="w"> </span>CC0-1.0<span class="w"> </span>OR<span class="w"> </span>Unlicense
<span class="nt">License-Expression:</span><span class="w"> </span>LicenseRef-Proprietary
<span class="nt">License-Expression:</span><span class="w"> </span>LicenseRef-Custom-License
</pre></div>
</div>
</section>
</section>
</section>
</article>
<nav id="pep-sidebar">
<h2>Contents</h2>
<ul>
<li><a class="reference internal" href="#examples">Examples</a><ul>
<li><a class="reference internal" href="#basic-example">Basic example</a></li>
<li><a class="reference internal" href="#advanced-example">Advanced example</a></li>
<li><a class="reference internal" href="#expression-examples">Expression examples</a></li>
</ul>
</li>
</ul>
<br>
<a id="source" href="https://github.com/python/peps/blob/main/peps/pep-0639/appendix-examples.rst">Page Source (GitHub)</a>
</nav>
</section>
<script src="../../_static/colour_scheme.js"></script>
<script src="../../_static/wrap_tables.js"></script>
<script src="../../_static/sticky_banner.js"></script>
</body>
</html>