[Python-Dev] Dropping __init__.py requirement for subpackages

Gustavo Carneiro gjcarneiro at gmail.com
Thu Apr 27 15:42:03 CEST 2006


On 4/26/06, Guido van Rossum <guido at python.org> wrote:
[...]

> So I have a very simple proposal: keep the __init__.py requirement for
> top-level pacakages, but drop it for subpackages. This should be a
> small change. I'm hesitant to propose *anything* new for Python 2.5,
> so I'm proposing it for 2.6; if Neal and Anthony think this would be
> okay to add to 2.5, they can do so.


  Damn these threads are so quick they are born and die off in 24 hours and
don't give enough time for people to comment :(

  I'm a bit late in the thread, but I'm +1 (for 2.5) for the following
reason.  There are mainly two use cases for having a couple of modules
foo.bar, and foo.zbr:

  1. foo.bar and foo.zbr are both part of the same _package_, and are
distributed together;

  2. foo.bar and foo.zbr are two independent modules, distributed
separately, but which share a common 'foo' _namespace_, to denote
affiliation with a project.

  The use case #1 is arguably more common, but use case #2 is also very
relevant.  It happens for a lot of GNOME python bindings, for example, where
we used to have gnome, gnome.ui, gnome.vfs, gnome.applet, etc.

  Now the problem.  Suppose you have the source package python-foo-bar,
which installs $pythondir/foo/__init__.py and $pythondir/foo/bar.py.  This
would make a module called "foo.bar" available.  Likewise, you can have the
source package python-foo-zbr, which installs $pythondir/foo/__init__.py and
$pythondir/foo/zbr.py.  This would make a module called "foo.zbr" available.

  The two packages above install the file $pythondir/foo/__init__.py.  If
one of them adds some content to __init__.py, the other one will overwrite
it.  Packaging these two packages for e.g. debian would be extremely
difficult, because no two .deb packages are allowed to intall the same file.

  One solution is to generate the __init__.py file with post-install hooks
and shell scripts.  Another solution would be for example to have only
python-foo-bar install the __init__.py file, but then python-foo-zbr would
have to depend on python-foo-bar, while they're not really related.

  I hope I made the problem clear enough, and I hope people find this a
compelling argument in favour of eliminating the need for __init__.py.


  Regards,

Gustavo Carneiro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060427/0dfbd77a/attachment.htm 


More information about the Python-Dev mailing list