Skip to content

Rust API for pyinitconfig - #6173

Open
Person-93 wants to merge 35 commits into
PyO3:mainfrom
Person-93:pyinitconfig
Open

Person-93 wants to merge 35 commits into
PyO3:mainfrom
Person-93:pyinitconfig

Conversation

@Person-93

Copy link
Copy Markdown
Contributor

Adds a rust API to initialize the embedded interpreter with configuration.

Closes #6153

@Person-93 Person-93 changed the title Ruat API for pyinitconfig Rust API for pyinitconfig Jun 30, 2026
@Person-93
Person-93 force-pushed the pyinitconfig branch 4 times, most recently from 2f0308c to f15f4fc Compare June 30, 2026 14:44
@ngoldbaum

Copy link
Copy Markdown
Contributor

According to codecov almost none of the API surface is tested. Can you please make sure there's coverage for all the InitConfig methods you're proposing to add?

@Person-93
Person-93 force-pushed the pyinitconfig branch 8 times, most recently from 57b35c8 to f622003 Compare July 1, 2026 07:45
Comment thread src/init_config.rs Resolved
Comment thread src/init_config.rs Resolved
@codspeed

codspeed Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Unable to measure the execution of 4 benchmarks

These benchmarks measured no execution time, so their results are not comparable and count as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

✅ 151 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing Person-93:pyinitconfig (e5d17f4) with main (d9a8b2b)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@Person-93

Copy link
Copy Markdown
Contributor Author

@codspeedbot fix this regression

@Person-93

Person-93 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Maintainers (@ngoldbaum), is test coverage OK. Do we need a test case which deliberately causes initialization to fail so the error handling code is covered?

@Person-93
Person-93 force-pushed the pyinitconfig branch 2 times, most recently from c8f66ec to 99b41b0 Compare July 30, 2026 01:35
@Person-93
Person-93 force-pushed the pyinitconfig branch 3 times, most recently from 141a505 to 7931138 Compare August 7, 2026 05:08

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, some various thoughts and suggestions. Sorry it took a long time to get around to this one.

Comment thread src/init_config.rs Resolved
Comment thread src/init_config.rs Resolved
Comment thread tests/test_init_config_init_fail.rs Resolved
Comment thread tests/test_init_config_add_module.rs Resolved
Comment thread src/init_config.rs Resolved
@Person-93
Person-93 force-pushed the pyinitconfig branch 3 times, most recently from 5ca5f0a to 5c01d67 Compare August 27, 2026 22:59

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this looks good to me!

@Person-93

Copy link
Copy Markdown
Contributor Author

I'm ignoring the test_init_fail testcase for now.

Comment thread tests/test_init_config_init_fail.rs Resolved
Comment thread src/interpreter_lifecycle.rs Resolved
@Person-93

Copy link
Copy Markdown
Contributor Author

@ngoldbaum what happened to CI for this PR? I see that you cancelled them after they were stuck for a few hours, so what happens now?

@ngoldbaum

Copy link
Copy Markdown
Contributor

Maybe try debugging locally or in your fork? I canceled CI because it was blocking CI on other PRs.

@Person-93

Copy link
Copy Markdown
Contributor Author

@ngoldbaum , I tried running CI again to see if it was a transient issue or if I could get logs, and I've confirmed that the pytest test_comparisons.py is what hangs. Please cancel CI again; sorry for the trouble.

@ngoldbaum

Copy link
Copy Markdown
Contributor

I usually enable actions in my fork of a project when I’m limited by permissions like you’re hitting here.

@Person-93

Copy link
Copy Markdown
Contributor Author

@davidhewitt @bschoenmaeckers is there still anything blocking this?

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the extremely delayed review. I took a pass at this with a local AI agent and dug up a few rough edges worth cleaning before we merge.

Comment thread src/init_config.rs Resolved
Comment thread src/init_config.rs Resolved
const ALREADY_INIT_MESSAGE: &str = "interpreter is already initialized";

let mut already_initialized = true;
START.get_or_try_init(|| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Local AI review suggests that calling Python::attach after a failed call to initialize_from_config may be unsound.

Some ideas:

  • We could make this initialization API unsafe and require the caller to be extremely careful to not call Python::attach until a sucessful reattempt at initialization
  • We could go further split it into fallible / infallible forms, making the infallible form abort inside get_or_try_init on failure so Python::attach never makes it past wait_for_initialization().
  • We could store the error in START and make all calls to Python::attach fail.

I'm not sure what's the best choice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Local AI review suggests that calling Python::attach after a failed call to initialize_from_config may be unsound.

Can you elaborate? Why is this unsound? It should work the same as any other initial call to Python::attach.

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.

Initialize python from Config

4 participants