[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules)

STINNER Victor report at bugs.python.org
Tue Jan 19 11:35:33 EST 2021


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

Ronald:
> I think we agree on that point: my counter proposal won’t work in the faulthandler scenario, and may be problematic in the Py_FatalError case as well.

The API providing a tuple of str (sys.module_names) works with the 4 use cases that I listed:

* faulthandler/Py_FatalError (dump third party extensions of sys.modules)
* isort (group stdlib imports)
* trace (don't trace stdlib modules)
* pypt (ignore stdlib modules when computing dependencies)


Ronald:
> Although that might give misleading answers with tools like pyinstaller/py2exe/py2app that package an application and its dependencies into a single zipfile.

These tools worked for years without sys.module_names and don't need to be modified to use sys.module_names.

sys.module_names is well defined, extract of its doc:

"The list is the same on all platforms. Modules which are not available on some platforms and modules disabled at Python build are also listed."

These packaging tools may require further checks than just checking if the name is in sys.module_names. These tools are complex anyway ;-)

----------

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


More information about the Python-bugs-list mailing list