Skip to content

gh-133143: Make information about the interpreter ABI more accessible - #137476

Merged
encukou merged 28 commits into
python:mainfrom
zklaus:add-sys.abi_info
Sep 8, 2025
Merged

encukou merged 28 commits into
python:mainfrom
zklaus:add-sys.abi_info

Conversation

@zklaus

@zklaus zklaus commented Aug 6, 2025 •

Copy link
Copy Markdown
Contributor

This adds a new sys.abi_info object to make basic abi information more readily accessible.

The basic idea is to have not just flags as originally envisioned in #133143, but rather a more pythonic object with the required information, following the model of the sys.thread_info and sys.int_info object as suggested in the discussion by @encukou.

gh-133143


📚 Documentation preview 📚: https://cpython-previews--137476.org.readthedocs.build/

@bedevere-app

bedevere-app Bot commented Aug 6, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@encukou encukou 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.

This is a big PR!
I'll ask you to simplify (and, alas, throw a lot of the scaffolding work away...)

Comment thread Python/abiinfo.c Resolved
Comment thread Python/abiinfo.c Resolved
Comment thread Include/pyabiinfo.h Resolved
Comment thread Python/abiinfo.c Resolved
Comment thread Doc/library/sys.rst Resolved
@zklaus
zklaus force-pushed the add-sys.abi_info branch from ab093fc to defb2b2 Compare August 7, 2025 13:09
@zklaus

zklaus commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for your review, @encukou! I think I have addressed all of your comments and, as you anticipated, it simplifies things a great deal.

Would you mind taking another look?

@encukou

encukou commented Aug 7, 2025

Copy link
Copy Markdown
Member

Looks good now, thanks!
It does need a test. (Ideally comparing things to sys.maxsize and sysconfig.get_config_var, which should also serve as guide/validation for what the packaging tools will need to do for earlier Python versions.)

And, of course, it needs deciding on what should go here; but that's for the discussion thread.

@zklaus

zklaus commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

Agreed about the tests and further discussion. I just wanted to stabilize the implementation sufficiently to be sure to write meaningful tests. Thanks again!

@zklaus

zklaus commented Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

Tests are in place and easily extendable. Let's focus on the discussion and get this in 💪.

@zklaus
zklaus marked this pull request as ready for review August 12, 2025 11:39
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Python/sysmodule.c Resolved

@vstinner vstinner 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.

Can you also mention the new sys.abi_info in Doc/whatsnew/3.15.rst document? You should add a new "sys" section in https://docs.python.org/dev/whatsnew/3.15.html#improved-modules

@zklaus
zklaus requested a review from AA-Turner as a code owner September 2, 2025 12:39
Comment thread Python/sysmodule.c Resolved

@vstinner vstinner 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.

LGTM

Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
Comment thread Doc/library/sys.rst Resolved
@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 5, 2025
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit ed7b6d9 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F137476%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 5, 2025
@zklaus

zklaus commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

@encukou, I think the two test failures are unrelated to this PR (both from tarfile, fixed in #138626).

Is there anything left that I should do?

@encukou

encukou commented Sep 8, 2025

Copy link
Copy Markdown
Member

Could you add semantic Sphinx syntax for .. attribute::, from zklaus#3 ? Sorry I didn't link to it on Friday.

With that, I consider this good to merge :)

sys.abi_info: Use Sphinx markup for attributes
@zklaus

zklaus commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

Done, thanks!

Comment thread Python/sysmodule.c Resolved
AA-Turner and others added 2 commits September 8, 2025 14:29
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@encukou
encukou enabled auto-merge (squash) September 8, 2025 13:50
@AA-Turner

Copy link
Copy Markdown
Member

oops, I meant to push to my own branch to propose a PR to @zklaus's repo, sorry. Given Petr has enabled auto-merge already I'll propose my changes in a follow-up.

Separately, should we use a named type for abi_info? Currently the repr shows namespace, which could be surprising for users:

❯ .\python.bat
>>> import sys
>>> sys.abi_info
namespace(pointer_bits=64, free_threaded=False, debug=True, byteorder='little')

A

@encukou
encukou merged commit 1acb718 into python:main Sep 8, 2025
@vstinner

vstinner commented Sep 8, 2025

Copy link
Copy Markdown
Member

Separately, should we use a named type for abi_info?

I don't think that using namespace is a big deal here.

@vstinner

vstinner commented Sep 8, 2025

Copy link
Copy Markdown
Member

Congrats @zklaus, your PR was merged :-)

@encukou

encukou commented Sep 8, 2025

Copy link
Copy Markdown
Member

should we use a named type for abi_info?

sys.implementation is a namespace too, and I haven't seen any complaints.
(float_info and such are separate types with iter & getitem for compatibility with long-gone Pythons where these were tuples. The names are nice, but not worth the complexity for new stuff.)

@AA-Turner

Copy link
Copy Markdown
Member

I realised that one drawback of using SimpleNamespace is that the namespace is not immutable, unlike e.g. sys.version_info, sys.int_info, etc. I'm happy to continue using it given @vstinner & @encukou's comments, but perhaps we should override __setattr__? All the other _info namespaces in sys are immutable, sys.implementation seems to be the exception as far as I can tell.

A

@encukou

encukou commented Sep 8, 2025

Copy link
Copy Markdown
Member

No need. This is Python; consenting adults; you break it you get to keep the pieces; etc.

You can already set sys.int_info = type(sys.int_info)([5, 8, 23, 864]) for example.

Comment thread Doc/library/sys.rst
Comment on lines +25 to +26
The available entries are the same on all platforms;
e.g. *pointer_size* is available even on 64-bit-only architectures.

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.

e.g. would have been better spelled out as for example

lkollar pushed a commit to lkollar/cpython that referenced this pull request Sep 9, 2025
This makes information about the interpreter ABI more accessible.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants