Skip to content

Rust API for pyinitconfig - #6173

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

Rust API for pyinitconfig#6173
Person-93 wants to merge 23 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 Outdated
Comment thread src/init_config.rs Outdated
@codspeed-hq

codspeed-hq Bot commented Jul 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 141 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing Person-93:pyinitconfig (2530e05) with main (7164282)

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 Outdated
Comment thread src/init_config.rs
Comment on lines +57 to +58
let result =
unsafe { PyInitConfig_GetExitCode(self.0.as_ptr(), &raw mut exitcode) };

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.

If initialization fails, is it safe to try again? (Either with the same config object or a new one.)

I assume that the answer is probably yes we can assume the main interpreter has fully finalized and we can initialize a new one? I wonder if we can test for that somehow.

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.

It's not safe to try again with the same object because modules in the init tab may be invalidated. That is why the initialize function consumes the config object instead of taking it by reference.

I think it's fine to use a new config or no config.

I'm not sure about testing. I suppose we could try to attach a thread state and assert that it fails. Does that seem right?

Comment thread tests/test_init_config_init_fail.rs Outdated
config
.set_str(c"prefix", c"/path/that/does/not/exit")
.unwrap();
config.initialize().unwrap_err();

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.

As per other comment I wonder if it's possible to try again here.

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.

Is there something you specifically want to be different in this test case?

Comment thread tests/test_init_config_add_module.rs Outdated
Comment thread src/init_config.rs Outdated
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