Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to include static package files in egg via setuptools

I am trying out the Pyramid tutorial example and it's built-in setup.py file appears to be set up to add static files to the egg file but it doesn't actually happen. I've done some search and toying with the settings but I'm unable to get the desired behavior.

  1. There is a MANIFEST.in file, it contains a line: include *.ini
  2. include_package_data is set to True
  3. package_data contains the entry: { '' : ['*.ini'] }'

It doesn't seem to matter what setting I change, there appears to be no effect. I should probably mention the desired files are listed in the SOURCES.txt file.

The files I'd like to have included are in the root of the distribution's directory (where setup.py resides).

What do I seem to be missing here?

like image 625
Danny Avatar asked Jul 27 '11 18:07

Danny


1 Answers

The top level .ini files of pyramid are "non-package data files", i.e. there is no __init__.py in the directory they reside. This somehow means that they will not be included in the egg archive generated with setup.py bdist_egg, even if your conditions 1 and 2 are satisfied.

To include such "non-package data files", I think the cleanest way is to add them as data_files to setup(), e.g.

setup(
    ...
    data_files=[
        ('', [
            'development.ini',
            'production.ini',
        ]),
    ],
    zip_safe=False,
    ...
)

Then, the files will be included in the egg archive at the top level, retrievable with:

import os
import pkg_resources

dist = pkg_resources.get_distribution('MyApp')
config_file = os.path.join(dist.location, 'production.ini')
like image 52
sayap Avatar answered Sep 18 '22 15:09

sayap