Skip to content

Commit 51d1f67

Browse files
jwodderncoghlan
authored andcommitted
Guide to MANIFEST.in (#609)
Replaces a cross reference to the legacy distutils documentation with a new self-contained guide. * Add notes about ** and relative directory patterns
1 parent da12afc commit 51d1f67

3 files changed

Lines changed: 109 additions & 10 deletions

File tree

source/guides/distributing-packages-using-setuptools.rst

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,15 @@ sample project <https://github.com/pypa/sampleproject>`_.
101101
MANIFEST.in
102102
~~~~~~~~~~~
103103

104-
A :file:`MANIFEST.in` is needed when you need to package
105-
additional files that are not automatically included in a source distribution.
106-
To see a list of what's included by default, see the `Specifying the files to
107-
distribute <https://docs.python.org/3/distutils/sourcedist.html#specifying-the-files-to-distribute>`_
108-
section from the :ref:`distutils` documentation.
104+
A :file:`MANIFEST.in` is needed when you need to package additional files that
105+
are not automatically included in a source distribution. For details on
106+
writing a :file:`MANIFEST.in` file, including a list of what's included by
107+
default, see ":ref:`Using MANIFEST.in`".
109108

110109
For an example, see the `MANIFEST.in
111110
<https://github.com/pypa/sampleproject/blob/master/MANIFEST.in>`_ from the `PyPA
112111
sample project <https://github.com/pypa/sampleproject>`_.
113112

114-
For details on writing a :file:`MANIFEST.in` file, see the `The MANIFEST.in
115-
template
116-
<https://docs.python.org/2/distutils/sourcedist.html#the-manifest-in-template>`_
117-
section from the :ref:`distutils` documentation.
118-
119113
.. note:: :file:`MANIFEST.in` does not affect binary distributions such as wheels.
120114

121115
LICENSE.txt

source/guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ introduction to packaging, see :doc:`/tutorials/index`.
1515
installing-scientific-packages
1616
multi-version-installs
1717
distributing-packages-using-setuptools
18+
using-manifest-in
1819
single-sourcing-package-version
1920
supporting-multiple-python-versions
2021
dropping-older-python-versions
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
.. _`Using MANIFEST.in`:
2+
3+
============================================================
4+
Including files in source distributions with ``MANIFEST.in``
5+
============================================================
6+
7+
When building a :term:`source distribution <Source Distribution (or "sdist")>`
8+
for your package, by default only a minimal set of files are included. You may
9+
find yourself wanting to include extra files in the source distribution, such
10+
as an authors/contributors file, a :file:`docs/` directory, or a directory of
11+
data files used for testing purposes. There may even be extra files that you
12+
*need* to include; for example, if your :file:`setup.py` computes your
13+
project's ``long_description`` by reading from both a README and a changelog
14+
file, you'll need to include both those files in the sdist so that people that
15+
build or install from the sdist get the correct results.
16+
17+
Adding & removing files to & from the source distribution is done by writing a
18+
:file:`MANIFEST.in` file at the project root.
19+
20+
21+
How files are included in an sdist
22+
==================================
23+
24+
The following files are included in a source distribution by default:
25+
26+
- all Python source files implied by the ``py_modules`` and ``packages``
27+
``setup()`` arguments
28+
- all C source files mentioned in the ``ext_modules`` or ``libraries``
29+
``setup()`` arguments
30+
- scripts specified by the ``scripts`` ``setup()`` argument
31+
- all files specified by the ``package_data`` and ``data_files`` ``setup()``
32+
arguments
33+
- the file specified by the ``license_file`` option in :file:`setup.cfg`
34+
(setuptools 40.8.0+)
35+
- all files matching the pattern :file:`test/test*.py`
36+
- :file:`setup.py` (or whatever you called your setup script)
37+
- :file:`setup.cfg`
38+
- :file:`README`
39+
- :file:`README.txt`
40+
- :file:`README.rst` (Python 3.7+ or setuptools 0.6.27+)
41+
- :file:`README.md` (setuptools 36.4.0+)
42+
- :file:`MANIFEST.in`
43+
44+
After adding the above files to the sdist, the commands in :file:`MANIFEST.in`
45+
(if such a file exists) are executed in order to add and remove further files
46+
to & from the sdist. Default files can even be removed from the sdist with the
47+
appropriate :file:`MANIFEST.in` command.
48+
49+
After processing the :file:`MANIFEST.in` file, setuptools removes the
50+
:file:`build/` directory as well as any directories named :file:`RCS`,
51+
:file:`CVS`, or :file:`.svn` from the sdist, and it adds a :file:`PKG-INFO`
52+
file and an :file:`*.egg-info` directory. This behavior cannot be changed with
53+
:file:`MANIFEST.in`.
54+
55+
56+
:file:`MANIFEST.in` commands
57+
============================
58+
59+
A :file:`MANIFEST.in` file consists of commands, one per line, instructing
60+
setuptools to add or remove some set of files from the sdist. The commands
61+
are:
62+
63+
=============================================== ==================================================================================================
64+
Command Description
65+
=============================================== ==================================================================================================
66+
``include pat1 pat2 ...`` Include all files matching any of the listed patterns
67+
``exclude pat1 pat2 ...`` Exclude all files matching any of the listed patterns
68+
``recursive-include dir-pattern pat1 pat2 ...`` Include all files under directories matching ``dir-pattern`` that match any of the listed patterns
69+
``recursive-exclude dir-pattern pat1 pat2 ...`` Exclude all files under directories matching ``dir-pattern`` that match any of the listed patterns
70+
``global-include pat1 pat2 ...`` Include all files anywhere in the source tree matching any of the listed patterns
71+
``global-exclude pat1 pat2 ...`` Exclude all files anywhere in the source tree matching any of the listed patterns
72+
``graft dir-pattern`` Include all files under directories matching ``dir-pattern``
73+
``prune dir-pattern`` Exclude all files under directories matching ``dir-pattern``
74+
=============================================== ==================================================================================================
75+
76+
The patterns here are glob-style patterns: ``*`` matches zero or more regular
77+
filename characters (on Unix, everything except forward slash; on Windows,
78+
everything except backslash and colon); ``?`` matches a single regular filename
79+
character, and ``[chars]`` matches any one of the characters between the square
80+
brackets (which may contain character ranges, e.g., ``[a-z]`` or
81+
``[a-fA-F0-9]``). Setuptools also has undocumented support for ``**`` matching
82+
zero or more characters including forward slash, backslash, and colon.
83+
84+
Directory patterns are relative to the root of the project directory; e.g.,
85+
``graft example*`` will include a directory named :file:`examples` in the
86+
project root but will not include :file:`docs/examples/`.
87+
88+
File & directory names in :file:`MANIFEST.in` should be ``/``-separated;
89+
setuptools will automatically convert the slashes to the local platform's
90+
appropriate directory separator.
91+
92+
Commands are processed in the order they appear in the :file:`MANIFEST.in`
93+
file. For example, given the commands::
94+
95+
graft tests
96+
global-exclude *.py[cod]
97+
98+
the contents of the directory tree :file:`tests` will first be added to the
99+
sdist, and then after that all files in the sdist with a ``.pyc``, ``.pyo``, or
100+
``.pyd`` extension will be removed from the sdist. If the commands were in the
101+
opposite order, then ``*.pyc`` files etc. would be only be removed from what
102+
was already in the sdist before adding :file:`tests`, and if :file:`tests`
103+
happened to contain any ``*.pyc`` files, they would end up included in the
104+
sdist because the exclusion happened before they were included.

0 commit comments

Comments
 (0)