@@ -10,12 +10,19 @@ by including the data files **inside the package directory**.
10
10
11
11
Setuptools focuses on this most common type of data files and offers three ways
12
12
of specifying which files should be included in your packages, as described in
13
- the following sections.
13
+ the following section.
14
+
15
+
16
+ Configuration Options
17
+ =====================
18
+
19
+
20
+ .. _include-package-data :
14
21
15
22
include_package_data
16
- ====================
23
+ --------------------
17
24
18
- First, you can simply use the ``include_package_data `` keyword.
25
+ First, you can use the ``include_package_data `` keyword.
19
26
For example, if the package tree looks like this::
20
27
21
28
project_root_directory
@@ -92,8 +99,10 @@ your package, provided:
92
99
(where ``include_package_data=False `` by default), which was not changed
93
100
to ensure backwards compatibility with existing projects.
94
101
102
+ .. _package-data :
103
+
95
104
package_data
96
- ============
105
+ ------------
97
106
98
107
By default, ``include_package_data `` considers **all ** non ``.py `` files found inside
99
108
the package directory (``src/mypkg `` in this case) as data files, and includes those that
@@ -260,8 +269,10 @@ we specify that ``data1.rst`` from ``mypkg1`` alone should be captured as well.
260
269
Please check :ref: `section subdirectories <subdir-data-files >` below.
261
270
262
271
272
+ .. _exclude-package-data :
273
+
263
274
exclude_package_data
264
- ====================
275
+ --------------------
265
276
266
277
Sometimes, the ``include_package_data `` or ``package_data `` options alone
267
278
aren't sufficient to precisely define what files you want included. For example,
@@ -327,6 +338,38 @@ even if they were listed in ``package_data`` or were included as a result of usi
327
338
``include_package_data ``.
328
339
329
340
341
+ Summary
342
+ -------
343
+
344
+ In summary, the three options allow you to:
345
+
346
+ ``include_package_data ``
347
+ Accept all data files and directories matched by
348
+ :ref: `MANIFEST.in <Using MANIFEST.in >` or added by
349
+ a :ref: `plugin <Adding Support for Revision Control Systems >`.
350
+
351
+ ``package_data ``
352
+ Specify additional patterns to match files that may or may
353
+ not be matched by :ref: `MANIFEST.in <Using MANIFEST.in >`
354
+ or added by a :ref: `plugin <Adding Support for Revision Control Systems >`.
355
+
356
+ ``exclude_package_data ``
357
+ Specify patterns for data files and directories that should *not * be
358
+ included when a package is installed, even if they would otherwise have
359
+ been included due to the use of the preceding options.
360
+
361
+ .. note ::
362
+ Due to the way the build process works, a data file that you
363
+ include in your project and then stop including may be "orphaned" in your
364
+ project's build directories, requiring you to manually deleting them.
365
+ This may also be important for your users and contributors
366
+ if they track intermediate revisions of your project using Subversion; be sure
367
+ to let them know when you make changes that remove files from inclusion so they
368
+ can also manually delete them.
369
+
370
+ See also troubleshooting information in :ref: `Caching and Troubleshooting `.
371
+
372
+
330
373
.. _subdir-data-files :
331
374
332
375
Subdirectory for Data Files
@@ -350,8 +393,13 @@ Here, the ``.rst`` files are placed under a ``data`` subdirectory inside ``mypkg
350
393
while the ``.txt `` files are directly under ``mypkg ``.
351
394
352
395
In this case, the recommended approach is to treat ``data `` as a namespace package
353
- (refer :pep: `420 `). With ``package_data ``,
354
- the configuration might look like this:
396
+ (refer :pep: `420 `). This way, you can rely on the same methods described above,
397
+ using either :ref: `package-data ` or :ref: `include-package-data `.
398
+ For the sake of completeness, we include below configuration examples
399
+ for the subdirectory structure, but please refer to the detailed
400
+ information in the previous sections of this document.
401
+
402
+ With :ref: `package-data `, the configuration might look like this:
355
403
356
404
.. tab :: pyproject.toml
357
405
@@ -407,8 +455,9 @@ which enables the ``data`` directory to be identified, and then, we separately s
407
455
files for the root package ``mypkg ``, and the namespace package ``data `` under the package
408
456
``mypkg ``.
409
457
410
- With ``include_package_data `` the configuration is simpler: you simply need to enable
411
- scanning of namespace packages in the ``src `` directory and the rest is handled by Setuptools.
458
+ Alternatively, you can also rely on :ref: `include-package-data `.
459
+ Note that this is the default behaviour in ``pyproject.toml ``, but you need to
460
+ manually enable scanning of namespace packages in ``setup.cfg `` or ``setup.py ``:
412
461
413
462
.. tab :: pyproject.toml
414
463
@@ -422,7 +471,7 @@ scanning of namespace packages in the ``src`` directory and the rest is handled
422
471
423
472
[tool.setuptools.packages.find]
424
473
# scanning for namespace packages is true by default in pyproject.toml, so
425
- # you need NOT include the following line .
474
+ # you need NOT include this configuration .
426
475
namespaces = true
427
476
where = ["src"]
428
477
@@ -451,34 +500,9 @@ scanning of namespace packages in the ``src`` directory and the rest is handled
451
500
include_package_data = True ,
452
501
)
453
502
454
- Summary
455
- =======
456
-
457
- In summary, the three options allow you to:
458
-
459
- ``include_package_data ``
460
- Accept all data files and directories matched by
461
- :ref: `MANIFEST.in <Using MANIFEST.in >` or added by
462
- a :ref: `plugin <Adding Support for Revision Control Systems >`.
463
-
464
- ``package_data ``
465
- Specify additional patterns to match files that may or may
466
- not be matched by :ref: `MANIFEST.in <Using MANIFEST.in >`
467
- or added by a :ref: `plugin <Adding Support for Revision Control Systems >`.
468
-
469
- ``exclude_package_data ``
470
- Specify patterns for data files and directories that should *not * be
471
- included when a package is installed, even if they would otherwise have
472
- been included due to the use of the preceding options.
473
-
474
- .. note ::
475
- Due to the way the build process works, a data file that you
476
- include in your project and then stop including may be "orphaned" in your
477
- project's build directories, requiring you to manually deleting them.
478
- This may also be important for your users and contributors
479
- if they track intermediate revisions of your project using Subversion; be sure
480
- to let them know when you make changes that remove files from inclusion so they
481
- can also manually delete them.
503
+ To avoid common mistakes with :ref: `include-package-data `,
504
+ please ensure :ref: `MANIFEST.in <Using MANIFEST.in >` is properly set
505
+ or use a revision control system plugin (see :doc: `/userguide/miscellaneous `).
482
506
483
507
484
508
.. _Accessing Data Files at Runtime :
0 commit comments