Creating "missing" __init__.py files is wrong

Fred Drake avatarFred Drake created an issue

When installing zope.testrunner using zc.buildout with distribute 0.6.15, I noticed this surprising message in the output:

Getting distribution for 'zope.testrunner'.
package init file 'src/zope/testrunner/testrunner-ex/__init__.py' not found (or not a regular file)
Creating missing __init__.py for zope.testrunner.testrunner-ex
Got zope.testrunner 4.0.3.

This is a wrong thing to do. The fact that there's a hyphen in the supposed package name makes that a little more obvious, and may be why I noticed it this time, but it's wrong for distribute to determine for me that a directory nested inside a package is a package as well, even if it includes .py files.

Python determines that a directory is a package based on the presence of the init.py file; if the developer didn't put one there, he shouldn't expect that directory to be treated as code. In a case like this, the directory most likely contains data, either to be loaded by the code during operation, or during tests. Adding that file during installation means that the directory is likely to be handled differently during development/testing and production use. Though it's unlikely to be a serious practical problem, when it is a problem it will be difficult to diagnose ("expensive").

Comments (4)

  1. Zooko O'Whielacronx

    The Twisted plugin mechanism relies on a directory named "twisted/plugin/" which contains .py files but does not contain a __init__.py file. If you add an __init__.py file to it, this would break the plugin finder mechanism.

  2. Anonymous
  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.