sphinx-argparse
sphinx-argparse copied to clipboard
Section numbers wrong when multiple argparse directives used in single page
This is a rewrite of https://github.com/alex-rudakov/sphinx-argparse/issues/127 from the old project, but I've made it into a smaller reproducible example. The summary of the issue is that Named Arguments and Options sections in a single restructuredtext document (~or maybe a single sphinx project~) that has a :numbered:
TOC tree will always use the section number from the last .. argparse::
directive.
mkdir sample_proj
cd sample_proj
touch myproj.py
touch index.rst
touch utils.rst
myproj.py
def get_parser1(parser):
parser.add_argument("--flag1", default=1, type=int)
return parser
def get_parser2(parser):
parser.add_argument("--flag2", default=2, type=int)
return parser
index.rst
Welcome to myproj's documentation!
==================================
.. toctree::
:maxdepth: 2
:caption: Contents:
:numbered:
utils
utils.rst
Utility Scripts
===============
Section A
---------
.. argparse::
:module: myproj
:func: get_parser1
:passparser:
Section B
---------
.. argparse::
:module: myproj
:func: get_parser2
:passparser:
Then generate the docs with:
PYTHONPATH=. sphinx-build . build -C -D extensions=sphinxarg.ext
And open built/utils.html
in a browser. You'll see something like:
Notice how the "Named Arguments" sections have the same section number. They should be 1.1.1 and 1.2.1.