Index: setup.py =================================================================== --- setup.py (révision 83978) +++ setup.py (copie de travail) @@ -22,6 +22,10 @@ # This global variable is used to hold the list of modules to be disabled. disabled_module_list = [] +# File which contains the directory for shared mods (for sys.path fixup +# when running from the build dir, see Modules/getpath.c) +_BUILDDIR_COOKIE = "pybuilddir.txt" + def add_dir_to_list(dirlist, dir): """Add the directory 'dir' to the list 'dirlist' (at the front) if 1) 'dir' is not already in 'dirlist' @@ -255,6 +259,11 @@ print_three_column(failed) print() + import locale + with open(_BUILDDIR_COOKIE, "wb") as f: + f.write(self.build_lib.encode(locale.getpreferredencoding(), + 'surrogateescape')) + def build_extension(self, ext): if ext.name == '_ctypes': Index: Lib/site.py =================================================================== --- Lib/site.py (révision 83978) +++ Lib/site.py (copie de travail) @@ -107,19 +107,7 @@ sys.path[:] = L return known_paths -# 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 sysconfig import get_platform - s = "build/lib.%s-%.3s" % (get_platform(), sys.version) - if hasattr(sys, 'gettotalrefcount'): - s += '-pydebug' - s = os.path.join(os.path.dirname(sys.path.pop()), s) - sys.path.append(s) - def _init_pathinfo(): """Return a set containing all existing directory entries from sys.path""" d = set() @@ -529,9 +517,6 @@ abs_paths() known_paths = removeduppaths() - if (os.name == "posix" and sys.path and - os.path.basename(sys.path[-1]) == "Modules"): - addbuilddir() if ENABLE_USER_SITE is None: ENABLE_USER_SITE = check_enableusersite() known_paths = addusersitepackages(known_paths) Index: Modules/getpath.c =================================================================== --- Modules/getpath.c (révision 83978) +++ Modules/getpath.c (copie de travail) @@ -131,6 +131,10 @@ static wchar_t *module_search_path = NULL; static wchar_t *lib_python = L"lib/python" VERSION; +/* Defined in Modules/main.c */ +extern wchar_t* _Py_char2wchar(char* arg); +extern FILE *_Py_wfopen(const wchar_t *path, const wchar_t *mode); + /* In principle, this should use HAVE__WSTAT, and _wstat should be detected by autoconf. However, no current POSIX system provides that function, so testing for @@ -396,10 +400,26 @@ /* Check to see if argv[0] is in the build directory */ wcscpy(exec_prefix, argv0_path); - joinpath(exec_prefix, L"Modules/Setup"); + joinpath(exec_prefix, L"pybuilddir.txt"); if (isfile(exec_prefix)) { - reduce(exec_prefix); - return -1; + FILE *f = _Py_wfopen(exec_prefix, L"rb"); + if (f == NULL) + errno = 0; + else { + char buf[MAXPATHLEN+1]; + wchar_t *rel_builddir_path; + size_t n; + n = fread(buf, 1, MAXPATHLEN, f); + buf[n] = '\0'; + fclose(f); + rel_builddir_path = _Py_char2wchar(buf); + if (rel_builddir_path != NULL) { + wcscpy(exec_prefix, argv0_path); + joinpath(exec_prefix, rel_builddir_path); + PyMem_Free(rel_builddir_path); + return -1; + } + } } /* Search from argv0_path, until root is found */ Index: Modules/main.c =================================================================== --- Modules/main.c (révision 83978) +++ Modules/main.c (copie de travail) @@ -101,10 +101,10 @@ PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n\ "; +FILE * +_Py_wfopen(const wchar_t *path, const wchar_t *mode) +{ #ifndef MS_WINDOWS -static FILE* -_wfopen(const wchar_t *path, const wchar_t *mode) -{ char cpath[PATH_MAX]; char cmode[10]; size_t r; @@ -119,8 +119,10 @@ return NULL; } return fopen(cpath, cmode); +#else + return _wfopen(path, mode); +#endif } -#endif static int @@ -640,7 +642,7 @@ } if (sts==-1 && filename!=NULL) { - if ((fp = _wfopen(filename, L"r")) == NULL) { + if ((fp = _Py_wfopen(filename, L"r")) == NULL) { char cfilename[PATH_MAX]; size_t r = wcstombs(cfilename, filename, PATH_MAX); if (r == PATH_MAX)