| 1 |
The pyproject.toml config file |
| 2 |
============================== |
| 3 |
|
| 4 |
This file lives next to the module or package. |
| 5 |
|
| 6 |
.. note:: |
| 7 |
|
| 8 |
Flit 3.x supported an alternative, older way of specifying project metadata |
| 9 |
in a ``[tool.flit.metadata]`` table. This was superseded by the ``[project]`` |
| 10 |
table described below. |
| 11 |
|
| 12 |
If you need to build a package that used ``[tool.flit.metadata]``, you will |
| 13 |
need ``flit_core <4``. Hopefully most packages specify this constraint and |
| 14 |
will automatically be built with the right version. |
| 15 |
|
| 16 |
Build system section |
| 17 |
-------------------- |
| 18 |
|
| 19 |
This tells tools like pip to build your project with flit. It's a standard |
| 20 |
defined by PEP 517. For any new project using Flit, it will look like this: |
| 21 |
|
| 22 |
.. code-block:: toml |
| 23 |
|
| 24 |
[build-system] |
| 25 |
requires = ["flit_core >=3.11,<5"] |
| 26 |
build-backend = "flit_core.buildapi" |
| 27 |
|
| 28 |
Version constraints: |
| 29 |
|
| 30 |
- For now, all packages should specify ``<5``, so they won't be impacted by |
| 31 |
changes in the next major version. |
| 32 |
- ``import-names`` and ``import-namespaces`` require ``flit_core >=4``. |
| 33 |
- License expressions using ``WITH`` require ``flit_core >=4.1``. |
| 34 |
- ``license-files`` and license expressions in the ``license`` field require |
| 35 |
``flit_core >=3.11``. |
| 36 |
- :ref:`pyproject_toml_project` requires ``flit_core >=3.2``. |
| 37 |
- The older ``[tool.flit.metadata]`` metadata table requires ``flit_core >=2,<4``. |
| 38 |
- The very old ``flit.ini`` file requires ``flit_core <3``. |
| 39 |
- TOML features new in version 1.0 require ``flit_core >=3.4``. |
| 40 |
- ``flit_core`` 3.12 is the last version supporting Python 3.6 & 3.7. |
| 41 |
- ``flit_core`` 3.3 is the last version supporting Python 3.4 & 3.5. Packages |
| 42 |
supporting these Python versions can only use `TOML v0.5 |
| 43 |
<https://toml.io/en/v0.5.0>`_. |
| 44 |
- Only ``flit_core`` 2.x can build packages on Python 2, so packages still |
| 45 |
supporting Python 2 cannot use new-style metadata (the ``[project]`` table). |
| 46 |
|
| 47 |
.. _pyproject_toml_project: |
| 48 |
|
| 49 |
Project metadata |
| 50 |
---------------- |
| 51 |
|
| 52 |
Project metadata is specified in the standard ``[project]`` table. |
| 53 |
A simple ``[project]`` table might look like this: |
| 54 |
|
| 55 |
.. code-block:: toml |
| 56 |
|
| 57 |
[project] |
| 58 |
name = "astcheck" |
| 59 |
authors = [ |
| 60 |
{name = "Thomas Kluyver", email = "[email protected]"}, |
| 61 |
] |
| 62 |
readme = "README.rst" |
| 63 |
license = "MIT" |
| 64 |
requires-python = ">=3.5" |
| 65 |
dynamic = ["version", "description"] |
| 66 |
|
| 67 |
.. seealso:: |
| 68 |
|
| 69 |
`The pyproject.toml specification <https://packaging.python.org/en/latest/specifications/pyproject-toml/>`_ |
| 70 |
|
| 71 |
The allowed fields are: |
| 72 |
|
| 73 |
name |
| 74 |
The name your package will have on PyPI. This field is required. For Flit, |
| 75 |
this name, with any hyphens replaced by underscores, is also the default value |
| 76 |
of the import name (see :ref:`pyproject_module` if that needs to be |
| 77 |
different). |
| 78 |
|
| 79 |
.. versionchanged:: 3.8 |
| 80 |
Hyphens in the project name are now translated to underscores for the |
| 81 |
import name. |
| 82 |
version |
| 83 |
Version number as a string. If you want Flit to get this from a |
| 84 |
``__version__`` attribute, leave it out of the TOML config and include |
| 85 |
"version" in the ``dynamic`` field. |
| 86 |
description |
| 87 |
A one-line description of your project. If you want Flit to get this from |
| 88 |
the module docstring, leave it out of the TOML config and include |
| 89 |
"description" in the ``dynamic`` field. |
| 90 |
readme |
| 91 |
A path (relative to the .toml file) to a file containing a longer description |
| 92 |
of your package to show on PyPI. This should be written in `reStructuredText |
| 93 |
<https://docutils.sourceforge.io/docs/user/rst/quickref.html>`_, Markdown or |
| 94 |
plain text, and the filename should have the appropriate extension |
| 95 |
(``.rst``, ``.md`` or ``.txt``). Alternatively, ``readme`` can be a table with |
| 96 |
either a ``file`` key (a relative path) or a ``text`` key (literal text), and |
| 97 |
an optional ``content-type`` key (e.g. ``text/x-rst``). |
| 98 |
requires-python |
| 99 |
A version specifier for the versions of Python this requires, e.g. ``~=3.3`` or |
| 100 |
``>=3.3,<4``, which are equivalent. |
| 101 |
license |
| 102 |
A valid SPDX `license expression <https://peps.python.org/pep-0639/#term-license-expression>`_ |
| 103 |
or a table with either a ``file`` key (a relative path to a license file) or a |
| 104 |
``text`` key (the license text). |
| 105 |
license-files |
| 106 |
A list of glob patterns for license files to include. |
| 107 |
Defaults to ``['COPYING*', 'LICEN[CS]E*', 'NOTICE*', 'AUTHORS*']``. |
| 108 |
authors |
| 109 |
A list of tables with ``name`` and ``email`` keys (both optional) describing |
| 110 |
the authors of the project. |
| 111 |
maintainers |
| 112 |
Same format as authors. |
| 113 |
keywords |
| 114 |
A list of words to help with searching for your package. |
| 115 |
classifiers |
| 116 |
A list of `Trove classifiers <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_. |
| 117 |
Add ``Private :: Do Not Upload`` into the list to prevent a private package |
| 118 |
from being uploaded to PyPI by accident. |
| 119 |
import-names |
| 120 |
A list containing the importable module names in this package. You don't |
| 121 |
normally need to supply this manually, but you can specify it with a |
| 122 |
``; private`` suffix to record that the module is not intended for public use. |
| 123 |
This does not stop anyone importing it. |
| 124 |
import-namespaces |
| 125 |
A list of import names in this package which are namespace packages. Like |
| 126 |
``import-names``, Flit will supply this metadata automatically if you use |
| 127 |
namespace packages. |
| 128 |
dependencies & optional-dependencies |
| 129 |
See :ref:`pyproject_project_dependencies`. |
| 130 |
urls |
| 131 |
See :ref:`pyproject_project_urls`. |
| 132 |
scripts & gui-scripts |
| 133 |
See :ref:`pyproject_project_scripts`. |
| 134 |
entry-points |
| 135 |
See :ref:`pyproject_project_entrypoints`. |
| 136 |
dynamic |
| 137 |
A list of field names which aren't specified here, for which Flit should |
| 138 |
find a value at build time. Only "version", "description", "import-names" |
| 139 |
and "import-namespaces" are accepted. |
| 140 |
|
| 141 |
.. _pyproject_project_dependencies: |
| 142 |
|
| 143 |
Dependencies |
| 144 |
~~~~~~~~~~~~ |
| 145 |
|
| 146 |
The ``dependencies`` field is a list of other packages from PyPI that this |
| 147 |
package needs. Each package may be followed by a version specifier like |
| 148 |
``>=4.1``, and/or an `environment marker`_ |
| 149 |
after a semicolon. For example: |
| 150 |
|
| 151 |
.. code-block:: toml |
| 152 |
|
| 153 |
dependencies = [ |
| 154 |
"requests >=2.6", |
| 155 |
"configparser; python_version == '2.7'", |
| 156 |
] |
| 157 |
|
| 158 |
The ``[project.optional-dependencies]`` table contains lists of packages needed |
| 159 |
for every optional feature. The requirements are specified in the same format as |
| 160 |
for ``dependencies``. For example: |
| 161 |
|
| 162 |
.. code-block:: toml |
| 163 |
|
| 164 |
[project.optional-dependencies] |
| 165 |
test = [ |
| 166 |
"pytest >=2.7.3", |
| 167 |
"pytest-cov", |
| 168 |
] |
| 169 |
doc = ["sphinx"] |
| 170 |
|
| 171 |
You can call these optional features anything you want, although ``test`` and |
| 172 |
``doc`` are common ones. You specify them for installation in square brackets |
| 173 |
after the package name or directory, e.g. ``pip install '.[test]'``. |
| 174 |
|
| 175 |
.. _pyproject_project_urls: |
| 176 |
|
| 177 |
URLs table |
| 178 |
~~~~~~~~~~ |
| 179 |
|
| 180 |
Your project's page on `pypi.org <https://pypi.org/>`_ can show a number of |
| 181 |
links. You can point people to documentation or a bug tracker, for example. |
| 182 |
|
| 183 |
This section is called ``[project.urls]`` in the file. You can use |
| 184 |
any names inside it. Here it is for flit: |
| 185 |
|
| 186 |
.. code-block:: toml |
| 187 |
|
| 188 |
[project.urls] |
| 189 |
Documentation = "https://flit.pypa.io" |
| 190 |
Source = "https://github.com/pypa/flit" |
| 191 |
|
| 192 |
.. _pyproject_project_scripts: |
| 193 |
|
| 194 |
Scripts section |
| 195 |
~~~~~~~~~~~~~~~ |
| 196 |
|
| 197 |
This section is called ``[project.scripts]`` in the file. |
| 198 |
Each key and value describes a shell command to be installed along with |
| 199 |
your package. These work like setuptools 'entry points'. Here's the section |
| 200 |
for flit: |
| 201 |
|
| 202 |
.. code-block:: toml |
| 203 |
|
| 204 |
[project.scripts] |
| 205 |
flit = "flit:main" |
| 206 |
|
| 207 |
|
| 208 |
This will create a ``flit`` command, which will call the function ``main()`` |
| 209 |
imported from :mod:`flit`. |
| 210 |
|
| 211 |
A similar table called ``[project.gui-scripts]`` defines commands which launch |
| 212 |
a GUI. This only makes a difference on Windows, where GUI scripts are run |
| 213 |
without a console. |
| 214 |
|
| 215 |
.. _pyproject_project_entrypoints: |
| 216 |
|
| 217 |
Entry points sections |
| 218 |
~~~~~~~~~~~~~~~~~~~~~ |
| 219 |
|
| 220 |
You can declare `entry points <https://entrypoints.readthedocs.io/en/latest/>`_ |
| 221 |
using sections named :samp:`[project.entry-points.{groupname}]`. E.g. to |
| 222 |
provide a pygments lexer from your package: |
| 223 |
|
| 224 |
.. code-block:: toml |
| 225 |
|
| 226 |
[project.entry-points."pygments.lexers"] |
| 227 |
dogelang = "dogelang.lexer:DogeLexer" |
| 228 |
|
| 229 |
In each ``package:name`` value, the part before the colon should be an |
| 230 |
importable module name, and the latter part should be the name of an object |
| 231 |
accessible within that module. The details of what object to expose depend on |
| 232 |
the application you're extending. |
| 233 |
|
| 234 |
If the group name contains a dot, it must be quoted (``"pygments.lexers"`` |
| 235 |
above). Script entry points are defined in :ref:`scripts tables |
| 236 |
<pyproject_project_scripts>`, so you can't use the group names |
| 237 |
``console_scripts`` or ``gui_scripts`` here. |
| 238 |
|
| 239 |
.. _pyproject_module: |
| 240 |
|
| 241 |
Module section |
| 242 |
~~~~~~~~~~~~~~ |
| 243 |
|
| 244 |
If your package will have different names for installation and import, |
| 245 |
you should specify the install (PyPI) name in the ``[project]`` table |
| 246 |
(:ref:`see above <pyproject_toml_project>`), and the import name in a |
| 247 |
``[tool.flit.module]`` table: |
| 248 |
|
| 249 |
.. code-block:: toml |
| 250 |
|
| 251 |
[project] |
| 252 |
name = "pynsist" |
| 253 |
# ... |
| 254 |
|
| 255 |
[tool.flit.module] |
| 256 |
name = "nsist" |
| 257 |
|
| 258 |
Flit looks for the source of the package by its import name. The source may be |
| 259 |
located either in the directory that holds the ``pyproject.toml`` file, or in a |
| 260 |
``src/`` subdirectory. |
| 261 |
|
| 262 |
.. _pyproject_toml_sdist: |
| 263 |
|
| 264 |
Contents of distribution files |
| 265 |
------------------------------ |
| 266 |
|
| 267 |
When building a wheel, Flit includes the package contents (including non-Python |
| 268 |
data files, but not ``.pyc`` bytecode files) along with the normal wheel |
| 269 |
metadata. |
| 270 |
|
| 271 |
When building an sdist, in addition to the package contents Flit includes |
| 272 |
everything it needs to build and install your module: your ``pyproject.toml`` |
| 273 |
file, the readme & license files given in the metadata, and the :ref:`external |
| 274 |
data folder <pyproject_toml_external_data>` if you specified that. |
| 275 |
|
| 276 |
If you want more control over the content of the sdist, you can give lists of |
| 277 |
paths or glob patterns as ``include`` and ``exclude`` in the ``tool.flit.sdist`` |
| 278 |
section of ``pyproject.toml``. For example: |
| 279 |
|
| 280 |
.. code-block:: toml |
| 281 |
|
| 282 |
[tool.flit.sdist] |
| 283 |
include = ["doc/"] |
| 284 |
exclude = ["doc/*.html"] |
| 285 |
|
| 286 |
These paths: |
| 287 |
|
| 288 |
- Always use ``/`` as a separator (POSIX style) |
| 289 |
- Must be relative paths from the directory containing ``pyproject.toml`` |
| 290 |
- Cannot go outside that directory (no ``../`` paths) |
| 291 |
- Cannot contain control characters or ``<>:"\\`` |
| 292 |
- Can refer to directories, in which case they include everything under the |
| 293 |
directory, including subdirectories |
| 294 |
- Should match the case of the files they refer to, as case-insensitive matching |
| 295 |
is platform dependent |
| 296 |
|
| 297 |
.. versionchanged:: 3.8 |
| 298 |
Include and exclude patterns can now use recursive glob patterns (``**``). |
| 299 |
|
| 300 |
.. note:: |
| 301 |
|
| 302 |
Flit includes a tool to generate these rules for you from a git repository. |
| 303 |
Generate any files that should be excluded, such as built documentation or |
| 304 |
test coverage data, and then run ``python -m flit.sdist_rules`` in the folder |
| 305 |
containing ``pyproject.toml``. Copy the rules into your project config and |
| 306 |
adjust them as necessary. |
| 307 |
|
| 308 |
Exclusions have priority over inclusions. Bytecode is excluded by default and cannot |
| 309 |
be included. |
| 310 |
|
| 311 |
Note that in the common case where a tool builds a sdist and then builds the wheel |
| 312 |
*from* that sdist, the ``exclude`` pattern can indirectly affect the content of the |
| 313 |
final wheel (by omitting content from the sdist that would otherwise have been |
| 314 |
included in the wheel). |
| 315 |
|
| 316 |
Including files committed in git/hg |
| 317 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 318 |
|
| 319 |
If you use :ref:`build_cmd` or :ref:`publish_cmd`, you can also make sdists with |
| 320 |
the files which are committed in version control (git or hg). This is a shortcut |
| 321 |
to e.g. include documentation source files, but not built HTML or PDF |
| 322 |
documentation. The include and exclude patterns are then applied on top of this |
| 323 |
list. |
| 324 |
|
| 325 |
For now, including files from version control is the default for :ref:`build_cmd` |
| 326 |
and :ref:`publish_cmd`, and can be disabled with ``--no-use-vcs``. The default |
| 327 |
will switch in a future version. |
| 328 |
|
| 329 |
Using ``flit_core`` as a backend to other tools such as `build |
| 330 |
<https://pypa-build.readthedocs.io/en/latest/>`_ never gets the list of files |
| 331 |
for the sdist from version control. |
| 332 |
|
| 333 |
.. _pyproject_toml_external_data: |
| 334 |
|
| 335 |
External data section |
| 336 |
--------------------- |
| 337 |
|
| 338 |
.. versionadded:: 3.7 |
| 339 |
|
| 340 |
Data files which your code will use should go inside the Python package folder. |
| 341 |
Flit will package these with no special configuration. |
| 342 |
|
| 343 |
However, sometimes it's useful to package external files for system integration, |
| 344 |
such as man pages or files defining a Jupyter extension. To do this, arrange |
| 345 |
the files within a directory such as ``data``, next to your ``pyproject.toml`` |
| 346 |
file, and add a section like this: |
| 347 |
|
| 348 |
.. code-block:: toml |
| 349 |
|
| 350 |
[tool.flit.external-data] |
| 351 |
directory = "data" |
| 352 |
|
| 353 |
Paths within this directory are typically installed to corresponding paths under |
| 354 |
a prefix (such as a virtualenv directory). E.g. you might save a man page for a |
| 355 |
script as ``(data)/share/man/man1/foo.1``. |
| 356 |
|
| 357 |
Whether these files are detected by the systems they're meant to integrate with |
| 358 |
depends on how your package is installed and how those systems are configured. |
| 359 |
For instance, installing in a virtualenv usually doesn't affect anything outside |
| 360 |
that environment. Don't rely on these files being picked up unless you have |
| 361 |
close control of how the package will be installed. |
| 362 |
|
| 363 |
If you install a package with ``flit install --symlink``, a symlink is made |
| 364 |
for each file in the external data directory. Otherwise (including development |
| 365 |
installs with ``pip install -e``), these files are copied to their destination, |
| 366 |
so changes here won't take effect until you reinstall the package. |
| 367 |
|
| 368 |
.. note:: |
| 369 |
|
| 370 |
For users coming from setuptools: external data corresponds to setuptools' |
| 371 |
``data_files`` parameter, although setuptools offers more flexibility. |
| 372 |
|
| 373 |
.. _environment marker: https://www.python.org/dev/peps/pep-0508/#environment-markers |