Repository navigation
Description
Problem
- Cannot give autodoc options with arguments to
sphinx-apidoc
Procedure to reproduce the problem
Example input file, call this tests/root/test-member-order/example/__init__.py (directory otherwise initially empty)
"""Silly example for testing ordering in docs.
As listed in the code, function "double" comes
before function "add_five", which differs from
alphabetical sorting. What order will the code's
documentation use?
"""
def double(x):
"""Return double the input argument."""
return x * 2
def add_five(x):
"""Return the input argument plus five."""
return x + 5```Setting simple options via the $SPHINX_APIDOC_OPTIONS environment variable works:
$ cd tests/roots/test-member-order/
$ rm -rf /tmp/api
$ SPHINX_APIDOC_OPTIONS=members,undoc-members,private-members,special-members,inherited-members,show-inheritance sphinx-apidoc -F -e -o /tmp/api example
Creating file /tmp/api/conf.py.
Creating file /tmp/api/index.rst.
Creating file /tmp/api/Makefile.
Creating file /tmp/api/make.bat.
$ more /tmp/api/modules.rst
example
=======
.. toctree::
:maxdepth: 4
example
$ more /tmp/api/example.rst
example package
===============
Module contents
---------------
.. automodule:: example
:members:
:undoc-members:
:private-members:
:special-members:
:inherited-members:
:show-inheritance:
However, I want to use options with arguments like the following (note commas may appear in the values):
:member-order: bysource
:special-members: __init__
:exclude-members: __dict__,__weakref__
Expected results
sphinx-apidoc would provide a way to set the automodule entries with a template or other mechanism able to cope with optional arguments to entries.
Reproducible project / your project
See above for the simple case (no arguments), here I try adding a single argument as member-order bysource, to demonstrate the failure:
$ cd tests/roots/test-member-order/
$ rm -rf /tmp/api
$ SPHINX_APIDOC_OPTIONS="members,undoc-members,private-members,special-members __init__,inherited-members,show-inheritance,member-order bysource" sphinx-apidoc -F -e -o /tmp/api example
$ more /tmp/api/example.rst
example package
===============
Module contents
---------------
.. automodule:: example
:members:
:undoc-members:
:private-members:
:special-members __init__:
:inherited-members:
:show-inheritance:
:member-order bysource:
That will fail due to the misplaced colons, Error in "automodule" directive: invalid option data: extension option field name may not contain multiple words.
Reading the code there is no attempt to handle arguments: https://github.com/sphinx-doc/sphinx/blob/1.6.3/sphinx/apidoc.py#L92
The simple comma separated environment variable $SPHINX_APIDOC_OPTIONS is ill suited to being extended to include optional arguments - especially as those arguments may contain commas.
Environment info
- OS: macOS
- Python version: 2.7
- Sphinx version:
$ sphinx-apidoc --version
Sphinx (sphinx-apidoc) 1.7+
Activity
peterjc commentedon Oct 10, 2017
It seems the accepted work around is to define defaults in
conf.pyinstead - which for some workflows is actually preferable (e.g. if always regenerating the RST file usingsphinx-apidoc).See issue #4075 and associated pull request #4076 for adding
autodoc_exclude_membersandautodoc_special_memberssettings toconf.py.peterjc commentedon Sep 24, 2018
As of #5215 and sphinx 1.8.0, we set these options in
conf.pyusingautodoc_default_values