Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are 'package data' files?

I've created package with distutils including package data. When i look in tar.gz of my package I see expected files, BUT after package installation (by pip or by 'python setup.py install') there is no any package data. Only python scripts included. My setup.py is:

# py3.3
#from packaging.core import setup
# py3.2
from distutils.core import setup

setup(
    name = 'mypkg',
    version = '0.7dev',
    author = 'Projekt Alef',
    author_email = '[email protected]',
    packages = [
        'my_pkg',
        'my_pkg/tests',
        'my_pkg/plugins',
    ],
    #scritps=['bin/setup.sh',],
)
like image 603
xliiv Avatar asked Mar 11 '12 11:03

xliiv


People also ask

Where are Python data packages stored?

Files which are to be used by your installed library (e.g. data files to support a particular computation method) should usually be placed inside of the Python module directory itself. E.g. in our case, a data file might be at funniest/funniest/data. json .

What is Python package data?

What is "package data"? Broadly, package data is any files that you want to include with your Python package that aren't Python source files. An example is a TOML default configuration file that you want to be able to produce for users.

What is package data in setup py?

package_data. By default, include_package_data considers all non .py files found inside the package directory ( src/mypkg in this case) as data files, and includes those that satisfy (at least) one of the above two conditions into the source distribution, and consequently in the installation of your package.

How do I include a file in a 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 .


1 Answers

Package data to be installed should be included as a package_data={} dictionary passed to the setup() function. Each dictionary gives the module (package) to be installed and a list of patterns to find data files to be installed from/with it, such as:

package_data = {
    'exceptional_middleware': [ 'templates/http_responses/*.html' ],
}

Additionally, you may prefer not to install your tests (just drop pkg/tests from the packages list).

like image 115
James Aylett Avatar answered Sep 28 '22 06:09

James Aylett