Skip to content

Commit 742e281

Browse files
authored
Merge pull request #1815 from befeleme/document-legacy
Document the legacy way of declaring pyproject.toml
2 parents a75bd7f + faf4c7d commit 742e281

File tree

3 files changed

+92
-23
lines changed

3 files changed

+92
-23
lines changed

source/guides/licensing-examples-and-user-scenarios.rst

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Licensing examples and user scenarios
1010
license files and other legally required information.
1111
This document aims to provide clear guidance how to migrate from the legacy
1212
to the standardized way of declaring licenses.
13+
Make sure your preferred build backend supports :pep:`639` before
14+
trying to apply the newer guidelines.
15+
As of February 2025, :doc:`setuptools <setuptools:userguide/pyproject_config>`
16+
and :ref:`flit <flit:pyproject_toml_project>` don't support :pep:`639` yet.
1317

1418

1519
Licensing Examples

source/guides/writing-pyproject-toml.rst

+40-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ You can also specify the format explicitly, like this:
325325
``license``
326326
-----------
327327

328+
:pep:`639` (accepted in August 2024) has changed the way the ``license`` field
329+
is declared. Make sure your preferred build backend supports :pep:`639` before
330+
trying to apply the newer guidelines.
331+
As of February 2025, :doc:`setuptools <setuptools:userguide/pyproject_config>`
332+
and :ref:`flit <flit:pyproject_toml_project>` don't support :pep:`639` yet.
333+
334+
:pep:`639` license declaration
335+
''''''''''''''''''''''''''''''
336+
328337
This is a valid :term:`SPDX license expression <License Expression>` consisting
329338
of one or more :term:`license identifiers <License Identifier>`.
330339
The full license list is available at the
@@ -352,10 +361,40 @@ The custom identifiers must follow the SPDX specification,
352361
[project]
353362
license = "LicenseRef-My-Custom-License"
354363
364+
Legacy license declaration
365+
''''''''''''''''''''''''''
366+
367+
This can take two forms. You can put your license in a file, typically
368+
:file:`LICENSE` or :file:`LICENSE.txt`, and link that file here:
369+
370+
.. code-block:: toml
371+
372+
[project]
373+
license = {file = "LICENSE"}
374+
375+
or you can write the name of the license:
376+
377+
.. code-block:: toml
378+
379+
[project]
380+
license = {text = "MIT License"}
381+
382+
If you are using a standard, well-known license, it is not necessary to use this
383+
field. Instead, you should use one of the :ref:`classifiers` starting with ``License
384+
::``. (As a general rule, it is a good idea to use a standard, well-known
385+
license, both to avoid confusion and because some organizations avoid software
386+
whose license is unapproved.)
387+
355388

356389
``license-files``
357390
-----------------
358391

392+
:pep:`639` (accepted in August 2024) has introduced the ``license-files`` field.
393+
Make sure your preferred build backend supports :pep:`639` before declaring the
394+
field.
395+
As of February 2025, :doc:`setuptools <setuptools:userguide/pyproject_config>`
396+
and :ref:`flit <flit:pyproject_toml_project>` don't support :pep:`639` yet.
397+
359398
This is a list of license files and files containing other legal
360399
information you want to distribute with your package.
361400

@@ -529,7 +568,7 @@ A full example
529568
]
530569
description = "Lovely Spam! Wonderful Spam!"
531570
readme = "README.rst"
532-
license = "MIT"
571+
license = "MIT" # or license = {file = "LICENSE.txt"} for legacy declaration
533572
license-files = ["LICEN[CS]E.*"]
534573
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
535574
classifiers = [

source/tutorials/packaging-projects.rst

+48-22
Original file line numberDiff line numberDiff line change
@@ -200,27 +200,52 @@ to include your username; this ensures that you have a unique
200200
package name that doesn't conflict with packages uploaded by other people
201201
following this tutorial.
202202

203-
.. code-block:: toml
204-
205-
[project]
206-
name = "example_package_YOUR_USERNAME_HERE"
207-
version = "0.0.1"
208-
authors = [
209-
{ name="Example Author", email="[email protected]" },
210-
]
211-
description = "A small example package"
212-
readme = "README.md"
213-
requires-python = ">=3.8"
214-
classifiers = [
215-
"Programming Language :: Python :: 3",
216-
"Operating System :: OS Independent",
217-
]
218-
license = "MIT"
219-
license-files = ["LICEN[CS]E*"]
220-
221-
[project.urls]
222-
Homepage = "https://github.com/pypa/sampleproject"
223-
Issues = "https://github.com/pypa/sampleproject/issues"
203+
.. tab:: hatchling/pdm
204+
205+
.. code-block:: toml
206+
207+
[project]
208+
name = "example_package_YOUR_USERNAME_HERE"
209+
version = "0.0.1"
210+
authors = [
211+
{ name="Example Author", email="[email protected]" },
212+
]
213+
description = "A small example package"
214+
readme = "README.md"
215+
requires-python = ">=3.8"
216+
classifiers = [
217+
"Programming Language :: Python :: 3",
218+
"Operating System :: OS Independent",
219+
]
220+
license = "MIT"
221+
license-files = ["LICEN[CS]E*"]
222+
223+
[project.urls]
224+
Homepage = "https://github.com/pypa/sampleproject"
225+
Issues = "https://github.com/pypa/sampleproject/issues"
226+
227+
.. tab:: setuptools/flit
228+
229+
.. code-block:: toml
230+
231+
[project]
232+
name = "example_package_YOUR_USERNAME_HERE"
233+
version = "0.0.1"
234+
authors = [
235+
{ name="Example Author", email="[email protected]" },
236+
]
237+
description = "A small example package"
238+
readme = "README.md"
239+
requires-python = ">=3.8"
240+
classifiers = [
241+
"Programming Language :: Python :: 3",
242+
"Operating System :: OS Independent",
243+
"License :: OSI Approved :: MIT License",
244+
]
245+
246+
[project.urls]
247+
Homepage = "https://github.com/pypa/sampleproject"
248+
Issues = "https://github.com/pypa/sampleproject/issues"
224249
225250
- ``name`` is the *distribution name* of your package. This can be any name as
226251
long as it only contains letters, numbers, ``.``, ``_`` , and ``-``. It also
@@ -249,9 +274,10 @@ following this tutorial.
249274
your package will work on. For a complete list of classifiers, see
250275
https://pypi.org/classifiers/.
251276
- ``license`` is the :term:`SPDX license expression <License Expression>` of
252-
your package.
277+
your package. Not supported by all the build backends yet.
253278
- ``license-files`` is the list of glob paths to the license files,
254279
relative to the directory where :file:`pyproject.toml` is located.
280+
Not supported by all the build backends yet.
255281
- ``urls`` lets you list any number of extra links to show on PyPI.
256282
Generally this could be to the source, documentation, issue trackers, etc.
257283

0 commit comments

Comments
 (0)