Skip to content

New conf.py directives autodoc_exclude_members + autodoc_special_members - #4076

Closed
peterjc wants to merge 5 commits into
sphinx-doc:masterfrom
peterjc:autodoc_flag_opts
Closed

peterjc wants to merge 5 commits into
sphinx-doc:masterfrom
peterjc:autodoc_flag_opts

Conversation

@peterjc

@peterjc peterjc commented Sep 20, 2017 •

Copy link
Copy Markdown
Contributor

Feature or Bugfix

  • Feature

Purpose

  • Adds conf.py setting autodoc_exclude_members (update) and autodoc_special_members

Relates

@peterjc

peterjc commented Sep 20, 2017

Copy link
Copy Markdown
Contributor Author

Note if this change is accepted, I would be happy to try to do the same for :special-members: as well.

@tk0miya

tk0miya commented Sep 24, 2017

Copy link
Copy Markdown
Member

@shimizukawa could you give us advice for this interface?
I don't know what is best design of autodoc.
I also feel to enhance autodoc_default_flags to allow dict as a default settings.
what do you think?

@tk0miya
tk0miya requested a review from shimizukawa September 24, 2017 07:39
@tk0miya tk0miya added this to the 1.7 milestone Sep 24, 2017

@stephenfin stephenfin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this is a good idea. Would like to see a similar option it for special-members too, as you suggest

Comment thread sphinx/ext/autodoc/__init__.py Outdated

# remove members given by exclude-members
if self.options.exclude_members:
exclude = self.options.exclude_members or \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd rather see this wrapped in brackets as it reads a little better. However, we use / elsewhere in the code base so it's not a pressing issue

@peterjc

peterjc commented Sep 28, 2017

Copy link
Copy Markdown
Contributor Author

This may not be the most elegant way to do this (since I turn the list of special methods into a comma-separated string), but it seems to work OK in my initial testing.

TODO: Testing overrides with different entries in the RST file directives...

@peterjc

peterjc commented Oct 9, 2017

Copy link
Copy Markdown
Contributor Author

Sorry for the delay, I've been ill which delayed looking at this.

I may be doing something wrong with my local testing, but it seems neither :no-special-members: nor entries like :special-members: __init__, __eq__ in an individual RST file are able to override a conf.py setting like autodoc_special_members = ['__init__', '__next__']

i.e. The special methods part of this patch needs more work. I'm happy to remove this in the short term if you'd rather merge the exclude members work (which I am happy with).

@stephenfin

Copy link
Copy Markdown
Contributor

@peterjc If you could point to the exact sections that are causing issues, I'd be happy to take a look this evening?

@peterjc

peterjc commented Oct 9, 2017 •

Copy link
Copy Markdown
Contributor Author

@stephenfin do you know how where the RST file specific autodoc directive for special methods is loaded and applied?

Update: I've started adding logging

e.g.

$ git diff sphinx/ext/autodoc/__init__.py
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 05dea49..064c54b 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -699,6 +699,12 @@ class Documenter(object):
             keep = False
             if want_all and membername.startswith('__') and \
                     membername.endswith('__') and len(membername) > 4:
+                logger.debug('[autodoc] considering %s.%s with '
+                             'self.options.special_members = %r '
+                             'and self.env.config.autodoc_special_members = %r',
+                             namespace, membername,
+                             self.options.special_members,
+                             self.env.config.autodoc_special_members)
                 # special __methods__
                 if self.options.special_members is ALL and \
                         membername != '__doc__':
@@ -1554,6 +1560,10 @@ class AutoDirective(Directive):
                 self.options[flag] = None
 
         if self.env.config.autodoc_special_members:
+            logger.debug("[autodoc] applying autodoc_special_members = %r, "
+                         "currently self.options['special-members'] = %r",
+                         self.env.config.autodoc_special_members,
+                         self.options['special-members'])
             # Using autodoc_special_members (which takes a list of methods)
             # overrides including special-members in autodoc_default_flags
             # (which applies the default value of None meaning ALL methods).

This output running sphinx-build -v ... to see the logging puzzles me:

...
[autodoc] /mnt/shared/users/xxx/repositories/biopython/Doc/api/Bio.SeqRecord.rst:4: input:
.. automodule:: Bio.SeqRecord
    :members:
    :undoc-members:
    :show-inheritance:
    :special-members: __init__,__eq__
[autodoc] applying autodoc_special_members = ['__init__', '__next__'], currently self.options['special-members'] = None
[autodoc] import Bio.SeqRecord
...

At what point does this RST file's entry :special-members: __init__,__eq__ get loaded?

Note my conf.py file contains autodoc_special_members = ['__init__', '__next__'] in this example.

@peterjc

peterjc commented Oct 9, 2017 •

Copy link
Copy Markdown
Contributor Author

To try to understand what is breaking,I'm wondering what the documentation update c333f51 refers to - this added the text for :special-members: saying as of release 1.2 "The option can now take arguments, i.e. the special members to document."

The git commit comment is "Doc change for d7ac5e46307d" but that hash does not seem to be in the tree...

$ git show d7ac5e46307d
fatal: ambiguous argument 'd7ac5e46307d': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Update: I'm guessing it refers to 5b9f431 "Changed the special-members option to behave like the members option." - which is all bits of the code I was already looking at. Hmm.

Entry in the RST file most important, then conf.py entry
autodoc_special_members (list), finally conf.py entry
autodoc_default_flags (where inclusion here means ALL
special methods).
@peterjc

peterjc commented Oct 9, 2017

Copy link
Copy Markdown
Contributor Author

As part of fixing the priorities for the new autodoc_special_members setting, I thinks I also have found and fixed a pre-existing bug where autodoc_default_flags = ['special-members', ...] would override any RST file entry like :special-members: __init__,__eq__ or :no-special-members:

@peterjc peterjc changed the title New conf.py directive autodoc_exclude_members New conf.py directives autodoc_exclude_members + autodoc_special_members Oct 18, 2017
@peterjc

peterjc commented Nov 21, 2017

Copy link
Copy Markdown
Contributor Author

Is there anything else that I can improve/fix before this is reviewed by @shimizukawa?

@shimizukawa

Copy link
Copy Markdown
Member

I also feel to enhance autodoc_default_flags to allow dict as a default settings.

+1 (by a quick look..)

@tk0miya tk0miya modified the milestones: 1.7, 1.8 Jan 14, 2018
@adamklein

Copy link
Copy Markdown

+1

@tk0miya

tk0miya commented Aug 18, 2018

Copy link
Copy Markdown
Member

Now I merged #5215 instead.
Thank you for your work!

@tk0miya tk0miya closed this Aug 18, 2018
@peterjc

peterjc commented Aug 18, 2018

Copy link
Copy Markdown
Contributor Author

That's great - I'll give this new functionality a test next time I work on our documentation. Thank you 😀

1 similar comment
@peterjc

peterjc commented Aug 18, 2018

Copy link
Copy Markdown
Contributor Author

That's great - I'll give this new functionality a test next time I work on our documentation. Thank you 😀

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants