-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-142417: Add PyInitConfig_SetInitCallback() function #142420
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
base: main
Are you sure you want to change the base?
Conversation
Add init_callback and init_callback_arg members to PyConfig.
|
Current documentation:
|
|
@indygreg: Hi, would such C API fit your needs for PyOxidizer? |
That is extremely vague. If there are no concrete promises about what's available, and what APIs can be called, new versions of CPython are theoretically allowed to "break" callers. Is the callback better than restoring older private "multi-phase" API? Would it be better to add API specifically for adding a simple metapath entry? |
It's vague on purpose, but you're right that it should be better specified. Python 3.13 documentation specify what is available at the "core" phase and what is the "main" phase: https://docs.python.org/3.13/c-api/init_config.html#multi-phase-initialization-private-provisional-api
Good question. I just tested: you can import built-in modules at this point, but only built-in modules.
The old API (Python 3.13 and older) allows not executing the "main" initialization phase, but IMO it makes no sense (there is not use case for that). What's needed is only to inject code (callback) between the "core" and the "main" initialization phase. IMO a callback API better fits the use case.
I'm not aware of other points which would be interesting during the initialization.
The bypy code to inject the The PyOxidizer code is also complex: |
I completed the documentation using Python 3.13 doc. |
That's worrying: it means that if we rewrite a module in Python, we break people's code. (For example, the
What's worrying for metapath entries is that "importlib", "Path Configuration" and " This does look like it should be unstable at least. But, I believe it would be best to bring the old private API back (deprecated) while a better alternative is designed: |
These things changed multiple times since PEP 587 (PyConfig C API) has been implemented, and it was just fine with users of the "Multi-Phase Initialization Private Provisional API". For example, the path configuration has been reimplemented in Python in Python 3.11 (
Well, a provisional API has a different backward compatibility contract: https://docs.python.org/dev/glossary.html#term-provisional-API
Anyway, the API has already been removed from Python 3.14. |
It also says:
What are the serious fundamental flaws that were missed? |
Add init_callback and init_callback_arg members to PyConfig.
📚 Documentation preview 📚: https://cpython-previews--142420.org.readthedocs.build/