|
| 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