Skip to content

Rust API for pyinitconfig#6173

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

Rust API for pyinitconfig#6173
Person-93 wants to merge 16 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
Signed-off-by: person93 <person93.person93@gmail.com>
@Person-93 Person-93 force-pushed the pyinitconfig branch 3 times, most recently from 2a9f29f to 2f0308c Compare June 30, 2026 14:40
@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 7 times, most recently from 590f4a5 to 57b35c8 Compare July 1, 2026 06:38
Comment thread src/init_config.rs Outdated
Comment thread src/init_config.rs Outdated
///
/// # Panic
/// Panics if the interpreter is already initialized.
pub fn initialize(self) -> Result<Option<c_int>, InitConfigError> {

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.

I think it is more appropriate to return the exit code as a variant of InitConfigError. And make this return Result<(), InitConfigError>

@Person-93 Person-93 Jul 4, 2026

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.

I think it is more appropriate to return the exit code as a variant of InitConfigError. And make this return Result<(), InitConfigError>

I think you're right, I've double checked the docs, and it doesn't explicitly say that calling python APIs when the interpreter wants to exit is forbidden, but that is what the examples show.

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.

I think it should be a new error type with two variants, one of which wraps the existing error type. This way users who want to handle the exit code differently (i.e. by exiting with that code) don't need to check it at every call.

@bschoenmaeckers bschoenmaeckers Jul 4, 2026

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.

I think it should be a new error type with two variants, one of which wraps the existing error type. This way users who want to handle the exit code differently (i.e. by exiting with that code) don't need to check it at every call.

Agreed.

Should InitConfigError be just a CString/String? It feels like a unnecessary wrapper. What do you think?

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.

I think that libraries should define their own error types. https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/define_error_type.html

@codspeed-hq

codspeed-hq Bot commented Jul 4, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 25.83%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 139 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
into_u128_u64_max 1.5 µs 2 µs -25.83%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Person-93:pyinitconfig (f8416ab) with main (9e6697d)

Open in CodSpeed

@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?

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

3 participants