Skip to content

bpo-45395: Make custom frozen modules additions instead of replacements. #28778

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

Merged

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Oct 6, 2021

Currently custom modules (the array set on PyImport_FrozenModules) replace all the frozen stdlib modules. That can be problematic and is unlikely to be what the user wants. This change treats the custom frozen modules as additions instead. They take precedence over all other frozen modules except for those needed to bootstrap the import system. If the "code" field of an entry in the custom array is NULL then that frozen module is treated as disabled, which allows a custom entry to disable a frozen stdlib module.

This change allows us to get rid of is_essential_frozen_module() and simplifies the logic for which frozen modules should be ignored.

https://bugs.python.org/issue45395

@gvanrossum
Copy link
Member

Same comment as for #28776 -- do we have any examples of apps that actually use this feature? Would they benefit from this change?

@ericsnowcurrently
Copy link
Member Author

I don't have examples, other than that PyImport_FrozenModules is what Tools/freeze/makefreeze.py uses. (Given @malemburg's requests elsewhere, Tools/freeze appears to be used in the wild.) The division between the kinds of frozen modules I introduce here allows us to simplify some of the logic in import.c, so I consider it worth doing regardless of any benefit to projects that set custom frozen modules. The only catch is that the existence of PyImport_FrozenModules complicates matters if we leave it as an override instead of making it additions.

@gvanrossum
Copy link
Member

Aha, so then we should just make sure that Tools/freeze still works. :-)

@ericsnowcurrently ericsnowcurrently force-pushed the frozen-modules-custom-additions branch from 87b8b98 to 600d521 Compare October 27, 2021 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants