Skip to content

Automodule options with arguments in apidoc #4057

Closed

Description

@peterjc

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

  1. peterjc commented on Oct 10, 2017

    @peterjc
    ContributorAuthor

    It seems the accepted work around is to define defaults in conf.py instead - which for some workflows is actually preferable (e.g. if always regenerating the RST file using sphinx-apidoc).

    See issue #4075 and associated pull request #4076 for adding autodoc_exclude_members and autodoc_special_members settings to conf.py.

  2. peterjc commented on Sep 24, 2018

    @peterjc
    ContributorAuthor

    As of #5215 and sphinx 1.8.0, we set these options in conf.py using autodoc_default_values

  3. locked as resolved and limited conversation to collaborators on Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions