sphinx-contrib / autoprogram

Documenting CLI programs
https://pypi.org/project/sphinxcontrib-autoprogram/
Other
44 stars 23 forks source link

Formatting fails with non-string choices #10

Closed turtlemonvh closed 4 years ago

turtlemonvh commented 4 years ago

I get this when running against one of my parsers.

reading sources... [ 10%] cli
Exception occurred:
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 103, in format_option
    value = '{{{0}}}'.format(','.join(arg.choices))
TypeError: sequence item 0: expected str instance, int found
The full traceback has been saved in /var/folders/m2/kzfqsnk915x24ddpjt6fggmmh_bxtz/T/sphinx-err-jqa3ku_t.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

Here is the bottom part of that /var/folders/m2/kzfqsnk915x24ddpjt6fggmmh_bxtz/T/sphinx-err-jqa3ku_t.log file

  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2081, in directive
    directive_class, match, type_name, option_presets)
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2130, in run_directive
    result = directive_instance.run()
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 236, in run
    for line in self.make_rst():
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 201, in make_rst
    parser, maxdepth=maxdepth, groups=groups
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 73, in scan_programs
    sub, command + [cmd], maxdepth, depth + 1
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 73, in scan_programs
    sub, command + [cmd], maxdepth, depth + 1
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 55, in scan_programs
    options = list(scan_options(parser._actions))
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 86, in scan_options
    yield format_option(arg)
  File "/anaconda2/envs/ionic-fs-watcher/lib/python3.6/site-packages/sphinxcontrib/autoprogram.py", line 103, in format_option
    value = '{{{0}}}'.format(','.join(arg.choices))
TypeError: sequence item 0: expected str instance, int found

The suspect code is here, which fails with integer values

    if arg.choices is not None:
        value = '{{{0}}}'.format(','.join(arg.choices))

Changing to something this should fix it

    if arg.choices is not None:
        value = '{{{0}}}'.format(','.join(str(c) for c in arg.choices))