Excluding a top-level directory from a setuptools package

自闭症网瘾萝莉.ら 提交于 2019-12-02 23:55:14
flexiondotorg

We use the following convention to exclude 'tests' from packages.

setup(
   name="project",
   packages=find_packages(exclude=("tests",)),
   include_package_data=True, 
   test_suite='nose.collector',
)

We also use MANIFEST.in to better control what include_package_data=True does.

I have the following in my setup.py...

setup(name='pyfoo',
      version="1.0.2",
      description='Example for stack overflow',
      url='http://stackoverflow.com/',
      author='David Michael Pennington',
      author_email='mike /|at|\ pennington.net',
      license='GPL',
      platforms='any',
      keywords='Stack Overflow Example',
      entry_points = "",
      long_description=read('README.rst'),
      include_package_data=True,  # Checks MANIFEST.in for explicit rules
      #                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      packages=find_packages(),
      use_2to3=True,
      zip_safe=False,
      setup_requires=["setuptools_hg"],

I had a doc/ directory that was getting massive due to the number of images I had in it; this meant that the size of my sdist was growing over 500kB. Originally I had this in my MANIFEST.in...

include LICENSE CHANGES README.rst requirements.txt
recursive-exclude * __pycache__
recursive-exclude * *.pyc
recursive-exclude * *.pyo
recursive-exclude * *.orig

The only thing I had to do to exclude my doc directory was this line at the bottom of MANIFEST.in...

prune doc*

Using prune doc* suddenly removed all my doc/ directory from the sdist tarball. So, it looks like you just need to use this in a MANIFEST.in file...

prune tests*

This is what I found in setuptools manual:

from setuptools import setup, find_packages
...
packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),

In my case the following was enough to exclude top-level tests directory:

packages = find_packages(exclude=["tests.*", "tests"]),

Ug, setuptools makes this really tricky :(

I don't know if this is what you want, but one project I work on uses a combination of two things:

from setuptools import setup, find_packages
...
packages = find_packages(exclude=['tests']),
data_files = os.walk(path_to_files),

For similar purpose, my collegue wrote setuptools-dummy package: http://github.com/ella/setuptools-dummy/tree/master

Take a look at setuptools_dummy, modify excludes to your needs and it should work. If not, open an issue ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!