This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Small inconsistency in usage message between the python and shell script versions of python-config
Type: behavior Stage: patch review
Components: Demos and Tools Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, kiendang
Priority: normal Keywords: patch

Created on 2021-09-04 18:32 by kiendang, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 28162 open kiendang, 2021-09-04 18:38
Messages (3)
msg401054 - (view) Author: Kien Dang (kiendang) * Date: 2021-09-04 18:32
`python-config` outputs a usage instruction message in case either the `--help` option or invalid arguments are provided.

However there is a small different in the output I/O between the python and shell script versions of `python-config`. In the python version, the message always prints to `stderr`.

https://github.com/python/cpython/blob/bc1c49fa94b2abf70e6937373bf1e6b5378035c5/Misc/python-config.in#L15-L18

def exit_with_usage(code=1):
    print("Usage: {0} [{1}]".format(
        sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
    sys.exit(code)

while in the shell script version it always prints to `stdout`.

https://github.com/python/cpython/blob/bc1c49fa94b2abf70e6937373bf1e6b5378035c5/Misc/python-config.sh.in#L5-L9

exit_with_usage ()
{
    echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed"
    exit $1
}

This inconsistency does not affect most users of `python-config`, who runs the script interactively. However it might cause issues when run programmatically.
msg401612 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2021-09-10 19:53
I think python-config is modelled after pkg-config: what does the latter do?

Also, I’m not sure it would be appropriate to change behaviour in existing releases.
msg402526 - (view) Author: Kien Dang (kiendang) * Date: 2021-09-23 20:57
Thanks. I didn't know about the `pkg-config` thing. I just checked with pkg-config on macOS

`pkg-config --help` prints usage instructions to stdout

pkg-config followed by invalid options prints output to stderr, for example `pkg-config --asdf` prints `Unknown option --asdf` to stderr.

The PR I submitted does something similar, making both python and shell script versions of `python-config` to print out the usage instruction message to stdout when --help is provided and stderr when given invalid arguments.
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89264
2021-09-23 20:57:44kiendangsetmessages: + msg402526
2021-09-10 19:53:48eric.araujosetnosy: + eric.araujo

messages: + msg401612
versions: - Python 3.9, Python 3.10
2021-09-04 18:38:18kiendangsetkeywords: + patch
stage: patch review
pull_requests: + pull_request26594
2021-09-04 18:32:12kiendangcreate