Skip to content

[cpyrt] Move Python interpreter embedding out of cpyrt - #139

Open
guitargeek wants to merge 1 commit into
compiler-research:mainfrom
guitargeek:tpython-extraction
Open

guitargeek wants to merge 1 commit into
compiler-research:mainfrom
guitargeek:tpython-extraction

Conversation

@guitargeek

Copy link
Copy Markdown
Collaborator

cppjit is a Python extension library, not an embedding library. Remove the PyConfig/Py_InitializeFromConfig fallback from cpyrt's private Initialize() and let it fail gracefully when the interpreter was not initialized by the embedding application, instead of initializing a bare interpreter from inside an extension module.

Along the same boundary, move the "access to the python interpreter" functions out of cpyrt entirely: Import(), Exec(), ExecScript() and Prompt() use none of cppjit's proxy machinery. Also drops the gMainDict bookkeeping they depended on, and exposes the extension module itself via GetThisModule() for an embedding framework to attach imported modules to.

cppjit is a Python extension library, not an embedding library. Remove
the PyConfig/Py_InitializeFromConfig fallback from cpyrt's private
Initialize() and let it fail gracefully when the interpreter was not
initialized by the embedding application, instead of initializing a
bare interpreter from inside an extension module.

Along the same boundary, move the "access to the python interpreter"
functions out of cpyrt entirely: Import(), Exec(), ExecScript() and
Prompt() use none of cppjit's proxy machinery. Also drops the gMainDict
bookkeeping they depended on, and exposes the extension module itself
via GetThisModule() for an embedding framework to attach imported
modules to.

@aaronj0 aaronj0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@aaronj0

aaronj0 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Is there a way to test usage of GetThisModule from an placeholder embedding application?

@guitargeek

Copy link
Copy Markdown
Collaborator Author

In principle we could do that, but I wouldn't require a test for a one-line getter

@aaronj0

aaronj0 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

My intent was less on testing the API and more to show an example of how that could be used by a client

@guitargeek

Copy link
Copy Markdown
Collaborator Author

Ah! Okay, I'll come back to this once we wrapped up the review on the ROOT side with Vincenzo

This branch has not been deployed

No deployments
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.

2 participants