mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Add zipimport hook at the end just in case (#280)
In Python, the zipimport path hook is usually the first entry in sys.path_hooks, so that any zip files in sys.path can be handled correctly. In the APE, the zipimport hook was removed because it was relatively slow compared to Cosmopolitan when it came to handling imports from the APE's internal zip store. However, some python scripts (for example when pip installs some packages) modify sys.path to consider a local zip file, and then attempt to import from it. This change prevents potential "unable to import" errors in such cases, so that Actually Portable Python can be more of a drop-in improved replacement.
This commit is contained in:
parent
9cabdaabfd
commit
2fe8571010
2 changed files with 5 additions and 2 deletions
5
third_party/python/Python/import.c
vendored
5
third_party/python/Python/import.c
vendored
|
@ -152,8 +152,9 @@ _PyImportZip_Init(void)
|
|||
"# can't import zipimport.zipimporter\n");
|
||||
}
|
||||
else {
|
||||
/* sys.path_hooks.insert(0, zipimporter) */
|
||||
err = PyList_Insert(path_hooks, 0, zipimporter);
|
||||
/* sys.path_hooks.append(zipimporter) */
|
||||
/* add this hook in case of import from external zip */
|
||||
err = PyList_Append(path_hooks, zipimporter);
|
||||
Py_DECREF(zipimporter);
|
||||
if (err < 0) {
|
||||
goto error;
|
||||
|
|
2
third_party/python/Python/pylifecycle.c
vendored
2
third_party/python/Python/pylifecycle.c
vendored
|
@ -295,6 +295,8 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
|
|||
Py_XDECREF(warnings_module);
|
||||
}
|
||||
|
||||
_PyImportZip_Init();
|
||||
|
||||
if (!Py_NoSiteFlag)
|
||||
_Py_InitSite(); /* Module site */
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue