docs: fix command help regenerator on python 3.10

In https://github.com/python/cpython/pull/23858 the section header for
option flags was changed from "optional arguments" to "options" with the
rationale that they are not (necessarily) at all optional, while GNU
coreutils calls them options.

In fact, POSIX calls them options (-o) and option-arguments (-o val) and
operands ("positional arguments") so it is indeed a mess, but argparse
is not yet perfect.

Still, fix the documentation generator for now so that it is compatible
with python 3.10 as well.

Fixes traceback on building the docs with:

```
[1/4] Generating gen_docs with a custom command
FAILED: gen_docs.stamp
/home/eschwartz/git/meson/docs/../tools/regenerate_docs.py --output-dir /home/eschwartz/git/meson/docs/builddir --dummy-output-file gen_docs.stamp
Traceback (most recent call last):
  File "/home/eschwartz/git/meson/docs/../tools/regenerate_docs.py", line 160, in <module>
    regenerate_docs(output_dir=args.output_dir,
  File "/home/eschwartz/git/meson/docs/../tools/regenerate_docs.py", line 146, in regenerate_docs
    generate_hotdoc_includes(root_dir, output_dir)
  File "/home/eschwartz/git/meson/docs/../tools/regenerate_docs.py", line 113, in generate_hotdoc_includes
    cmd_data = get_commands_data(root_dir)
  File "/home/eschwartz/git/meson/docs/../tools/regenerate_docs.py", line 106, in get_commands_data
    cmd_data[cmd] = parse_cmd(cmd_output)
  File "/home/eschwartz/git/meson/docs/../tools/regenerate_docs.py", line 65, in parse_cmd
    assert arguments_start
AssertionError
```
pull/9874/head
Eli Schwartz 3 years ago
parent a0d28e850e
commit a038fa80f5
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 2
      tools/regenerate_docs.py

@ -40,7 +40,7 @@ def _get_meson_output(root_dir: Path, args: T.List) -> str:
def get_commands_data(root_dir: Path) -> T.Dict[str, T.Any]: def get_commands_data(root_dir: Path) -> T.Dict[str, T.Any]:
usage_start_pattern = re.compile(r'^usage: ', re.MULTILINE) usage_start_pattern = re.compile(r'^usage: ', re.MULTILINE)
positional_start_pattern = re.compile(r'^positional arguments:[\t ]*[\r\n]+', re.MULTILINE) positional_start_pattern = re.compile(r'^positional arguments:[\t ]*[\r\n]+', re.MULTILINE)
options_start_pattern = re.compile(r'^optional arguments:[\t ]*[\r\n]+', re.MULTILINE) options_start_pattern = re.compile(r'^(optional arguments|options):[\t ]*[\r\n]+', re.MULTILINE)
commands_start_pattern = re.compile(r'^[A-Za-z ]*[Cc]ommands:[\t ]*[\r\n]+', re.MULTILINE) commands_start_pattern = re.compile(r'^[A-Za-z ]*[Cc]ommands:[\t ]*[\r\n]+', re.MULTILINE)
def get_next_start(iterators: T.Sequence[T.Any], end: T.Optional[int]) -> int: def get_next_start(iterators: T.Sequence[T.Any], end: T.Optional[int]) -> int:

Loading…
Cancel
Save