[Python-Dev] Does Zip Importer have to be Special?
Phil Thompson
phil at riverbankcomputing.com
Thu Jul 24 18:55:15 CEST 2014
I have an importer for use in applications that embed an interpreter
that does a similar job to the Zip importer (except that the storage is
a C data structure rather than a .zip file). Just like the Zip importer
I need to import my importer and add it to sys.path_hooks. However the
earliest opportunity I have to do this is after the Py_Initialize() call
returns - but this is too late because some parts of the standard
library have already needed to be imported.
My current workaround is to include a modified version of _bootstrap.py
as a frozen module that has the necessary steps added to the end of its
_install() function.
The Zip importer doesn't have this problem because it gets special
treatment - the call to its equivalent code is hard-coded and happens
exactly when needed.
What would help is a table of functions that were called where
_PyImportZip_Init() is currently called. By default the only entry in
the table would be _PyImportZip_Init. There would be a way of modifying
the table, either like how PyImport_FrozenModules is handled or how
Inittab is handled.
...or if there is a better solution that I have missed that doesn't
require a modified _bootstrap.py.
Thanks,
Phil
More information about the Python-Dev
mailing list