[Distutils] __init__.py files missing from my eggs

Richard Cooper Richard at artsalliancemedia.com
Fri Nov 11 17:51:27 CET 2005


Hi,

I'm developing an application and a number of plugins for that app. The
app is frozen using py2exe and I want to distribute the plugins as eggs.
Unfortunately I'm having some difficulty. Either I'm not building the
egg correctly or I'm not importing it correctly (or possibly both). I'm
sure I'm doing something stupid, so if someone could hit me with the
cluestick I would appreciate it. 

My package structure looks roughly like this (All of the directories
contain __init__.py files which I've omitted):

My/
  Project/
    app/
      setup.py (Builds the app)
      ...
    plugin/
      setup.py (Builds all the plugins)
      Plugin1/
        ...
      Plugin2/
        ...
      Plugin3/
        ...

In the plugin's setup.py I'm doing the following for each plugin:

setup(
    name = pluginName,
    packages = ['My.Project.plugin.'+pluginName],
    namespace_packages = ['My.Project.plugin'],
    package_dir = {'':'../../..'},
    package_data = ...
)

This is producing an egg file containing the following structure:
My/
  Project/
    plugin/
      Plugin1/
        ...

Which is what I expected except that there is no __init__.py(c|o)? files
in "My" or "Project" or "plugin". It looks like if I want to use the
generated egg as a plugin then the __init__ files are required. In my
main app I'm calling:

pkg_resources.working_set.add_entry(r'path\to\my\Plugin1.egg')
x = pkg_resources.resource_string('My.Project.plugin.Plugin1',
someResource) # Where someResource exists in Plugin1.egg.

Which results in the following error:

  File
"c:\progra~1\python23\lib\site-packages\setuptools-0.6a7-py2.3.egg\pkg_r
esources.py", line 688, in resource_string
    return get_provider(package_or_requirement).get_resource_string(
  File
"c:\progra~1\python23\lib\site-packages\setuptools-0.6a7-py2.3.egg\pkg_r
esources.py", line 119, in get_provider
    __import__(moduleOrReq)
ImportError: No module named Plugin1

If I manually edit Plugin1.egg to include all the __init__.py files then
the same code in the main app works as expected.

Does anyone know where I'm going wrong? How are other people creating
namespace packages?

Thanks,

Richard


More information about the Distutils-SIG mailing list