Skip to content

Commit cd54de1

Browse files
committed
Document the legacy way of declaring pyproject.toml
1 parent c9b8cb6 commit cd54de1

File tree

3 files changed

+89
-23
lines changed

3 files changed

+89
-23
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ 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, setuptools and flit don't support PEP 639 yet.
1316

1417

1518
Licensing Examples

source/guides/writing-pyproject-toml.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ 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, setuptools and flit don't support PEP 639 yet.
332+
333+
PEP 639 license declaration
334+
'''''''''''''''''''''''''''
335+
328336
This is a valid :term:`SPDX license expression <License Expression>` consisting
329337
of one or more :term:`license identifiers <License Identifier>`.
330338
The full license list is available at the
@@ -352,10 +360,39 @@ The custom identifiers must follow the SPDX specification,
352360
[project]
353361
license = "LicenseRef-My-Custom-License"
354362
363+
Legacy license declaration
364+
''''''''''''''''''''''''''
365+
366+
This can take two forms. You can put your license in a file, typically
367+
``LICENSE`` or ``LICENSE.txt``, and link that file here:
368+
369+
.. code-block:: toml
370+
371+
[project]
372+
license = {file = "LICENSE"}
373+
374+
or you can write the name of the license:
375+
376+
.. code-block:: toml
377+
378+
[project]
379+
license = {text = "MIT License"}
380+
381+
If you are using a standard, well-known license, it is not necessary to use this
382+
field. Instead, you should use one of the :ref:`classifiers` starting with ``License
383+
::``. (As a general rule, it is a good idea to use a standard, well-known
384+
license, both to avoid confusion and because some organizations avoid software
385+
whose license is unapproved.)
386+
355387

356388
``license-files``
357389
-----------------
358390

391+
PEP 639 (accepted in August 2024) has introduced the ``license-files`` field.
392+
Make sure your preferred build backend supports PEP 639 before declaring the
393+
field.
394+
As of February 2025, setuptools and flit don't support PEP 639 yet.
395+
359396
This is a list of license files and files containing other legal
360397
information you want to distribute with your package.
361398

@@ -529,7 +566,7 @@ A full example
529566
]
530567
description = "Lovely Spam! Wonderful Spam!"
531568
readme = "README.rst"
532-
license = "MIT"
569+
license = "MIT" # or license = {file = "LICENSE.txt"} for legacy declaration
533570
license-files = ["LICEN[CS]E.*"]
534571
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
535572
classifiers = [

source/tutorials/packaging-projects.rst

Lines changed: 48 additions & 22 deletions
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)