[issue40333] Request for multi-phase initialization API to run code after importlib init

STINNER Victor report at bugs.python.org
Mon Apr 27 09:40:17 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

> 5) Remove PathFinder if filesystem imports are disabled

Extract of importlib._bootstrap_external._install():

def _install(_bootstrap_module):
    ...
    sys.meta_path.append(PathFinder)

PathFinder is always registered. So you are not only asking for an API to customize sys.path, but also to customize sys.meta_path, right?


> A super minor paper cut is the lack of a PyConfig_SetBytesString() variant for PyWideStringList_Append(). It was slightly annoying having to convert a POSIX char* path to a wchar_t* since paths on POSIX are bytes.

Would you mind to open a separated issue for this feature request?


> It would be useful if there were some kind of PyErr API that returned a PyString (or PyStatus) and was guaranteed to work before main is initialized.

Are you asking to format the current exception as a string? Something like traceback.format_exc() but as a C function?


> Overall, the new code in PyOxidizer is much, much cleaner! Thanks again for the new API!

You're welcome. PyOxidizer is a good use case for PEP 587 (PyConfig). Sadly, you have to drop support for Python 3.8 and older, or maintain two code paths. I saw many projects which maintains two code paths: one for Python 3 (use Unicode and a few other changes), one for Python 2 (use bytes).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40333>
_______________________________________


More information about the Python-bugs-list mailing list