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: --help for runnable stdlib modules
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: later
Dependencies: Superseder:
Assigned To: Nosy List: Antony.Lee, ezio.melotti, r.david.murray
Priority: normal Keywords:

Created on 2015-07-16 16:30 by Antony.Lee, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg246808 - (view) Author: Antony Lee (Antony.Lee) * Date: 2015-07-16 16:30
Support for python -m<runnable-stdlib-module> [-h|--help] is a bit patchy right now:

$ python -mpdb -h
usage: pdb.py [-c command] ... pyfile [arg] ...
<help elided>

$ python -mpdb --help
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.4/pdb.py", line 1685, in <module>
    pdb.main()
  File "/usr/lib/python3.4/pdb.py", line 1629, in main
    opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['--help', '--command='])
  File "/usr/lib/python3.4/getopt.py", line 93, in getopt
    opts, args = do_longs(opts, args[0][2:], longopts, args[1:])
  File "/usr/lib/python3.4/getopt.py", line 157, in do_longs
    has_arg, opt = long_has_args(opt, longopts)
  File "/usr/lib/python3.4/getopt.py", line 174, in long_has_args
    raise GetoptError(_('option --%s not recognized') % opt, opt)
getopt.GetoptError: option --help not recognized
# <-- not a getopt specialist but --help is actually listed in the call to getopt!

$ python -mtrace -h
/usr/lib/python3.4/trace.py: option -h not recognized
Try `/usr/lib/python3.4/trace.py --help' for more information

$ python -mtrace --help
Usage: /usr/lib/python3.4/trace.py [OPTIONS] <file> [ARGS]
<help elided>
msg246811 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-07-16 18:47
Please open individual issues to address individual modules that you would like to contribute to improving.  Adding/fixing help is often best done by rewriting the argument parsing...contributions have been made to improve several modules already.  In most cases we don't have tests for the -m features, and those need to be created first.  In some cases we don't really want to continue to support whatever -m code exists (because it exists for no-longer-relevant historical reasons...though that doesn't apply in the two cases you reference).  So each module needs to be addressed individually.

To address the specific issue you raise: I believe that when we have rewritten things, we have chosen to follow argparse's lead and support both -h and --help for the display of help information.
msg246835 - (view) Author: Antony Lee (Antony.Lee) * Date: 2015-07-16 22:47
To be honest I don't really plan to contribute any patch on this specific issue right now, the CLI interface of e.g. trace has some other serious issues (see e.g. #24649) that I don't want to work out, and writing tests for the CLI are a pain too (also why I haven't made more progress on #23596).
msg246852 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-07-17 13:48
Yes, that's pretty much why things are in the state they are in ;)

Still, opening individual issues for help problems with individual modules is the way to go, as you did (thank you).
msg246855 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2015-07-17 14:11
> writing tests for the CLI are a pain too

It shouldn't be particularly difficult to do it using script_helper.assert_python_{ok|failure}(), even though you could also check the argument /parsing/ separately without having to launch a subprocess.
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68832
2015-07-17 14:11:39ezio.melottisetnosy: + ezio.melotti
messages: + msg246855
2015-07-17 13:48:55r.david.murraysetmessages: + msg246852
2015-07-16 22:47:11Antony.Leesetmessages: + msg246835
2015-07-16 18:47:09r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg246811

resolution: later
stage: resolved
2015-07-16 16:30:57Antony.Leecreate