[python-win32] distutils question

Jeff Shannon jeff@ccvcorp.com
Fri, 29 Mar 2002 09:28:15 -0800


> > robin and jim wrote:
>
> > > The question is: how should setup.py be implemented to automate this so
> that
> > > an __init__ module is placed in each directory as it is created during
> the
> > > build?
> >
> > Well IMHO this is not a task for setup.py but for module writer.
> >
> > Niki Spahiev
>
> Perhaps you are correct, but if setup.py is to install a package, I want to
> make it do so without additional user effort (e.g., manually adding __init__
> modules or updating the Windows registry).  Some packages do this; I just
> have not, yet, discovered how they do so.

Creating the __init__.py is part of creating a package.  It isn't part of installing it -- it should be done *before* using distutils to bundle up the package.  Indeed, it's the presence of an __init__.py that *makes* a set of modules into a package, and __init__.py is used to control a number of
details of how that package behaves (what modules it exports, etc).

Note that Python uses the directory structure as part of the package structure.  If I'm reading what you're doing properly, it looks to me like you may wish, instead of putting an __init__.py in each of a series of otherwise empty directories (empty of Python files anyhow), to change your directory
structure so that your \processor directory is a direct subdirectory of site-packages.  Then, you would import your package as

import processor.foo

possibly renaming processor to be a little more specific.  Keep in mind that each segment of a name in an import statement (except the final one), is asking the interpreter to find a directory of that name and import the __init__.py file found in that directory.

Jeff Shannon
Technician/Programmer
Credit International