Pyproject.toml: Difference between revisions
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
* https://python-poetry.org/docs/pyproject/ | * https://python-poetry.org/docs/pyproject/ | ||
* https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#writing-pyproject-toml | |||
=Internal= | =Internal= | ||
* [[Poetry_Concepts#pyproject.toml|Poetry Concepts]] | * [[Poetry_Concepts#pyproject.toml|Poetry Concepts]] | ||
Line 11: | Line 13: | ||
=Build Backend Configuration= | =Build Backend Configuration= | ||
<code>pyproject.toml</code> tells the [[Python_Language_Modularization#Build_Frontend|build frontend]] tool which [[Python_Language_Modularization#Build_Backend|backend]] to use for the specific project it is part of. | <code>pyproject.toml</code> tells the [[Python_Language_Modularization#Build_Frontend|build frontend]] tool which [[Python_Language_Modularization#Build_Backend|backend]] to use for the specific project it is part of. | ||
The <code>requires</code> key is a list of packages that are needed to build the package. The frontend should install them automatically when building the package. <font color=darkkhaki>What about the dependencies specified in <code>[[requirements.txt|requirements.txt]]</code>?</font> The <code>build-backend</code> key is the name of the Python object that frontends will use to perform the build. | |||
Additional configuration of the build tool will either be in a <code>tool</code> section of the <code>pyproject.toml</code>, or in a special file defined by the build tool. For example, when using <code>setuptools</code> as build backend, additional configuration may be added to a <code>setup.py</code> or <code>setup.cfg</code> file. | |||
<syntaxhighlight lang='toml'> | <syntaxhighlight lang='toml'> | ||
Line 19: | Line 25: | ||
=Project Metadata= | =Project Metadata= | ||
<syntaxhighlight lang='toml'> | |||
[project] | |||
name = "ofddi" | |||
version = "0.1.0" | |||
authors = [ | |||
{ name="Ovidiu Feodorov", email="ovidiu@example.com" }, | |||
] | |||
description = "DDI" | |||
readme = "README.md" | |||
requires-python = ">=3.12" | |||
classifiers = [ | |||
"Programming Language :: Python :: 3", | |||
"License :: OSI Approved :: MIT License", | |||
"Operating System :: OS Independent", | |||
] | |||
[project.urls] | |||
Homepage = "https://github.com/ovidiuf/ofddi" | |||
Issues = "https://github.com/ovidiuf/ofddi/issues" | |||
</syntaxhighlight> | |||
==<tt>name</tt>== | |||
<code>name</code> is the [[Python_Language_Modularization#Distribution_Name|distribution name of the package]]. For more details, see: {{Internal|Python_Language_Modularization#Distribution_Name|Python Language Modularization | Distribution Packages}} | |||
==<tt>version</tt>== | |||
See: {{Internal|Python_Language_Modularization#Distribution_Package_Version|Python Language Modularization | Distribution Package Version}} | |||
==<tt>authors</tt>== | |||
Used to identify the author of the package. A name and an email for each author is required. | |||
==<tt>description</tt>== | |||
A short, one-sentence summary of the package. | |||
==<tt>readme</tt>== | |||
A path to a file containing a detailed description of the package. This is shown on the package detail page on PyPI. In this case, the description is loaded from <code>README.md</code>, which is a common pattern. There also is a more advanced table form. | |||
==<tt>requires-python</tt>== | |||
The versions of Python supported by the project. An installer like <code>pip</code> will look back through older versions of packages until it finds one that has a matching Python version. | |||
==<tt>classifiers</tt>== | |||
This section provides the index and <code>pip</code> additional metadata about the package. In this case, the package is only compatible with Python 3, is licensed under the MIT license, and is OS-independent. You should always include at least which version(s) of Python your package works on, which license your package is available under, and which operating systems your package will work on. For a complete list of classifiers, see: {{External|https://pypi.org/classifiers}} | |||
==<tt>urls</tt>== | |||
Extra links to show on PyPI. Generally this could be to the source, documentation, issue trackers, etc. |
Latest revision as of 02:42, 6 April 2024
External
- https://python-poetry.org/docs/pyproject/
- https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#writing-pyproject-toml
Internal
Overview
pyproject.toml
is a file that specifies required packages, scripts, plugins and URLs.
Build Backend Configuration
pyproject.toml
tells the build frontend tool which backend to use for the specific project it is part of.
The requires
key is a list of packages that are needed to build the package. The frontend should install them automatically when building the package. What about the dependencies specified in requirements.txt
? The build-backend
key is the name of the Python object that frontends will use to perform the build.
Additional configuration of the build tool will either be in a tool
section of the pyproject.toml
, or in a special file defined by the build tool. For example, when using setuptools
as build backend, additional configuration may be added to a setup.py
or setup.cfg
file.
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Project Metadata
[project]
name = "ofddi"
version = "0.1.0"
authors = [
{ name="Ovidiu Feodorov", email="ovidiu@example.com" },
]
description = "DDI"
readme = "README.md"
requires-python = ">=3.12"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
Homepage = "https://github.com/ovidiuf/ofddi"
Issues = "https://github.com/ovidiuf/ofddi/issues"
name
name
is the distribution name of the package. For more details, see:
version
See:
authors
Used to identify the author of the package. A name and an email for each author is required.
description
A short, one-sentence summary of the package.
readme
A path to a file containing a detailed description of the package. This is shown on the package detail page on PyPI. In this case, the description is loaded from README.md
, which is a common pattern. There also is a more advanced table form.
requires-python
The versions of Python supported by the project. An installer like pip
will look back through older versions of packages until it finds one that has a matching Python version.
classifiers
This section provides the index and pip
additional metadata about the package. In this case, the package is only compatible with Python 3, is licensed under the MIT license, and is OS-independent. You should always include at least which version(s) of Python your package works on, which license your package is available under, and which operating systems your package will work on. For a complete list of classifiers, see:
urls
Extra links to show on PyPI. Generally this could be to the source, documentation, issue trackers, etc.