Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setuptools troubles -- excluding packages, including data files

Tags:

I'm fairly new to setuptools. I've seen a few similar questions and it drives a little bit insane that I've seemed to follow advice I saw but setuptools still does something different than what I want.

Here is the structure of my project:

. .. package1/     __init__.py     abc.py     ... tests/     __init__.py     test_package1.py LICENSE README.md RELEASE setup.py 

And here is the contents of my setup.py:

#!/usr/bin/env python import os #from distutils.core import setup from setuptools import setup, find_packages  setup(     name='package1',     version='1.1',     test_suite="tests",     packages=find_packages(exclude=['tests']),         include_package_data=True,     package_data = {         '': ['LICENSE', 'README.md5', 'RELEASE']     },    ) 

Also, in my manifest file I have:

include LICENSE include RELEASE include README.md 

I build the tar with:

python setup.py sdist 

I want to:

  1. Exclude tests directory from the source distribution;
  2. Have LICENSE, README.md, RELEASE files in the site-packages directory, either at the top level, or inside the package1 directory (at this point I will agree to either).

Instead, here's what happens:

  1. tests directory remains to be in the created tar archive and gets installed to the site-packages;
  2. Files are copied to the archive, but do not get installed to the site-packaged directory of the package.

I am out of ideas, can someone explain to me what I am doing wrong and how to fix it?

like image 342
0x4B1D Avatar asked Dec 19 '11 04:12

0x4B1D


People also ask

How do you include data in a Python package?

Place the files that you want to include in the package directory (in our case, the data has to reside in the roman/ directory). Add the field include_package_data=True in setup.py. Add the field package_data={'': [... patterns for files you want to include, relative to package dir...]} in setup.py .

What is Setuptools package in Python?

Setuptools is a collection of enhancements to the Python distutils that allow developers to more easily build and distribute Python packages, especially ones that have dependencies on other packages. Packages built and distributed using setuptools look to the user like ordinary Python packages based on the distutils .

Do I need to install Setuptools?

you generally don't need to worry about setuptools - either it isn't really needed, or the high-level installers will make sure you have a recent enough version installed; in this last case, as long as the operations they have to do are simple enough generally they won't fail.

Is Setuptools included in Python?

Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). It includes: Python package and module definitions.


1 Answers

find_packages uses fnmatchcase for its exclude filtering. You can test if your exclusion pattern matches a package name as follows:

>>> from fnmatch import fnmatchcase >>> fnmatchcase('my.package.name.tests', 'tests') False 

Assuming all the tests in your project live in package names ending in tests or subpackages of those packages, the following should suffice to exclude all the test code:

setup(     name='package1',     version='1.1',     packages=find_packages(exclude=['tests', '*.tests', '*.tests.*']),     ) 

To also exclude the tests folder from source distributions, add the following to MANIFEST.in:

recursive-exclude tests * 
like image 78
oby1 Avatar answered Sep 20 '22 13:09

oby1