python / cpython

The Python programming language
https://www.python.org
Other
62.36k stars 29.95k forks source link

Add `python -m sysconfig --json` output option #123350

Open Florents-Tselai opened 3 weeks ago

Florents-Tselai commented 3 weeks ago

Feature or enhancement

Proposal:

Currently python -m sysconfig prints only tab-ed textual output which is useful for debugging, but cumbersome to extract speicific information from.

I think it makes sense to have a json-formatted output too python -m sysconfig --json | jq ".variables.prefix". With the eventual goal of having to avoid python -c 'import sysconfig; print(sysconfig.get_*(*)))'?


python -m sysconfig --json
    {
       "platform": "macosx-14.6-arm64",
       "pyversion": "3.14",
       "default_scheme": "posix_prefix",
       "paths": {
           "stdlib": "/Users/flo/cpython/build/lib/python3.14",
           "platstdlib": "/Users/flo/cpython/build/lib/python3.14",
           "purelib": "/Users/flo/cpython/build/lib/python3.14/site-packages",
           ...
       },
       "variables": {
           "prefix": "/Users/flo/cpython/build",
           "exec_prefix": "/Users/flo/cpython/build",
           "python_version": "3.14.0a0",
           ...
       }
   }

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/add-python-m-sysconfig-json-option/61918/

Linked PRs

Florents-Tselai commented 3 weeks ago

There's also a PR already #123318

Florents-Tselai commented 3 weeks ago

As a future note: If this looks appealing, I was wondering if it would make more sense to give some more love to python -m sysconfig and even promote it as a more reliable replacement to python3-X.X-config .

This would also mean adding pkg-config-like flag. Yes, this means duplicating what python3-X.X-config does, but python -m sysconfig will always be there, unlike python3-X.X-config ..