GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [PEP 741] gh-107954: Add PyInitConfig C API by vstinner · Pull Request #110176 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Oct 1, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Add PyInitConfig functions:

  • PyInitConfig_Python_New()
  • PyInitConfig_Isolated_New()
  • PyInitConfig_Free(config)
  • PyInitConfig_SetInt(config, key, value)
  • PyInitConfig_SetStr(config, key, value)
  • PyInitConfig_SetWStr(config, key, value)
  • PyInitConfig_SetStrList(config, key, length, items)
  • PyInitConfig_SetWStrList(config, key, length, items)
  • PyInitConfig_GetErrorMsg(config)

Add also functions using it:

  • Py_InitializeFromInitConfig(config)
  • Py_ExitWithInitConfig(config)

Changes:

  • Add Include/initconfig.h header.

Discussion: https://discuss.python.org/t/fr-allow-private-runtime-config-to-enable-extending-without-breaking-the-pyconfig-abi/18004/20

  • Issue: [C API] PEP 741: Add PyInitConfig C API to customize the Python initialization #107954

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added the awaiting review label Oct 1, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Oct 1, 2023
[C API] PEP 741: Add PyInitConfig C API to customize the Python initialization #107954
Closed
@vstinner
vstinner marked this pull request as draft October 1, 2023 12:22
@bedevere-app bedevere-app Bot removed the awaiting review label Oct 1, 2023
@vstinner
vstinner force-pushed the config_set_abi branch from 26ff1c2 to 4bee604 Compare October 1, 2023 13:09
@vstinner

vstinner commented Oct 1, 2023

Copy link
Copy Markdown
Member Author

Discussion: https://discuss.python.org/t/fr-allow-private-runtime-config-to-enable-extending-without-breaking-the-pyconfig-abi/18004/20

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner force-pushed the config_set_abi branch from 4bee604 to 2b5a76c Compare October 1, 2023 14:16
@vstinner vstinner added the skip news label Oct 1, 2023
@vstinner

vstinner commented Oct 1, 2023

Copy link
Copy Markdown
Member Author

TODO: once we reach an consensus on the API, I will document the API.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Oct 2, 2023
[WIP] gh-107954: Add _PyConfig_Parse() #110145
Closed
@vstinner
vstinner force-pushed the config_set_abi branch from 2b5a76c to dd6c047 Compare October 3, 2023 17:26
@vstinner vstinner mentioned this pull request Nov 13, 2023
[C API] Meta issue: add new public functions with doc+tests to replace removed private functions #111481
Closed
@vstinner
vstinner force-pushed the config_set_abi branch from acdcb6c to 624cbcb Compare November 30, 2023 22:16
@vstinner vstinner removed the skip news label Nov 30, 2023
@vstinner
vstinner force-pushed the config_set_abi branch from 624cbcb to e85efd1 Compare November 30, 2023 22:20
@vstinner
vstinner marked this pull request as ready for review November 30, 2023 22:20
@vstinner
vstinner requested review from a team and encukou as code owners November 30, 2023 22:20
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 30, 2023
@vstinner

vstinner commented Nov 30, 2023

Copy link
Copy Markdown
Member Author

I documented the API. I decided to add a new Doc/c-api/config.rst documentation for that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou reviewed Dec 1, 2023
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you!
Now that I see all the docs, it looks the design is missing a function: https://discuss.python.org/t/fr-allow-private-runtime-config-to-enable-extending-without-breaking-the-pyconfig-abi/18004/49?u=encukou

I also have a few docs nitpicks. I didn't look very closely at the implementation yet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/c-api/config.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/config.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/config.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/config.rst Outdated
Comment on lines +94 to +95
Return ``-1`` if Python wants to exit and on error. Call
:c:func:`Py_ExitWithInitConfig` in this case.

@encukou encukou Dec 1, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What happens if you don't call it? (If it needs to be called, why does Py_InitializeFromInitConfig not call it itself?)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Dec 1, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The idea is to let the caller decide how to handle an error or an exit code. When you embed Python, you may not want the process to exit. It's a similar design than Py_InitializeFromConfig() and the PyStatus C API.

What happens if you don't call it?

Python is in an undefined state. The error/exit code stays in PyInitConfig. It's safer to handle the init error :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/c-api/config.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/config.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner force-pushed the config_set_abi branch 2 times, most recently from fee8cc4 to 7d59519 Compare December 1, 2023 16:08
@vstinner

vstinner commented Dec 1, 2023

Copy link
Copy Markdown
Member Author

This change is quite big, so I moved PyConfig_Get() API to a separated PR: PR #112609.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Dec 7, 2023
Add PyConfig_Get() and PyConfig_GetInt() functions capi-workgroup/decisions#3
Closed
1 of 4 tasks
@vstinner
vstinner force-pushed the config_set_abi branch from 7d59519 to 582a0c1 Compare December 12, 2023 16:42
@vstinner
pythongh-107954: Add PyInitConfig C API
6d02e9e
Add PyInitConfig functions:

* PyInitConfig_Python_New()
* PyInitConfig_Isolated_New()
* PyInitConfig_Free(config)
* PyInitConfig_SetInt(config, key, value)
* PyInitConfig_SetStr(config, key, value)
* PyInitConfig_SetWStr(config, key, value)
* PyInitConfig_SetStrList(config, key, length, items)
* PyInitConfig_SetWStrList(config, key, length, items)
* PyInitConfig_Exception(config)
* PyInitConfig_GetError(config, &err_msg)
* PyInitConfig_GetExitCode(config, &exitcode)

Add also functions using it:

* Py_InitializeFromInitConfig(config)
* Py_ExitWithInitConfig(config)

Add these functions to the limited C API.

Changes:

* Add Doc/c-api/config.rst.
* Add Include/initconfig.h header.
@vstinner
vstinner force-pushed the config_set_abi branch from 582a0c1 to 6d02e9e Compare December 12, 2023 16:45
@vstinner
Fix Windows build: _testcapi\config.c was removed
7a39b5a
@vstinner

vstinner commented Dec 20, 2023

Copy link
Copy Markdown
Member Author

This API is kind of complicated (there are multiple use cases). I created PR #112609 as a starting point, just to add two functions. But apparently, adding PyConfig_Get() and PyConfig_GetInt() functions is more complicated than what I expected. I don't have the bandwidth to deal with such large API for now, so I prefer to close the PR. See also my comment on the PyConfig_Get() PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner closed this Dec 20, 2023
@vstinner
vstinner deleted the config_set_abi branch December 20, 2023 11:09
@vstinner vstinner mentioned this pull request Jan 16, 2024
[C API] Deprecate legacy API for configure Python initialization #88279
Closed
@vstinner
vstinner restored the config_set_abi branch February 7, 2024 02:04
@vstinner vstinner changed the title gh-107954: Add PyInitConfig C API [PEP 741] gh-107954: Add PyInitConfig C API May 3, 2024
@vstinner

vstinner commented Aug 30, 2024

Copy link
Copy Markdown
Member Author

New PR: #123502

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Aug 30, 2024
gh-107954, PEP 741: Add PyInitConfig C API #123502
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@vstinner @encukou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.