PEP 302 + zipimport:
- new import hooks in import.c, exposed in the sys module
- new module called 'zipimport'
- various changes to allow bootstrapping from zip files
I hope I didn't break the Windows build (or anything else for that
matter), but then again, it's been sitting on sf long enough...
Regarding the latest discussions on python-dev: zipimport sets
pkg.__path__ as specified in PEP 273, and likewise, sys.path item such as
/path/to/Archive.zip/subdir/ are supported again.
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 54b57c7..03646a5 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -365,6 +365,7 @@
char *path = getenv("PATH");
char *prog = Py_GetProgramName();
char argv0_path[MAXPATHLEN+1];
+ char zip_path[MAXPATHLEN+1];
int pfound, efound; /* 1 if found; -1 if found build directory */
char *buf;
size_t bufsz;
@@ -483,6 +484,18 @@
else
reduce(prefix);
+ strncpy(zip_path, prefix, MAXPATHLEN);
+ if (pfound > 0) { /* Use the reduced prefix returned by Py_GetPrefix() */
+ reduce(zip_path);
+ reduce(zip_path);
+ }
+ else
+ strncpy(zip_path, PREFIX, MAXPATHLEN);
+ joinpath(zip_path, "lib/python00.zip");
+ bufsz = strlen(zip_path); /* Replace "00" with version */
+ zip_path[bufsz - 6] = VERSION[0];
+ zip_path[bufsz - 5] = VERSION[2];
+
if (!(efound = search_for_exec_prefix(argv0_path, home))) {
if (!Py_FrozenFlag)
fprintf(stderr,
@@ -521,6 +534,7 @@
defpath = delim + 1;
}
+ bufsz += strlen(zip_path) + 1;
bufsz += strlen(exec_prefix) + 1;
/* This is the only malloc call in this file */
@@ -541,6 +555,10 @@
else
buf[0] = '\0';
+ /* Next is the default zip path */
+ strcat(buf, zip_path);
+ strcat(buf, delimiter);
+
/* Next goes merge of compile-time $PYTHONPATH with
* dynamically located prefix.
*/