6

I'm trying to create a package with with a data file, but it's not working.

My setup.cfg (per link) is below.

[metadata]
name = my_package
version = 1.0.0
description = My package description
author = John Henckel
author_email = henckel.jonathan@mayo.edu
url = http://example.com
keywords = one, two
license = BSD 3-Clause License
classifiers =
    Framework :: Django
    License :: OSI Approved :: BSD License
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3.5

[options]
include_package_data = True
packages = find:

[options.package_data]
* = *.txt

and the directory structure of my project is...

LICENSE
pyproject.toml
README.md
setup.cfg
my_package
    hello.txt
    __init__.py

and I typed...

python -m build --sdist
tar -vtf dist/my_package-1.0.0.tar.gz

and the output, as you can see does not contain the hello.txt. WHY NOT!??

drwxrwxrwx  0 0      0           0 Oct 22 17:28 my_package-1.0.0/
-rw-rw-rw-  0 0      0          48 Oct 22 17:24 my_package-1.0.0/LICENSE
-rw-rw-rw-  0 0      0         474 Oct 22 17:28 my_package-1.0.0/PKG-INFO
-rw-rw-rw-  0 0      0          29 Oct 22 17:24 my_package-1.0.0/README.md
drwxrwxrwx  0 0      0           0 Oct 22 17:28 my_package-1.0.0/my_package/
-rw-rw-rw-  0 0      0           0 Oct 22 17:24 my_package-1.0.0/my_package/__init__.py
drwxrwxrwx  0 0      0           0 Oct 22 17:28 my_package-1.0.0/my_package.egg-info/
-rw-rw-rw-  0 0      0         474 Oct 22 17:28 my_package-1.0.0/my_package.egg-info/PKG-INFO
-rw-rw-rw-  0 0      0         201 Oct 22 17:28 my_package-1.0.0/my_package.egg-info/SOURCES.txt
-rw-rw-rw-  0 0      0           1 Oct 22 17:28 my_package-1.0.0/my_package.egg-info/dependency_links.txt
-rw-rw-rw-  0 0      0          11 Oct 22 17:28 my_package-1.0.0/my_package.egg-info/top_level.txt
-rw-rw-rw-  0 0      0         108 Oct 01 13:52 my_package-1.0.0/pyproject.toml
-rw-rw-rw-  0 0      0         528 Oct 22 17:28 my_package-1.0.0/setup.cfg
John Henckel
  • 10,274
  • 3
  • 79
  • 79

1 Answers1

5

I suspect that this might depend on which version of setuptools you have installed. When I build a test version of your package, using the same setup.cfg, my source distribution contains hello.txt. However, you may also want to try removing the include_package_data = True option from setup.cfg. The latest setuptools user guide says the following:

"In summary, the three options allow you to:

  • include_package_data Accept all data files and directories matched by MANIFEST.in.
  • package_data Specify additional patterns to match files that may or may not be matched by MANIFEST.in or found in source control.
  • exclude_package_data Specify patterns for data files and directories that should not be included when a package is installed, even if they would otherwise have been included due to the use of the preceding options."

It may be that, for some versions of setuptools, the include_package_data option overrides the package_data list so that you have to supply a MANIFEST.in file instead.

Edit: I overlooked this statement in the setuptools user guide, which seems to confirm what I wrote above:

"If using the setuptools-specific include_package_data argument, files specified by package_data will not be automatically added to the manifest unless they are listed in the MANIFEST.in file."

Ray Osborn
  • 430
  • 5
  • 13
  • Since a lot of packages are currently being converted to use pyproject.toml, it might be helpful to know if my answer works for others as well. – Ray Osborn Feb 14 '22 at 18:03
  • Yes, this is correct. In order to include `hello.txt` in the package, it is necessary to remove the line that says `include_package_data = True`. Not very intuitive! but I can see why it is this way, because of historical reasons. THANKS – John Henckel May 19 '22 at 16:19