The python3-config script is frequently used to get relevant flags of the Python installation.
There are two problems with that:
Not all Python installations have it. e.g. python -m venv does not create it. It’s mostly present at system level package
Even if it is present, locating it can be tricky and one can easily pickup the wrong one and left wondering what’s wrong. e.g. /usr/loca/bin/python3-config or /opt/homebrew…` on mac.
I’ve also noticed that people usually do something like `python -c “import sys; print(sys…”) to fetch specific info.
Personally I prefer the python -m sysconfig output, mainly because I already know which $prefix/bin/python I use, but then I have to grep etc. for the specific info.
With that in mind I think it makes sense to have a more structured output of this info via the python -m sysconfig module, so that one can do things like python -m sysconfig | jq .variables.prefix
Assuming that you’re just looking for a scripting-friendly way to pull out a specific variable, any reason not to use python -c 'import sysconfig; print(sysconfig.get_config_var("prefix"))'?
This assume one knows exactly what they’re looking for. prefix is easy.
For non-trivial scenarios (e.g. embedding python and python3-config --embed doesn’t work) this is not the case.
e.g. why vars.CONFINCLUDEDIR or vars.CONFINCLUDEPY instead of paths.include?
In practice, I find myself inspecting the output of -m sysconfig and pick what looks suitable. Rinse and repeat. With a json-formatted output this looks much more convenient, especially when piped to jq.
Also, Consider having something like this in a Makefile though (typical when embedding cpython). PREFIX=$(shell python -c 'import sysconfig; print(sysconfig.get_config_var("prefix"))')
Tweaking and debugging and getting the parentheses right can be a pain
If it was up to me I would even ditch the pypython prefix completely and have just version.
much like pkg-config --version python
Makes jq filtering easier too.
Having said that I noticed that PY_VERSION is ussed in the vars as-is, so I thought of keeping that in top-level keys too.
Also “using the documentation” is not that straightforward as it sounds.
From the documentation on ‘python-config’
It is not necessarily trivial to find the right flags to pass to your compiler (and linker) in order to embed the Python interpreter into your application
To find out the required compiler and linker flags, you can execute the pythonX.Y-config script which is generated as part of the installation process (a python3-config script may also be available).
Why not simply submit your implementation as a PR for Python 3.14? It doesn’t seem like an unreasonable idea, and the implementation is simple enough that it probably doesn’t need an extended debate here. The core devs with responsibility for the sysconfig module might still reject the PR, but it’s their decision, ultimately, in any case.