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 ignorespackage_data
- If
include_package_data=False
(the default), it also includes files frompackage_data
- setuptools includes everything from
- If you’re building a wheel:
- setuptools includes package data entries from
MANIFEST.in
IFFinclude_package_data=True
- If
include_package_data=True
it ignorespackage_data
- If
include_package_data=False
(the default), it includes files frompackage_data
- setuptools includes package data entries from
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 thepackage_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.
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?
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 ofinclude_package_data
. - Nothing from
MANIFEST.in
is included in the wheel, unlessinclude_package_data=True
, then package data (i.e. files inside packages) specified inMANIFEST.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.)
Thanks for that, it works so I am using it now.