[Import-SIG] [Python-ideas] My objections to implicit package directories

Nick Coghlan ncoghlan at gmail.com
Tue Mar 13 22:20:20 CET 2012

On Mar 14, 2012 6:25 AM, "Eric Snow" <ericsnowcurrently at gmail.com> wrote:
> Here's one idea to address the PEP 395 concern.
> Traverse up the directory tree until you hit one of the following three
> * there is no __init__.py in the current directory (in the case where
> there was one adjacent to the original module)
> * current directory is on sys.path
> * setup.py is in the current directory
> All these indicate that you have left the package.  If you make it to
> the FS root, the module would not be considered to exist in a package.
> The third option is the new idea.  As a bonus, using setup.py as a
> marker would also nudge people toward packaging.
> -eric

Alas, that doesn't work - to avoid slowing down normal startup too much,
there needs to be a *fast* check that tells the interpreter immediately
whether or not it is inside a package and needs to search the filesystem
for the parent of the package directory. That's only possible when each
package directory has an explicit marker.

Instead, I'll have to put the search in importlib so the import error
message can tell the user which directory to switch to and what "python -m"
command to use to run their module. I do like the idea of using
setup.py/cfgas an extra marker, though.

I'll be moving house over the next few days and only have mobile internet
at home for a while after that, so I'll probably revise PEP 395 some time
after the next 3.3 alpha.


Sent from my phone, thus the relative brevity :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20120314/3ca4de42/attachment.html>

More information about the Import-SIG mailing list