On 2014-02-12 20:25, Matthew Woehlke wrote:
I have some code like:

Foo/Bar.py
class Bar(object):
   ...code and doc...

Foo/__init__.py
from .Bar import Bar

...IOW, Bar.py defines the class Bar, which should appear to be fully
qualified like Foo.Bar, not Foo.Bar.Bar. I believe this to be a common
pattern(?), but I can't figure out how to get it to document correctly.

If I do:

   .. autoclass:: Foo.Bar

...then I get documentation, but the source links are missing.

If I do:

   .. automodule:: Foo.Bar

...then I get source links, but the class name is documented as
Foo.Bar.Bar.

Is there a way to either strip the superfluous module from the name, or
else get the source links to work with the first form? (Failing that, is
there a way to turn the source links off entirely? The problem is that I
have a mixture of classes and "true" modules, which will have source
links if the classes don't, and I don't want that inconsistency...)

Okay, I figured it out... it is necessary to reimplement ClassDocumenter and add the customized version as an additional documenter. Here's the code I came up with:

  class ClassModuleClassDocumenter(autodoc.ClassDocumenter):
    def resolve_name(self, *args):
      module, attrs = super(ClassModuleClassDocumenter,
                            self).resolve_name(*args)
      module = module.split('.')
      if module[-1] == attrs[0]:
        del module[-1]
      return '.'.join(module), attrs

  def setup(app):
    app.add_autodocumenter(ClassModuleClassDocumenter)

Nice to be able to go in and change the guts of autodoc this way :-).

--
Matthew

--
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to