Simple documentation for setup.cfg

But they don’t. Anything from MANIFEST.in that’s not inside a package gets pulled into the sdist irrespective of the value of include_package_data.

Correction: include_package_data=True has no effect on MANIFEST.in for sdists, it simply just makes setuptools ignore package_data. I’m sure I used to know this…

The way it works is:

  • If you’re building an sdist:
    • setuptools includes everything from MANIFEST.in
    • If include_package_data=True it ignores package_data
    • If include_package_data=False (the default), it also includes files from package_data
  • If you’re building a wheel:
    • setuptools includes package data entries from MANIFEST.in IFF include_package_data=True
    • If include_package_data=True it ignores package_data
    • If include_package_data=False (the default), it includes files from package_data
2 Likes

I’ve gone with the one which works on this computer (Python 3.10.0) - which only seems to like deprecated forms:

from importlib import resources # for filepaths

namehelp = 'qucs_netlist.hlp'
filehelp_contents = resources.read_text(__package__, namehelp)
with resources.path(__package__, namehelp) as filehelp:
	print(filehelp)

So perhaps I am non-stupid after all. I’ll tidy it up and have a go at uploading it tomorrow.

Thanks for the machete guys! …to hack through the jungle that is Python packaging. Or more seriously, your patient reading of my posts and helpful answers.

Thanks for the comprehensive summary @layday!

According the docs in Data Files Support - setuptools 69.0.3.post20231223 documentation

If datafiles are contained in a subdirectory of a package that isn’t a package itself (no __init__.py ), then the subdirectory names (or * ) are required in the package_data argument (as shown above with "data/*.dat" ).

In your experience, is this paragraph valid for wheels? Or as you say everything in MANIFEST.in gets included?


If that is the case, maybe the best “rule of thumb” is to always have include_package_data=True and rely on tools like setuptools_scm to automatically populate the manifest…

(I am considering here that files outside of the package directory are no longer recommended/supported)

Oops, sorry! The context manager is called as_file, not as_path. It is available on Python 3.10.

1 Like

That paragraph talks about the package_data field, which behaves identically between sdists and wheels.

Included where and when building what kind of distribution using which options?

Opened docs: clarify option usage by layday · Pull Request #2835 · pypa/setuptools · GitHub.

1 Like

Hi @layday, sorry if I was not clear.

The question here is specifically targetting wheels, and “included” is used in the same context of your original post:

Which seems to mean “included in the distribution”.

If the paragraph is accurate and works identically between sdists and wheels, then it seems that setuptools would still need to have package_data set even If include_package_data=True, for the case the subdirectories where you are storing data files are not valid Python packages (e.g. missing __init__.py or with a name that is an invalid Python identifier, e.g. sub-folder).

No, the value of package_data is ignored completely when include_package_data=True, both for sdists and wheels.

  • Everything from MANIFEST.in gets pulled into the sdist regardless of the value of include_package_data.
  • Nothing from MANIFEST.in is included in the wheel, unless include_package_data=True, then package data (i.e. files inside packages) specified in MANIFEST.in are included in the wheel.

I could try putting it all in a table…

distribution  `include_package_data`  `package_data`  package data from `MANIFEST.in`
------------  ---------------------   -------------   -------------------------------
sdist         True                    ignored         included
sdist         False                   included        included
wheel         True                    included        included
wheel         False                   included        ignored

(Corrected for wheel package_data on 29/10.)

2 Likes

Thank you for the explanation @layday.

Thanks for that, it works so I am using it now.