What's the correct way to exclude files from a python wheel distribution package?
Editing the MANIFEST.in
does not have any effect and I can't find information about this detail.
What's the correct way to exclude files from a python wheel distribution package?
Editing the MANIFEST.in
does not have any effect and I can't find information about this detail.
I assume you are asking how to exclude __pycache__
directory and *.pyc
while packaging into a wheel file using bdist/sdist. If so, the following manifest commands worked for me.
global-exclude */__pycache__/*
global-exclude *.pyc
If you are noticing this as part of a pip install
one thing to do is figure out if the .pyc
files are part of the build or part of the install.
To distinguish between the two options have a look at the files in the build/
directory. If you see pyc files in there then you know it's part of the wheel and the MANIFEST.in
solution from @Sreekhar will work to exclude them.
However if there are no .pyc
files in the build/
directory then the pyc files are created during the install. To fix this you simply need to add the --no-compile
option to pip install
.
I have never had that problem.
Here's an excerpt from my setup.py
:
name='aenum',
version='2.0.2',
url='https://bitbucket.org/stoneleaf/aenum',
packages=['aenum'],
package_data={
'aenum' : [
'LICENSE',
'README',
'doc/aenum.rst',
'doc/aenum.pdf',
]
},
include_package_data=True,
license='BSD License',
description="Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants",
long_description=long_desc,
provides=['aenum'],
author='Ethan Furman',
author_email='...',
classifiers=[
...
],
and my MANIFEST.in
:
exclude aenum/*
include setup.py
include README
include aenum/__init__.py
include aenum/test.py
include aenum/test_v3.py
include aenum/LICENSE
include aenum/CHANGES
include aenum/README
include aenum/doc/aenum.pdf
include aenum/doc/aenum.rst
I would say the exclude aenum/*
is what does the trick for me, so probably an exclude <package_name>/__pycache__
would work for you.
find_packages
from setuptools does that, additionally you may specify direrctories to exclude, like:
packages=find_packages(exclude=['docs', 'tests']),
But compiled artifacts (pyc files and __pycache__
dir) should be excluded automatically.
find_packages(exclude=[])
only filters at the package level –
Farreaching Why would you be doing that? The __pycache__ directory will be generated anyway when a project is run for the first time on the target machine. It's simply an optimised bytecode representation of Python.
But anyway, you can write an script that unpacks the .whl file and does the modifications and then repacks the wheel.
© 2022 - 2024 — McMap. All rights reserved.