-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-42955: Add sys.modules_names #24238
Conversation
The most important part of the PR is the It ignores the following modules. I'm not sure if we should ignore them or not.
I chose to ignore these modules to make the list looking nicer. But it makes the list "not correct". For Windows, I'm lazy and hardcoded the list since it's short and is no updated often:
|
With this PR, sys.module_names contains 295 names. It should contain the exact same number on any platform. A module is listed even if it's disabled explicitly at build time. |
I updated the documentation:
I also fixed the code to also list sub-packages: the new module count is now 313. Should we also list package sub-modules like asyncio.base_events? |
ensurepip._bundled is not included since it doesn't contain any .py file, only .whl files. |
My bad, it's listed: there is |
@pablogsal @serhiy-storchaka: Ok, this PR is now ready for your review :-) I updated the documentation to explicit which modules are included and which are excluded:
|
There is the dump of sys.module_names, 296 modules: http://paste.alacon.org/47013 |
I modified the script to not ignore any module: with such hack, sys.module_names contains 1869 names. List of the 1575 ignored modules: http://paste.alacon.org/47014 I don't think that we should include these test modules and sub-modules. IMO only listing parent packages is enough. It's easy to detect that "asyncio" is a stdlib module from the "asyncio.base_events" name. |
I rebased my PR, squashed commits, and fixed a few comments of Tools/scripts/generate_module_names.py. |
"make regen-module-names" should be tested on macOS and FreeBSD, I'm not sure that setup.py reports properly missing modules in all cases. |
On FreeBSD, I wrote a short script to check which modules can be imported or not. Only 9 modules cannot be import on my FreeBSD VM:
There are 5 modules specific to Windows (_msi, msilib, msvcrt, winreg, winsound), spwd doesn't exist on FreeBSD, _tkinter probably needs a missing build dependency (and turtle needs it). import_all.py script:
|
On Linux (on my Fedora 33 laptop), only 5 modules of sys.module_names cannot be imported, the 5 Windows specific modules:
|
On Windows, 22 modules cannot be imported:
Oh, there are 3 built-in modules on Windows which are not listed on Linux:
I chose to exclude _xxsubinterpreters in Tools/scripts/generate_module_names.py:
I would prefer to have the same list on Linux and Windows. |
I updated the PR to add 3 modules (_winapi, _xxsubinterpreters, nt). sys.module_names now contains 299 modules on all platforms. Note: I checked that all built-in modules listed in Modules/config.c on Linux and PC/config.c on Windwos are listed by Python/module_names.h. |
@ronaldoussoren: The important part of this PR is the documentation. Do you think that it clearly describe what can found in the list and limitations? Or do you disagree with including modules which are not available? |
I rebased this PR which made it way simpler to only focus on adding the sys.module_names list. I already merged the uncontroversial part in a private API. I started with a private list _Py_module_names in a new Python/module_names.h file: cad8020 It unblocked bpo-42923 to dump third party extension modules on a fatal error. |
I enhanced Tools/scripts/generate_module_names.py to reorder the list and to avoid duplicates. sysmodule.c no longer has to remove duplicates at runtime. |
Hum, the generated list can be sorted as well. I simplified the runtime construction of sys.module_names even more. |
Add sys.module_names, containing the list of the standard library module names.
I updated the PR to take @pablogsal review in account:
Sorry, I amended my commit to be able to modify the commit message. |
@ronaldoussoren @serhiy-storchaka @pablogsal: I plan to merge this PR next monday. Please tell me if you want to review it before that. When I created https://bugs.python.org/issue42955 I wasn't sure if sys.module_names would be useful, but then I found tons of use cases, and multiple persons told me that they need it for their projects (see the issue, I listed all of them). Maybe we could add in addition a way to get paths of the stdlib, but I suggest to do that separately. Multiple use cases cannot import modules, but need to check the module name. |
Add sys.module_names, containing the list of the standard library module names.
Add sys.module_names attribute: the list of the standard library
module names.
https://bugs.python.org/issue42955