[Python-Dev] Dropping init.py requirement for subpackages (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Fri Apr 28 18:11:23 CEST 2006


Thomas Wouters wrote:

Indeed! I hadn't realized that, although I might've if I'd been able to find where Modules is put on sys.path. And, likewise, I would do as you suggest (which feels like the right thing) if I could only find out where Modules is put on sys.path :) I don't have time to search for it today nor, probably, this weekend (which is a party weekend in the Netherlands.) I'll get to it eventually, although a helpful hint from an old-timer who remembers as far back as Modules/Setup would be welcome. :)

With some debugging, I found it out: search_for_exec_prefix looks for the presence of Modules/Setup; if that is found, it strips off /Setup, leaving search_for_exec_prefix with -1. This then gets added to sys.path with

    /* Finally, on goes the directory for dynamic-load modules */
    strcat(buf, exec_prefix);

I wasn't following exactly, so I might have mixed something up, but... it appears that this problem here comes from site.py adding the build directory for the distutils dynamic objects even after Modules. The site.py code is

XXX This should not be part of site.py, since it is needed even when

using the -S option for Python. See http://www.python.org/sf/586680

def addbuilddir(): """Append ./build/lib. in case we're running in the build dir (especially for Guido :-)""" from distutils.util import get_platform s = "build/lib.%s-%.3s" % (get_platform(), sys.version) s = os.path.join(os.path.dirname(sys.path[-1]), s) sys.path.append(s)

I would suggest fixing #586680: Add build/lib.* before adding dynamic-load modules, by moving the code into Modules/getpath.c. You should be able to use efound < 0 as an indication that this is indeed the build directory.

Regards, Martin



More information about the Python-Dev mailing list